File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 24
24
import argparse
25
25
import io
26
26
import os
27
+ import _compression
27
28
28
29
# We import a copy of the gzip module so we can use that to define the classes
29
30
# here and replace the zlib module with the isal_zlib module. This way the
@@ -142,15 +143,12 @@ def write(self,data):
142
143
return length
143
144
144
145
145
- class _IGzipReader (gzip . _GzipReader ):
146
+ class _IGzipReader (_compression . DecompressReader ):
146
147
def __init__ (self , fp ):
147
- super ().__init__ (fp )
148
- self ._decompfactory = isal_zlib .decompressobj
149
- self ._decompressor = self ._decompfactory (** self ._decomp_args )
148
+ super ().__init__ (fp , isal_zlib .decompressobj ,
149
+ wbits = 16 + isal_zlib .MAX_WBITS )
150
150
151
- def _add_read_data (self , data ):
152
- self ._crc = isal_zlib .crc32 (data , self ._crc )
153
- self ._stream_size += len (data )
151
+
154
152
155
153
# Plagiarized from gzip.py from python's stdlib.
156
154
def compress (data , compresslevel = _COMPRESS_LEVEL_BEST , * , mtime = None ):
Original file line number Diff line number Diff line change @@ -353,6 +353,7 @@ cdef class Decompress:
353
353
cdef public bytes unused_data
354
354
cdef public unconsumed_tail
355
355
cdef public bint eof
356
+ cdef public bint needs_input
356
357
cdef bint is_initialised
357
358
cdef inflate_state stream
358
359
cdef unsigned char * obuf
@@ -379,6 +380,7 @@ cdef class Decompress:
379
380
self .unconsumed_tail = b" "
380
381
self .eof = 0
381
382
self .is_initialised = 1
383
+ self .needs_input = 1
382
384
383
385
def __dealloc__ (self ):
384
386
if self .obuf is not NULL :
@@ -396,6 +398,8 @@ cdef class Decompress:
396
398
elif max_length < 0 :
397
399
raise ValueError (" max_length can not be smaller than 0" )
398
400
401
+ if data == b" " :
402
+ data = self .unconsumed_tail
399
403
cdef Py_ssize_t total_length = len (data)
400
404
if total_length > UINT32_MAX:
401
405
# Zlib allows a maximum of 64 KB (16-bit length) and python has
@@ -454,6 +458,7 @@ cdef class Decompress:
454
458
# 2. All input data was consumed. Clear unconsumed_tail.
455
459
unused_bytes = self .stream.avail_in
456
460
self .unconsumed_tail = data[- unused_bytes:]
461
+ self .needs_input = 0 if unused_bytes > 0 else 1
457
462
return b" " .join(out)
458
463
459
464
def flush (self , Py_ssize_t length = DEF_BUF_SIZE):
You can’t perform that action at this time.
0 commit comments