ZLIB Decompression - Client Side

后端 未结 8 856
孤街浪徒
孤街浪徒 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: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.

提交回复
热议问题