Gzip without server support?

I wrote a CSS server that performs minimization and basic replace / replace. The server uses node.js.

I want gzip my answer from this server. As the IRC says, there is currently no gzip library in the node.js file, so I'm trying to do this manually from the command line (since I use gzip only when not in the cache).

I have 'gzip -c -9 -q ' + tempFile file data in a temporary file and then use exec to call 'gzip -c -9 -q ' + tempFile . I correctly return the compressed data (it seems) and send the correct Content-Encoding header as 'gzip' , but Chrome reports:

Error 330 (net::ERR_CONTENT_DECODING_FAILED): Unknown error .

In addition, some independent gzip testers online also do not work (not just Chrome).

I guess this is something simple that I don’t know about generating gzip blocks for browsers, since I never tried to do it manually.

Any help would be helpful. The server is very fast, but I need to compress the content to get the best performance for end users.

Thank you

UPDATE I confirmed that my Content-Length is correct

+5
source share
2 answers

Have you updated Content-Length to fit gzipped size? It looks like it might ruin the decoding.

+1
source

Node still crashes and does not seem to have good binary data processing yet.

Node string encodings are ascii, binary, and utf8. [...] "binary" only look [s] at the first 8 bits of the 16-bit characters of the JavaScript string. The problem is that ECMA strings are 16-bit character strings. If you use UTF-8 (this is the default), then when reading into a string, there is some normalization, and this corrupts gzip. If you are using ascii, this obviously will not work.

It will work if you use binary coding for both reading and writing . The top 8 bits of the Javascript line character are simply not used. If not, try sending files directly to the client without any download to Javascript strings, possibly using a proxy in front of Node.

I myself hope that the Google V8 engine implements a true binary string data type, something like this sentence http://groups.google.com/group/nodejs/browse_thread/thread/648a0f5ed2c95211/ef89acfe538931a1?lnk=gst&q=binary+type # ef89acfe538931a1

CommonJS also offers Binary / B , and since Node is trying to follow CommonJS, there is hope for the future.

Edit I just discovered a net2 branch Node that contains a binary buffer (see src / node_buffer.h). This is part of a complete network review.

+2
source

Source: https://habr.com/ru/post/1301994/


All Articles