Skip to content
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

Question How to Achieve Inflater nowrap=true #8

Open
oldfishdk opened this issue Jan 27, 2025 · 0 comments
Open

Question How to Achieve Inflater nowrap=true #8

oldfishdk opened this issue Jan 27, 2025 · 0 comments

Comments

@oldfishdk
Copy link

Hi,

Thanks for this amazing repo but I have a quick question: so I am trying to use libdeflate-java to replace Inflater, however in some cases I wasn't able to replicate the results, and it seems to me in some cases, when the compressed data is not well formatted, the libdeflate is more strict about the format and complain about the input data is corrupted.

For example, I am able to use Java's Inflater class to decompress following raw bytes:

        byte[] rawBuffer = new byte[]{
                4, -64, 81, 10, -62, 48, 12, 6, -32, -69, -4, -49, -11, 2, 121, 84, 111, -96, 62, -115, 49, 106, 90, 88,
                -96, 75, -53, -110, 60, -56, -24, -35, -3, 46, -8, 111, 84, 16, 44, -66, -58, -89, 12, -105, -82, -122,
                4, -34, -77, 106, 109, 6, 90, 46, 104, 62, 42, 8, 71, 118, -34, -85, 33, 97, -100, -67, 4, -5, 38, -59,
                64, 11, -18, -17, -57, -19, -13, 122, 98, 77, -56, -52, 61, -44, 55, 41, 6, -46, 104, 109, -82, -13, 15,
                0, 0, -1, -1};
        int offset = rawBuffer.length;
        Inflater inflater = new Inflater(true);
        inflater.setInput(rawBuffer, 0, offset);
        ByteBuffer decompressBuffer = ByteBuffer.allocate(4096 * 1024);
        decompressBuffer.clear();
        try {
            int actualLen = 0;
            while ((actualLen = inflater.inflate(decompressBuffer.array(),
                                                 decompressBuffer.position(),
                                                 decompressBuffer.remaining())) > 0) {
                decompressBuffer.position(decompressBuffer.position() + actualLen);
            }
        } catch (DataFormatException e) {
            throw new RuntimeException(e);
        }
        decompressBuffer.flip();
        System.out.println(ByteUtil.toString(decompressBuffer));

And this would also fail when nowrap parameter is set to false. So I am wondering is there an equivalent way to use libdeflate to replicate this behavior?

Much appreciate your time and response in advance; and kindly let me know if anything is unclear or needs more explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant