Reworked gzip/deflate encoding to reduce duplication