Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is an add-on to MizardX's answer, giving some explanation and background.</p> <p>See <a href="http://www.chiramattel.com/george/blog/2007/09/09/deflatestream-block-length-does-not-match.html" rel="noreferrer">http://www.chiramattel.com/george/blog/2007/09/09/deflatestream-block-length-does-not-match.html</a></p> <p>According to <a href="http://www.ietf.org/rfc/rfc1950.txt" rel="noreferrer">RFC 1950</a>, a zlib stream constructed in the default manner is composed of:</p> <ul> <li>a 2-byte header (e.g. 0x78 0x9C) </li> <li>a deflate stream -- see <a href="http://www.ietf.org/rfc/rfc1951.txt" rel="noreferrer">RFC 1951</a> </li> <li>an Adler-32 checksum of the uncompressed data (4 bytes) </li> </ul> <p>The C# <code>DeflateStream</code> works on (you guessed it) a deflate stream. MizardX's code is telling the zlib module that the data is a raw deflate stream.</p> <p>Observations: (1) One hopes the C# "deflation" method producing a longer string happens only with short input (2) Using the raw deflate stream without the Adler-32 checksum? Bit risky, unless replaced with something better.</p> <p><strong>Updates</strong></p> <p><strong>error message <code>Block length does not match with its complement</code></strong></p> <p>If you are trying to inflate some compressed data with the C# <code>DeflateStream</code> and you get that message, then it is quite possible that you are giving it a a zlib stream, not a deflate stream. </p> <p>See <a href="https://stackoverflow.com/q/762614/12892">How do you use a DeflateStream on part of a file?</a></p> <p>Also copy/paste the error message into a Google search and you will get numerous hits (including the one up the front of this answer) saying much the same thing.</p> <p><strong>The Java <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/util/zip/Deflater.html" rel="noreferrer"><code>Deflater</code></a></strong> ... used by "the website" ... C# DeflateStream "is pretty straightforward and has been tested against the Java implementation". Which of the following possible Java Deflater constructors is the website using?</p> <blockquote> <p><code>public Deflater(int level, boolean nowrap)</code></p> <p>Creates a new compressor using the specified compression level. If 'nowrap' is true then the ZLIB header and checksum fields will not be used in order to support the compression format used in both GZIP and PKZIP.</p> <p><code>public Deflater(int level)</code></p> <p>Creates a new compressor using the specified compression level. Compressed data will be generated in ZLIB format.</p> <p><code>public Deflater()</code></p> <p>Creates a new compressor with the default compression level. Compressed data will be generated in ZLIB format. </p> </blockquote> <p><strong>A one-line deflater</strong> after throwing away the 2-byte zlib header and the 4-byte checksum: </p> <pre><code>uncompressed_string.encode('zlib')[2:-4] # does not work in Python 3.x </code></pre> <p>or </p> <pre><code>zlib.compress(uncompressed_string)[2:-4] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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