Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can still use the <a href="https://docs.python.org/2/library/zlib.html" rel="noreferrer"><code>zlib</code></a> module to inflate/deflate data. The <a href="https://docs.python.org/2/library/gzip.html" rel="noreferrer"><code>gzip</code></a> module uses it internally, but adds a file-header to make it into a gzip-file. Looking at the <a href="http://hg.python.org/cpython/file/8ebda8114e97/Lib/gzip.py" rel="noreferrer"><code>gzip.py</code></a> file, something like this could work:</p> <pre><code>import zlib def deflate(data, compresslevel=9): compress = zlib.compressobj( compresslevel, # level: 0-9 zlib.DEFLATED, # method: must be DEFLATED -zlib.MAX_WBITS, # window size in bits: # -15..-8: negate, suppress header # 8..15: normal # 16..30: subtract 16, gzip header zlib.DEF_MEM_LEVEL, # mem level: 1..8/9 0 # strategy: # 0 = Z_DEFAULT_STRATEGY # 1 = Z_FILTERED # 2 = Z_HUFFMAN_ONLY # 3 = Z_RLE # 4 = Z_FIXED ) deflated = compress.compress(data) deflated += compress.flush() return deflated def inflate(data): decompress = zlib.decompressobj( -zlib.MAX_WBITS # see above ) inflated = decompress.decompress(data) inflated += decompress.flush() return inflated </code></pre> <p>I don't know if this corresponds exactly to whatever your server requires, but those two functions are able to round-trip any data I tried.</p> <p>The parameters maps directly to what is passed to the zlib library functions.</p> <p><strong>Python</strong> &rArr; <strong>C</strong><br> <code>zlib.compressobj(...)</code> &rArr; <code>deflateInit(...)</code><br> <code>compressobj.compress(...)</code> &rArr; <code>deflate(...)</code><br> <code>zlib.decompressobj(...)</code> &rArr; <code>inflateInit(...)</code><br> <code>decompressobj.decompress(...)</code> &rArr; <code>inflate(...)</code></p> <p>The constructors create the structure and populate it with default values, and pass it along to the init-functions. The <code>compress</code>/<code>decompress</code> methods update the structure and pass it to <code>inflate</code>/<code>deflate</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload