1818
1919
2020class 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."""
2322 def __init__ (self , fileish , mode = 'rb' , compresslevel = 9 , buffer_size = 2 ** 32 - 1 ):
2423 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
2529 if hasattr (self , 'max_chunk_read' ):
2630 gzip_file .max_read_chunk = GZIP_MAX_READ_CHUNK
27- self .buffer_size = buffer_size
2831
2932 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"""
3137 n_bytes = len (buf )
3238 try :
3339 # This works around a known issue in Python 3.5.
@@ -49,9 +55,6 @@ def readinto(self, buf):
4955
5056
5157def _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-
5558 gzip_file = BufferedGzipFile (fileish , * args , ** kwargs )
5659 return gzip_file
5760
0 commit comments