ZLIB Decompression - Client Side

后端 未结 8 840
孤街浪徒
孤街浪徒 2020-12-05 01:29

I am receiving data as an \"ZLIB\" compressed inputstream.

Using Javascript/Ajax/JQuery, I need to uncompress it on the client side.

Is the

相关标签:
8条回答
  • 2020-12-05 01:31

    The js-deflate project by dankogai may be what you are looking for. I haven't actually tried it, but the rawinflate.js code seems fairly minimal, and should be able to decompress DEFLATE/zlib:ed data.

    0 讨论(0)
  • 2020-12-05 01:32

    Our library JSXGraph contains the deflate, unzip and gunzip algorithm. Please, have a look at jsxcompressor (a spin-off from JSXGraph, see http://jsxgraph.uni-bayreuth.de/wp/download/) or at Utils.js in the source code.

    0 讨论(0)
  • 2020-12-05 01:34

    Try pako https://github.com/nodeca/pako , it's not just inflate/deflate, but exact zlib port to javascript, with almost all features and options supported. Also, it's the fastest implementation in modern browsers.

    0 讨论(0)
  • 2020-12-05 01:39

    Browserify-zlib works perfectly for me, it uses pako and has the exact same api as zlib. After I struggled for days with compressing/decompressing zlib encoded payloads in client side with pako, I can say that browserify-zlib is really convenient.

    0 讨论(0)
  • 2020-12-05 01:52

    A more recent offering is https://github.com/imaya/zlib.js

    I think it's much better than the alternatives.

    0 讨论(0)
  • 2020-12-05 01:52

    you should see zlib rfc from:zlib rfc

    the javascript inflate code I tested:inflate in Javascript the java code I wrote:

        static public byte[] compress(byte[] input) {
        Deflater deflater = new Deflater();
        deflater.setInput(input, 0, input.length);
        deflater.finish();
        byte[] buff = new byte[input.length + 50];
        deflater.deflate(buff);
    
        int compressedSize = deflater.getTotalOut();
    
        if (deflater.getTotalIn() != input.length)
            return null;
    
        byte[] output = new byte[compressedSize - 6];
    
        System.arraycopy(buff, 2, output, 0, compressedSize - 6);// del head and
                                                                    // foot byte
        return output;
    }
    

    The very Important thing is in deflate in Java you must cut the head 2 byte,foot 4 byte,to get the raw deflate.

    0 讨论(0)
提交回复
热议问题