I must inflate some data (csv file chunks actually) client side in JavaScript, and deflate it on server side in C#.
On client side I'm using pako, and it looks like this:
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);
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:
1201562201899117927731141602491...
I found out 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.
Problem is on server side I can't manage to deflate the data. This is what my code looks like:
// 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);
}
I get an error from DeflateStream constructor saying the data is not quite right.
Now here is what I gathered so far:
What do you think I should do to properly deflate the data server side?
Pass the data to the blob constructor in an array
var dataBlob = new Blob([data], { "type": "application/zlib" });
From MDN
var aBlob = new Blob( array, options );
Parameters