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

Closed
blaiseli opened this issue Sep 9, 2019 · 1 comment
Closed

How to write valid empty gzip file? #47

blaiseli opened this issue Sep 9, 2019 · 1 comment

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
$
@nhz2
Copy link
Member

nhz2 commented Dec 31, 2024

To create an empty gzip file, you can use TranscodingStreams.TOKEN_END.

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

Ideally, this would be simpler.

@nhz2 nhz2 closed this as completed Dec 31, 2024
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