lz4 / lz4-java

LZ4 compression for Java
Apache License 2.0
1.09k stars 248 forks source link

LZ4SafeDecompressor requires length #179

Closed sksamuel closed 2 years ago

sksamuel commented 3 years ago

Hi,

The docs make it seem like decompressed length is not required for LZ4SafeDecompressor but it requires it. Is the solution just make a huge array that you know will be big enough ? If so, what's the best size to choose?

odaira commented 3 years ago

Is the solution just make a huge array that you know will be big enough ?

Correct, but LZ4SafeDecompressor/LZ4FastDecomparessor are low-level APIs, and users will usually know the decompressed size (e.g. when they compress a fixed-sized buffer) or will store the decompressed size somewhere.

If so, what's the best size to choose?

Unfortunately, there is no known "best size", and the maximum compression ratio of lz4 is 255, which would be too large.

If you need to compress/decompress unknown-sized data, it would be a good indication that you should use the stream-oriented APIs, i.e. LZ4FrameInputStream/LZ4FrameOutputStream. If you really need block-oriented APIs, LZ4CompressorWithLength/LZ4DecompressorWithLength are also provided, for convenience.

See also #26 and #88.

sksamuel commented 3 years ago

The stream orientated APIs seem great.

odaira commented 2 years ago

Would you need more help?

sksamuel commented 2 years ago

I haven't tried your suggestion yet, but I'm sure it will work. We can close this. Thanks for your help :)

On Tue, 24 Aug 2021 at 14:50, Rei Odaira @.***> wrote:

Would you need more help?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lz4/lz4-java/issues/179#issuecomment-904928007, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGQ2WDTIFM6LYGLRCJLT6PZZFANCNFSM5BARZ67Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .