Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example Mismatch #90

Open
cneberg opened this issue Feb 28, 2020 · 2 comments
Open

Example Mismatch #90

cneberg opened this issue Feb 28, 2020 · 2 comments

Comments

@cneberg
Copy link

cneberg commented Feb 28, 2020

Python example to compress a string with snappy can't be decompressed with the command line tool example to decompress a file with the same string in it. The command line tool should be expanded to support this use case, or at the very least a second programmatic example explaining how to create a file which can be read with the tool.

import snappy
import os
fout = open('compressed_file.snappy', 'w')
buf ='hello world'
buf = snappy.compress(buf)
fout.write(buf)
fout.close()
os.system("python -m snappy -d compressed_file.snappy uncompressed_file");

UncompressError: chunk truncated

@martindurant
Copy link
Member

Indeed, it is not obvious that files should be in the "framing format" rather than the simpler, implicit snappy.de/compress functions. This is the code that would do it

import snappy
import io
src = io.BytesIO(b'hello world')
with open('compressed_file.snappy', 'wb') as dst:
    snappy.stream_compress(src, dst)

(substitute an open input file for src instead of the in-memory buffer, if desired)

Please propose as a pull request!

@martindurant
Copy link
Member

(by the way, the equivalent function call is snappy.StreamCompressor().compress(b'hello world'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants