zstd - Using airlift java library to uncompress a file - Stack Overflow

admin2025-04-15  3

I am using the library to uncompress a byte array of data using the zstd compression algorithm. The documentation of the project (which is actively maintained) is a little sparse. It says to uncompress binary data:

byte[] data = ...

Decompressor decompressor = new ZstdDecompressor();
byte[] uncompressed = new byte[data.length];
int uncompressedSize = decompressor.decompress(compressed, 0, compressedSize, uncompressed, 0, uncompressed.length);

However if I try to adapt this to my code, I have:

 byte[] data = ...

 Decompressor decompressor = new ZstdDecompressor();
 byte[] uncompressed = new byte[data.length];
 int uncompressedSize = decompressor.decompress(data, 0, data.length, uncompressed, 0, 0);
 return uncompressed;

And when I apply this to a zstd content, I have an uncompressedSize of 0 and an empty uncompressed array, filled with 0). What am I doing wrong?

You might say that I should put the uncompressed length of the data as the last argument of the method, but I don't know how to compute this uncompressed length, and it is not explained in the airlift project.

转载请注明原文地址:http://www.anycun.com/QandA/1744729014a86800.html