support gzip encoding

this add auto-detection of gzip files for decompression, and an optional parameter to compress for selecting gzip encoding. (it also fixes a bug in the use of total_in and adds partial support for headers, although it doesn't use that)