Skip to content

Commit

Permalink
Add filename support for GZIPCompressedStream (#4)
Browse files Browse the repository at this point in the history
ADDED:
 - new parameter "filename" which enables naming of the compressed stream
MODIFIED:
 - incorporated "filename" in the constructor call "gzip.GzipFile"
REMOVED:
 - nothing
  • Loading branch information
0x446 committed Dec 8, 2021
1 parent c3d3f92 commit 45ca64a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gzip_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@


class GZIPCompressedStream(io.RawIOBase):
def __init__(self, stream: BinaryIO, *, compression_level: int):
def __init__(self, stream: BinaryIO, *, compression_level: int,
filename: str = None):
assert 1 <= compression_level <= 9

self._compression_level = compression_level
self._stream = stream

self._compressed_stream = io.BytesIO()
self._compressor = gzip.GzipFile(
filename=filename,
mode='wb',
fileobj=self._compressed_stream,
compresslevel=compression_level
Expand Down

0 comments on commit 45ca64a

Please sign in to comment.