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

How to write valid empty gzip file? #47

Open
blaiseli opened this issue Sep 9, 2019 · 0 comments
Open

How to write valid empty gzip file? #47

blaiseli opened this issue Sep 9, 2019 · 0 comments

Comments

@blaiseli
Copy link

blaiseli commented Sep 9, 2019

How should one proceed to generate a valid empty gzip file using CodecZlib?

Here is what I tried:

import CodecZlib
gz = CodecZlib
fh = gz.GzipCompressorStream(open("test_out.gz", "w"))
close(fh)

However, the following results in an empty file (zero bytes) that gzip cannot handle properly:

$ zcat test_out.gz 

gzip: test_out.gz: unexpected end of file
$

I can generate valid gzipped file using Python:

>>> from gzip import open as gzopen
>>> with gzopen("test_out.gz", "w") as fh:
...     pass
... 

The resulting file is not really empty (a few bytes), and gzip does not complain when I try to zcat it:

$ zcat test_out.gz
$
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

1 participant