I've attached a simple module I use to encode/decode gzip files. Hope
this helps.
zlib can do this for you. Then you don't need to put up so much pressure
on the GC, and there's no need for manual header parsing/generation.
Quoting the docs for deflateInit2:
"windowBits can also be greater than 15 for optional gzip encoding. Add
16 to windowBits to write a simple gzip header and trailer around the
compressed data instead of a zlib wrapper."
You can also enable automatic header detection for zlib/gzip decoding in
inflateInit2.
But I think you'll have to stop using std.zlib to use this functionality.