mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
Issue #7471: Improve the performance of GzipFile's buffering mechanism,
and make it implement the `io.BufferedIOBase` ABC to allow for further speedups by wrapping it in an `io.BufferedReader`. Patch by Nir Aides.
This commit is contained in:
parent
49d709c921
commit
673ddf9907
3 changed files with 58 additions and 58 deletions
|
@ -5,6 +5,7 @@
|
|||
import unittest
|
||||
from test import test_support
|
||||
import os
|
||||
import io
|
||||
import struct
|
||||
gzip = test_support.import_module('gzip')
|
||||
|
||||
|
@ -80,6 +81,16 @@ class TestGzip(unittest.TestCase):
|
|||
zgfile.close()
|
||||
self.assertEquals(contents, 'a'*201)
|
||||
|
||||
def test_buffered_reader(self):
|
||||
# Issue #7471: a GzipFile can be wrapped in a BufferedReader for
|
||||
# performance.
|
||||
self.test_write()
|
||||
|
||||
f = gzip.GzipFile(self.filename, 'rb')
|
||||
with io.BufferedReader(f) as r:
|
||||
lines = [line for line in r]
|
||||
|
||||
self.assertEqual(lines, 50 * data1.splitlines(True))
|
||||
|
||||
def test_readline(self):
|
||||
self.test_write()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue