File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1313import gzip
1414import bz2
1515
16+ # The largest memory chunk that gzip can use for reads
17+ GZIP_MAX_READ_CHUNK = 100 * 1024 * 1024 # 100Mb
18+
19+
20+ def _gzip_open (fileish , * args , ** kwargs ):
21+ # open gzip files with faster reads on large files using larger chunks
22+ # See https://github.com/nipy/nibabel/pull/210 for discussion
23+ gzip_file = gzip .open (fileish , * args , ** kwargs )
24+ gzip_file .max_read_chunk = GZIP_MAX_READ_CHUNK
25+ return gzip_file
26+
1627
1728class Opener (object ):
1829 """ Class to accept, maybe open, and context-manage file-likes / filenames
@@ -32,7 +43,7 @@ class Opener(object):
3243 passed to opening method when `fileish` is str. Change of defaults as
3344 for \*args
3445 """
35- gz_def = (gzip . open , ('mode' , 'compresslevel' ))
46+ gz_def = (_gzip_open , ('mode' , 'compresslevel' ))
3647 bz2_def = (bz2 .BZ2File , ('mode' , 'buffering' , 'compresslevel' ))
3748 compress_ext_map = {
3849 '.gz' : gz_def ,
You can’t perform that action at this time.
0 commit comments