-
-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary gzip string not in correct gzip format #54
Comments
var output = require('pako').gzip("{test:'hello world'}", { to: 'string' });
console.log(output.charCodeAt(0).toString(16), output.charCodeAt(1).toString(16));
1f 8b It's your bug in file write encoding. |
I had the same issue when trying to send the data to the server from the browser. I fixed it by doing this:
|
Ok, but that's not related to this package anyhow - pako's job is to produce arrays or binary strings. |
Yes, but it will help those who are trying to use this library. I guess this belongs in a forum an not in the issues. |
@patrickliechty Hi, I m trying out the exact same thing and i m stuck. I m using jquery ajax to post the gzipped string to server but not able to ungzip it on server. Could you brief me the params that needs to be set in AJAX calls to make it work? |
@gandhirajan JS strings are UTF16 (2 bytes per char). You should convert it to binary format first (1 byte per element, utf8 for example) |
@puzrin Hi Puzrin, thanks for your response. I tried that but dint work. Do i need to do some encoding while sending the gzipped string from jquery AJAX to server? |
@puzrin We managed to resolve this issue. The issue was with encoding while sending the gzipped string from Javascript to Server. window.btoa() in javascript and base64 decoding at server side resolved the issue |
That's not the most effective way, but possible. I'd suggest to use utf8 instead of base64. Something like this http://ecmanaut.blogspot.ru/2006/07/encoding-decoding-utf8-in-javascript.html (but note that built-in methods can throw exceptions on invalid char sequences). However i did not compared sizes after different methods use. |
Hi Puzrin, Thanks again for your suggestion. But if i try out the following as mentioned in the link above: |
@gandhirajan I've added working example https://github.com/nodeca/pako/tree/master/examples with both browser and server code. It's not for production but to demonstrate reencoding steps for data flow. See comments. |
@puzrin, Thanks a lot for your response. But was looking for a JAVA sample on server side which i m still figuring out. (Sending gzipped response from server side as AJAX response) |
Hello, I allow myself resurrecting this thread. Here is a Java snippet to handle pako String:
Pako provided the string with:
|
For me, usefull was patrickliechty's example. `
` |
trying to decompress data of uint8Array getting error . const uncompressedData = inflate(uint8ArrayDe, { raw: true }) how can i fix ? The error is invalid block type |
var output = pako.gzip("{test:'hello world'}", { to: 'string' });
Produces this output in a file:
1F C2 8B 08 00 00 00 00 00 00 03 C2 AB 2E 49 2D 2E C2 B1 52 C3 8F 48 C3 8D C3 89 C3 89 57 28 C3 8F 2F C3 8A 49 51 C2 AF 05 00 37 C2 90 12 C3 89 14 00 00 00
According to this:
http://en.wikipedia.org/wiki/Gzip
The output should start with a 1F 8B. It has a C2 in there, otherwise it looks good. I am trying to gzip a big block of JSON in the browser and send it to the backend. The Java backend is throwing an error saying that this is not in GZip format.
The text was updated successfully, but these errors were encountered: