Skip to content

Commit 3d0d364

Browse files
committed
Implement writestr
Fixes #7
1 parent 8c043b0 commit 3d0d364

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

zipstream/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ def write_iter(self, arcname, iterable, compress_type=None):
220220
kwargs = {'arcname': arcname, 'iterable': iterable, 'compress_type': compress_type}
221221
self.paths_to_write.append(kwargs)
222222

223+
def writestr(self, arcname, data, compress_type=None):
224+
"""
225+
Writes a str into ZipFile by wrapping data as a generator
226+
"""
227+
def _iterable():
228+
yield data
229+
return self.write_iter(arcname, _iterable(), compress_type=compress_type)
230+
223231
def __write(self, filename=None, iterable=None, arcname=None, compress_type=None):
224232
"""Put the bytes from filename into the archive under the name
225233
`arcname`."""

0 commit comments

Comments
 (0)