18
18
19
19
20
20
class BufferedGzipFile (gzip .GzipFile ):
21
- """GzipFile capable to readinto buffer >= 2**32 bytes."""
22
- # Speedup for #209; breaks in Python 3.5
21
+ """GzipFile able to readinto buffer >= 2**32 bytes."""
23
22
def __init__ (self , fileish , mode = 'rb' , compresslevel = 9 , buffer_size = 2 ** 32 - 1 ):
24
23
super (BufferedGzipFile , self ).__init__ (fileish , mode = mode , compresslevel = compresslevel )
24
+ self .buffer_size = buffer_size
25
+
26
+ # Speedup for #209; attribute not present in in Python 3.5
27
+ # open gzip files with faster reads on large files using larger chunks
28
+ # See https://github.com/nipy/nibabel/pull/210 for discussion
25
29
if hasattr (self , 'max_chunk_read' ):
26
30
gzip_file .max_read_chunk = GZIP_MAX_READ_CHUNK
27
- self .buffer_size = buffer_size
28
31
29
32
def readinto (self , buf ):
30
- """Uses self.buffer_size to do a buffered read."""
33
+ """Uses self.buffer_size to do a buffered read.
34
+
35
+ This works around a known issue in Python 3.5.
36
+ See https://bugs.python.org/issue25626"""
31
37
n_bytes = len (buf )
32
38
try :
33
39
# This works around a known issue in Python 3.5.
@@ -49,9 +55,6 @@ def readinto(self, buf):
49
55
50
56
51
57
def _gzip_open (fileish , * args , ** kwargs ):
52
- # open gzip files with faster reads on large files using larger chunks
53
- # See https://github.com/nipy/nibabel/pull/210 for discussion
54
-
55
58
gzip_file = BufferedGzipFile (fileish , * args , ** kwargs )
56
59
return gzip_file
57
60
0 commit comments