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

Fix LZ4SafeDecompressor javadoc #168

Closed
wants to merge 1 commit into from
Closed

Conversation

wsargent
Copy link

@wsargent wsargent commented Oct 7, 2020

No description provided.

@odaira
Copy link
Member

odaira commented Oct 7, 2020

LZ4SafeDecompressor does require the size of the compressed data (i.e. the size after compression) to be known, doesn't it?

@wsargent
Copy link
Author

wsargent commented Oct 7, 2020

I'm obviously confused, but I don't understand how decompression in LZ4 works -- the decompression byte array needs to be a certain size, but how do you know how large it should be if you don't have access to the decompressed size itself?

@wsargent wsargent closed this Oct 8, 2020
@wsargent wsargent deleted the patch-1 branch October 8, 2020 20:01
@odaira
Copy link
Member

odaira commented Oct 9, 2020

There is no simple way to know how large the decompressed data will be. The maximum possible inflation rate of LZ4 is 256x, but it would be too much to prepare a buffer of 256x the size of the compressed data in most cases. LZ4FastDecompressor and LZ4SafeDecompressor are low-level APIs. They just expose the original C APIs of the LZ4 library. You need to get the original size by storing it somewhere else. These APIs are designed so for maximum flexibility.

Most people would use LZ4FrameOutputStream/LZ4FrameInputStream if they do not want to manage the original size themselves, especially when they exchange LZ4-compressed data through files or network. If you really prefer block-oriented API to stream-oriented one, LZ4CompressorWithLength/LZ4DecompressorWithLength are provided, but please note that they are not compatible with the LZ4 block format or LZ4 frame format.

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

Successfully merging this pull request may close these issues.

2 participants