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

Add a helper for compressing a slice into a vec #86

Open
casey opened this issue Dec 23, 2022 · 0 comments
Open

Add a helper for compressing a slice into a vec #86

casey opened this issue Dec 23, 2022 · 0 comments

Comments

@casey
Copy link

casey commented Dec 23, 2022

A common use case is compressing a &[u8] into a Vec<u8> without doing any I/O. The current docs don't make it clear how to do this.

A google search turns up this forum post with this code snippet:

use std::io::Write;

pub fn compress(input: &[u8]) -> Vec<u8> {
    let mut writer = brotli::CompressorWriter::new(
        Vec::new(),
        4096,
        11,
        22);
    writer.write_all(input).unwrap();
    writer.into_inner()
}

Which is nontrivial to figure out. A helper functions in the root of the crate to compress a &[u8] into a Vec<u8> and to decompress a Vec<u8> into a &[u8] would help a lot with this. (Also, if these functions don't do I/O then perhaps they could be be infallible.)

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

No branches or pull requests

1 participant