Hervé Girod
Hervé Girod

Reputation: 547

Using airlift java library to uncompress a file

I am using the https://github.com/airlift/aircompressor 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.

Upvotes: 0

Views: 31

Answers (0)

Related Questions