johnfound johnfound - 1 month ago 19
Linux Question

How to create bare deflate stream from file in Linux?

So, all tools that I know put the compressed by deflate algorithm stream in some file format with headers, file names, additional check sums etc.

Is it possible to create directly a file containing only the deflate compressed stream, as described in RFC-1951, using some of standard Linux tools + bash?

Answer

I've seen some development tools which can do it, but with normal tools it is not (immediately) possible, because the raw compressed stream is generally useless.

Otherwise, on Linux, gzip --no-name results in compressed stream with header of fixed size of 10 bytes. You can trim it with dd.E.g.:

cat something | gzip --no-name | \
  ( dd of=/dev/null bs=1 count=10; cat > gzip-without-header )

All what's left, is to strip the last 8 bytes (CRC, uncompressed size) from the output file:

dd if=gzip-without-header of=gzip-without-anything \
    bs=1 count=$[ `stat -c '%s' gzip-without-header` - 8 ]

P.S. GZip file format is defined in RFC1952.

Comments