Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c-ext/compressionwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static PyObject *ZstdCompressionWriter_write(ZstdCompressionWriter *self,

if (self->closed) {
PyErr_SetString(PyExc_ValueError, "stream is closed");
return NULL;
goto finally;
}

self->output.pos = 0;
Expand Down
2 changes: 1 addition & 1 deletion c-ext/decompressionwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static PyObject *ZstdDecompressionWriter_write(ZstdDecompressionWriter *self,

if (self->closed) {
PyErr_SetString(PyExc_ValueError, "stream is closed");
return NULL;
goto finally;
}

output.dst = PyMem_Malloc(self->outSize);
Expand Down
12 changes: 12 additions & 0 deletions tests/test_compressor_stream_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@


class TestCompressor_stream_writer(unittest.TestCase):
def test_closed_write_releases_buffer(self):
ctx = zstd.ZstdCompressor()
writer = ctx.stream_writer(io.BytesIO())
writer.close()

for data in (bytearray(), bytearray(b"foo")):
with self.subTest(data=data):
for _ in range(2):
with self.assertRaisesRegex(ValueError, "stream is closed"):
writer.write(data)
data.extend(b"bar")

def test_io_api(self):
buffer = io.BytesIO()
cctx = zstd.ZstdCompressor()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_decompressor_stream_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ def decompress_via_writer(data):


class TestDecompressor_stream_writer(unittest.TestCase):
def test_closed_write_releases_buffer(self):
ctx = zstd.ZstdDecompressor()
writer = ctx.stream_writer(io.BytesIO())
writer.close()

for data in (bytearray(), bytearray(b"foo")):
with self.subTest(data=data):
for _ in range(2):
with self.assertRaisesRegex(ValueError, "stream is closed"):
writer.write(data)
data.extend(b"bar")

def test_io_api(self):
buffer = io.BytesIO()
dctx = zstd.ZstdDecompressor()
Expand Down