sile / libflate

A Rust implementation of DEFLATE algorithm and related formats (ZLIB, GZIP)
https://docs.rs/libflate
MIT License
180 stars 35 forks source link

Convenience functions? #44

Open phayes opened 4 years ago

phayes commented 4 years ago

Hi there,

I was thinking about opening up a pull request with convenience functions, and was wondering if the maintainers of this crate would be open to merging such a PR.

Specifically, I'm thinking of creating a bunch of functions (one per format mod) with signatures similar to this:

pub fn decode(input: &[u8]) -> Result<Vec<u8>> {
    let mut output = Vec::with_capacity(input.len());
    let mut decoder = Decoder::new(input)?;
    decoder.read_to_end(&mut output)?;
    Ok(output)
}

pub fn encode(input: &[u8]) -> Result(Vec<u8>) {
    let output = Vec::with_capacity(input.len());
    let mut encoder = Encoder::new(&mut output)?;
    encoder.write(input)?;
    let output = encoder.finish().into_result();
    output.shrink_to_fit()
    Ok(output)
}

This code is just back-of-the-napkin sketches of what these convenience functions would look like.

I find that these types of convenience functions are very nice when I run into them in other encoding/decoding crates and was thinking they would make a nice addition here too.

If you give me the go-ahead, I'll work up a proper PR for review.

sile commented 4 years ago

Sounds good. Please go for it!