Roland Hedberg <roland <at> catalogix.se> writes: > I have a problem with zlib and compressing/decompressing according to > RFC 1951. > > It seems like I can decompress, something compressed according to RFC > 1951 by someone else, provided I set wbits to something negative (used > -8 but I guess any negative number would work?).
-15 will get you a 32KB window which is the best and is the default in APIs where a default is possible. original_data = zlib.decompress(deflated_data, -15) > But how can I compress using zlib so it doesn't add a gzip header ? You don't need to, because zlib doesn't add a gzip header (RFC 1952) -- it adds a zlib header (RFC 1950) ... without out any frills (i.e. default case) a zlib stream is a 2-byte header plus the RFC 1951 deflate stream plus a 4-byte checksum. deflated_data = zlib.compress(uncompressed_data)[2:-4] Coincidentally this question arose elsewhere very recently: see http://stackoverflow.com/questions/1089662/ python-inflate-and-deflate-implementations concatenate the above two lines -- gmane <= 80-byte line limit 8-P BTW FWIW, one can evidently force zlib to do a gzip wrapper instead of a zlib wrapper by setting wbits to positive > 15 [brilliant API design], but one might be better off using the gzip module directly ... HTH, John -- http://mail.python.org/mailman/listinfo/python-list