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 13
13
import gzip
14
14
import bz2
15
15
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
+
16
27
17
28
class Opener (object ):
18
29
""" Class to accept, maybe open, and context-manage file-likes / filenames
@@ -32,7 +43,7 @@ class Opener(object):
32
43
passed to opening method when `fileish` is str. Change of defaults as
33
44
for \*args
34
45
"""
35
- gz_def = (gzip . open , ('mode' , 'compresslevel' ))
46
+ gz_def = (_gzip_open , ('mode' , 'compresslevel' ))
36
47
bz2_def = (bz2 .BZ2File , ('mode' , 'buffering' , 'compresslevel' ))
37
48
compress_ext_map = {
38
49
'.gz' : gz_def ,
You can’t perform that action at this time.
0 commit comments