Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just ran into this same issue.</p> <p>For Completeness... (since this stumped me for several hours)</p> <p>In the case of ZLib.Net you also have to call finish(), which usually happens during Close(), before you call return output.ToArray()</p> <p>Otherwise you will get an empty/incomplete byte array from your memory stream, because the ZStream hasn't actually written all of the data yet:</p> <pre><code>public static void CompressData(byte[] inData, out byte[] outData) { using (MemoryStream outMemoryStream = new MemoryStream()) using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, zlibConst.Z_DEFAULT_COMPRESSION)) using (Stream inMemoryStream = new MemoryStream(inData)) { CopyStream(inMemoryStream, outZStream); outZStream.finish(); outData = outMemoryStream.ToArray(); } } public static void DecompressData(byte[] inData, out byte[] outData) { using (MemoryStream outMemoryStream = new MemoryStream()) using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream)) using (Stream inMemoryStream = new MemoryStream(inData)) { CopyStream(inMemoryStream, outZStream); outZStream.finish(); outData = outMemoryStream.ToArray(); } } </code></pre> <p>In this example I'm also using the zlib namespace:</p> <pre><code>using zlib; </code></pre> <p>Originally found in this thread: <a href="https://stackoverflow.com/questions/1327412/zlib-decompression">ZLib decompression</a></p> <p>I don't have enough points to vote up yet, so...</p> <p>Thanks to Tim Greaves for the tip regarding finish before ToArray</p> <p>And Jon Skeet for the tip regarding nesting the using statements for streams (which I like much better than try/finally)</p>
    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. 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.
    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