@@ -67,14 +67,10 @@ def open(filename, mode="rb", compresslevel=igzip._COMPRESS_LEVEL_TRADEOFF,
6767 gzip_file = io .BufferedReader (
6868 _ThreadedGzipReader (binary_file , block_size = block_size ))
6969 else :
70- # Deflating random data results in an output a little larger than the
71- # input. Making the output buffer 10% larger is sufficient overkill.
72- compress_buffer_size = block_size + max (
73- block_size // 10 , 500 )
7470 gzip_file = io .BufferedWriter (
7571 _ThreadedGzipWriter (
7672 fp = binary_file ,
77- buffer_size = compress_buffer_size ,
73+ block_size = block_size ,
7874 level = compresslevel ,
7975 threads = threads
8076 ),
@@ -201,15 +197,19 @@ def __init__(self,
201197 level : int = isal_zlib .ISAL_DEFAULT_COMPRESSION ,
202198 threads : int = 1 ,
203199 queue_size : int = 1 ,
204- buffer_size : int = 1024 * 1024 ,
200+ block_size : int = 1024 * 1024 ,
205201 ):
206202 self .lock = threading .Lock ()
207203 self .exception : Optional [Exception ] = None
208204 self .raw = fp
209205 self .level = level
210206 self .previous_block = b""
207+ # Deflating random data results in an output a little larger than the
208+ # input. Making the output buffer 10% larger is sufficient overkill.
209+ compress_buffer_size = block_size + max (block_size // 10 , 500 )
210+ self .block_size = block_size
211211 self .compressors : List [isal_zlib ._ParallelCompress ] = [
212- isal_zlib ._ParallelCompress (buffersize = buffer_size ,
212+ isal_zlib ._ParallelCompress (buffersize = compress_buffer_size ,
213213 level = level ) for _ in range (threads )
214214 ]
215215 if threads > 1 :
@@ -273,8 +273,19 @@ def write(self, b) -> int:
273273 with self .lock :
274274 if self .exception :
275275 raise self .exception
276- index = self .index
276+ length = b .nbytes if isinstance (b , memoryview ) else len (b )
277+ if length > self .block_size :
278+ # write smaller chunks and return the result
279+ memview = memoryview (b )
280+ start = 0
281+ total_written = 0
282+ while start < length :
283+ total_written += self .write (
284+ memview [start :start + self .block_size ])
285+ start += self .block_size
286+ return total_written
277287 data = bytes (b )
288+ index = self .index
278289 zdict = memoryview (self .previous_block )[- DEFLATE_WINDOW_SIZE :]
279290 self .previous_block = data
280291 self .index += 1
0 commit comments