PSeitz / lz4_flex

Fastest pure Rust implementation of LZ4 compression/decompression.
MIT License
441 stars 28 forks source link

Allow for reusing buffer in block compression #102

Closed CosmicHorrorDev closed 1 year ago

CosmicHorrorDev commented 1 year ago

Currently the block (de)compression functions return a freshly allocated Vec per call. A common alternative when designing an API for putting data somewhere is to take a output: &mut Vec<u8> so that you can reuse the same buffer over multiple calls

This would be a breaking change, but shouldn't affect performance in the existing benchmarks

PSeitz commented 1 year ago

That's already possible with lz4_flex::block::compress_into

CosmicHorrorDev commented 1 year ago

That only works if output is already large enough to hold the result. A &mut Vec<u8> can be resized larger

PSeitz commented 1 year ago

Yes you need to call buffer.resize(get_maximum_output_size(input), 0) before calling compress_into

CosmicHorrorDev commented 1 year ago

Ah I forgot that get_maximum_output_size() is public. It's a bit clunky, but works so I'll go ahead and close