title: Decompress file using zlib - stuck at 256kb limit
body: <p>I hope someone here will be able to help me out with this.
  What I'm trying to do is decompress a zlib compressed file in C# using <a href="https://zlibnet.codeplex.com/" rel="nofollow noreferrer">ZlibNet</a>. (I've also tried <a href="https://dotnetzip.codeplex.com" rel="nofollow noreferrer">DotNetZip</a> and <a href="https://github.com/icsharpcode/SharpZipLib/" rel="nofollow noreferrer">SharpZipLib</a>)</p>
  
  <p>The problem that I'm having is that it'll decompress only the first 256kb, or rather the first 262144 bytes.
  Here's my Decompress method, taken from <a href="https://stackoverflow.com/questions/25382485/c-sharp-decompress-an-android-backup-adb-file">here</a>:</p>
  
  <pre><code>public static byte[] Decompress(byte[] gzip)
      {
          using (var stream = new Ionic.Zlib.ZlibStream(new MemoryStream(gzip), Ionic.Zlib.CompressionMode.Decompress))
          {
              var outStream = new MemoryStream();
              const int size = 999999; //Playing around with various sizes didn't help
              byte[] buffer = new byte[size];
  
              int read;
              while ((read = stream.Read(buffer, 0, size)) &gt; 0)
              {
                  outStream.Write(buffer, 0, read);
                  read = 0;
              }
  
              return outStream.ToArray();
          }
      }
  </code></pre>
  
  <p>Basically, the int (read) gets set to 262144 on the first time the while loop executes, it writes, and then the next pass of the while loop, read gets said to 0, thus making the loop exit and the function return the outStream as an array. (Even though there are still bytes left to be read!)</p>
  
  <p>Thanks in advance to anyone who could help with this!</p>