CodecZlib.jl icon indicating copy to clipboard operation
CodecZlib.jl copied to clipboard

How to write valid empty gzip file?

Open blaiseli opened this issue 6 years ago • 0 comments

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
$

blaiseli avatar Sep 09 '19 16:09 blaiseli