@@ -67,14 +67,10 @@ def open(filename, mode="rb", compresslevel=igzip._COMPRESS_LEVEL_TRADEOFF,
67
67
gzip_file = io .BufferedReader (
68
68
_ThreadedGzipReader (binary_file , block_size = block_size ))
69
69
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 )
74
70
gzip_file = io .BufferedWriter (
75
71
_ThreadedGzipWriter (
76
72
fp = binary_file ,
77
- buffer_size = compress_buffer_size ,
73
+ block_size = block_size ,
78
74
level = compresslevel ,
79
75
threads = threads
80
76
),
@@ -201,15 +197,19 @@ def __init__(self,
201
197
level : int = isal_zlib .ISAL_DEFAULT_COMPRESSION ,
202
198
threads : int = 1 ,
203
199
queue_size : int = 1 ,
204
- buffer_size : int = 1024 * 1024 ,
200
+ block_size : int = 1024 * 1024 ,
205
201
):
206
202
self .lock = threading .Lock ()
207
203
self .exception : Optional [Exception ] = None
208
204
self .raw = fp
209
205
self .level = level
210
206
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
211
211
self .compressors : List [isal_zlib ._ParallelCompress ] = [
212
- isal_zlib ._ParallelCompress (buffersize = buffer_size ,
212
+ isal_zlib ._ParallelCompress (buffersize = compress_buffer_size ,
213
213
level = level ) for _ in range (threads )
214
214
]
215
215
if threads > 1 :
@@ -273,8 +273,19 @@ def write(self, b) -> int:
273
273
with self .lock :
274
274
if self .exception :
275
275
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
277
287
data = bytes (b )
288
+ index = self .index
278
289
zdict = memoryview (self .previous_block )[- DEFLATE_WINDOW_SIZE :]
279
290
self .previous_block = data
280
291
self .index += 1
0 commit comments