Skip to content

Commit

Permalink
add support for zst writing (#812)
Browse files Browse the repository at this point in the history
* add support for zst writing

* windows dammit

* use our special named_temporary_file decorator
  • Loading branch information
mpenkov authored Mar 21, 2024
1 parent 1b271bf commit 01b14c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions smart_open/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def _handle_gzip(file_obj, mode):


def _handle_zstd(file_obj, mode):
import zstandard as zstd
result = zstd.ZstdDecompressor().stream_reader(file_obj, closefd=True)
import zstandard # type: ignore
result = zstandard.open(filename=file_obj, mode=mode)
return result


Expand Down
12 changes: 12 additions & 0 deletions smart_open/tests/test_smart_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ def named_temporary_file(mode='w+b', prefix=None, suffix=None, delete=True):
logger.error(e)


def test_zst_write():
with named_temporary_file(suffix=".zst") as tmp:
with smart_open.open(tmp.name, "wt") as fout:
print("hello world", file=fout)
print("this is a test", file=fout)

with smart_open.open(tmp.name, "rt") as fin:
got = list(fin)

assert got == ["hello world\n", "this is a test\n"]


class ParseUriTest(unittest.TestCase):
"""
Test ParseUri class.
Expand Down

0 comments on commit 01b14c6

Please sign in to comment.