airlift / aircompressor

A port of Snappy, LZO, LZ4, and Zstandard to Java
Apache License 2.0
570 stars 113 forks source link

How should ZstdDecompressor.getDecompressedSize work? #106

Open mcraiha opened 4 years ago

mcraiha commented 4 years ago

Hi,

I am trying to port ZstdDecompressor to C# and I have hard time understanding how ZstdDecompressor.getDecompressedSize should work.

If I modify testDecompressWithOutputPaddingAndChecksum() to following

public void testDecompressWithOutputPaddingAndChecksum()
            throws IOException
    {
        int padding = 1021;

        byte[] compressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/with-checksum.zst"));
        byte[] uncompressed = Resources.toByteArray(getClass().getClassLoader().getResource("data/zstd/with-checksum"));

        byte[] output = new byte[uncompressed.length + padding * 2]; // pre + post padding
        int decompressedSize = getDecompressor().decompress(compressed, 0, compressed.length, output, padding, output.length);

        long decompressedSize2 = ZstdDecompressor.getDecompressedSize(compressed, 0, compressed.length);

        assertEquals(decompressedSize2, 11359, "Should be equal");
        assertByteArraysEqual(uncompressed, 0, uncompressed.length, output, padding, decompressedSize);
    }

then the decompressedSize2 has value -1 and test fails. Am I missing something in here?