image-rs / weezl

LZW en- and decoding that goes weeeee!
Apache License 2.0
25 stars 7 forks source link

Add into_vec for simple in-memory coding #24

Closed HeroicKatora closed 3 years ago

HeroicKatora commented 3 years ago

Closes: #23 @s3bk

I don't like the idea of having a separate set of free standing methods due to the number of constructor arguments and the complications in terms of adding new constructors (e.g. a GNU compress compatible option). Instead, I chose an interface where the simplest in-memory case now looks like so:

let data = Decoder::new(BitOrder::Msb, 9).decode(compressed)?;

This adds some special treatment for vectors (which previously were handled via io::Write and into_stream) but on the other hand this will allow for forward compatible, slight performance gain if we add decoding/encoding into uninitialized buffers in the future. It also adds a useful adapter for the common no_std, alloc combination.

s3bk commented 3 years ago

Thanks! That definitely solves my problem.