@@ -60,8 +60,30 @@ def readinto(self, buf):
60
60
return n_read
61
61
62
62
63
- def _gzip_open (fileish , * args , ** kwargs ):
64
- gzip_file = BufferedGzipFile (fileish , * args , ** kwargs )
63
+ def _gzip_open (fileish , mode = 'rb' , compresslevel = 9 ):
64
+
65
+ # is indexed_gzip present?
66
+ try :
67
+ from indexed_gzip import SafeIndexedGzipFile
68
+ have_indexed_gzip = True
69
+ except :
70
+ have_indexed_gzip = False
71
+
72
+ # is this a file? if not we assume it is a string
73
+ is_file = hasattr (fileish , 'read' ) and hasattr (fileish , 'write' ) and \
74
+ hasattr (fileish , 'mode' )
75
+ if is_file :
76
+ mode = file .mode
77
+
78
+ # use indexed_gzip if possible for faster read access
79
+ if mode == 'rb' and have_indexed_gzip :
80
+ kwargs = {'spacing' : 4194304 , 'readbuf_size' : 1048576 }
81
+ if hasattr (fileish , 'read' ) and hasattr (fileish , 'write' ):
82
+ gzip_file = SafeIndexedGzipFile (fid = fileish , ** kwargs )
83
+ else :
84
+ gzip_file = SafeIndexedGzipFile (filename = fileish , ** kwargs )
85
+ else :
86
+ gzip_file = BufferedGzipFile (fileish , mode , compresslevel )
65
87
66
88
# Speedup for #209; attribute not present in in Python 3.5
67
89
# open gzip files with faster reads on large files using larger
0 commit comments