Skip to content

Commit dc75021

Browse files
author
Arjan Schrijver
committed
Allow passing buffer_size to write_iter and writestr
1 parent 41bb027 commit dc75021

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

zipstream/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,20 @@ def write(self, filename, arcname=None, compress_type=None):
215215
kwargs = {'filename': filename, 'arcname': arcname, 'compress_type': compress_type}
216216
self.paths_to_write.append(kwargs)
217217

218-
def write_iter(self, arcname, iterable, compress_type=None):
218+
def write_iter(self, arcname, iterable, compress_type=None, buffer_size=None):
219219
"""Write the bytes iterable `iterable` to the archive under the name `arcname`."""
220-
kwargs = {'arcname': arcname, 'iterable': iterable, 'compress_type': compress_type}
220+
kwargs = {'arcname': arcname, 'iterable': iterable, 'compress_type': compress_type, 'buffer_size': buffer_size}
221221
self.paths_to_write.append(kwargs)
222222

223-
def writestr(self, arcname, data, compress_type=None):
223+
def writestr(self, arcname, data, compress_type=None, buffer_size=None):
224224
"""
225225
Writes a str into ZipFile by wrapping data as a generator
226226
"""
227227
def _iterable():
228228
yield data
229-
return self.write_iter(arcname, _iterable(), compress_type=compress_type)
229+
return self.write_iter(arcname, _iterable(), compress_type=compress_type, buffer_size=buffer_size)
230230

231-
def __write(self, filename=None, iterable=None, arcname=None, compress_type=None):
231+
def __write(self, filename=None, iterable=None, arcname=None, compress_type=None, buffer_size=None):
232232
"""Put the bytes from filename into the archive under the name
233233
`arcname`."""
234234
if not self.fp:
@@ -265,7 +265,7 @@ def __write(self, filename=None, iterable=None, arcname=None, compress_type=None
265265
if st:
266266
zinfo.file_size = st[6]
267267
else:
268-
zinfo.file_size = 0
268+
zinfo.file_size = buffer_size or 0
269269
zinfo.flag_bits = 0x00
270270
zinfo.flag_bits |= 0x08 # ZIP flag bits, bit 3 indicates presence of data descriptor
271271
zinfo.header_offset = self.fp.tell() # Start of header bytes

0 commit comments

Comments
 (0)