title: JavaScript/C# Inflate and deflate data sent through XHR
body: <p>I must inflate some data (csv file chunks actually) client side in JavaScript, and deflate it on server side in C#.</p>
  
  <p>On client side I'm using pako, and it looks like this:</p>
  
  <pre><code>var fileReader = new FileReader();
  
  fileReader.onload = function(progressEvent) {
      var arrayBuffer = this.result;
      var binData = new Uint8Array(arrayBuffer);
  
      var data = pako.deflate(binData);
  
      var dataBlob = new Blob(data, { "type": "application/zlib" });
      callback(dataBlob);
  };
  
  fileReader.readAsArrayBuffer(bytes);
  </code></pre>
  
  <p>It seems to be working well. I say "seem" because if I save the data received on server side, I get a string looking like this:</p>
  
  <pre><code>1201562201899117927731141602491...
  </code></pre>
  
  <p>I <a href="https://stackoverflow.com/a/17176881/6061217">found out</a> that ZLib compressed data is supposed to start with 0x78 and 0x9C, and 120 is decimal for 0x78 and 156 is decimal for 0x9C, so client side inflate seems OK.</p>
  
  <p>Problem is on server side I can't manage to deflate the data. This is what my code looks like:</p>
  
  <pre><code>// Read past the first two bytes of the zlib header
  inputStream.Seek(2, SeekOrigin.Begin);
  
  using (var zipStream = new DeflateStream(inputStream, CompressionMode.Decompress))
  using (FileStream fileStream = File.Create(filePath))
  {
      zipStream.CopyTo(fileStream);
  }
  </code></pre>
  
  <p>I get an error from DeflateStream constructor saying the data is not quite right.</p>
  
  <p>Now here is what I gathered so far:</p>
  
  <ul>
  <li>If I add a { "to": "string" } to pako.deflate, it returns some binary string instead of a Uint8Array. It looks quite like what I get when I inflate the data server side, so that's probably what C# DeflateStream is expecting.</li>
  <li>Data is sent through XHR FormData, which expects a Blob, which seems to always transform the data to a decimal string.</li>
  <li>I read the data on server side with HttpContent.ReadAsStreamAsync().</li>
  </ul>
  
  <p>What do you think I should do to properly deflate the data server side?</p>