Add a helper for compressing a slice into a vec
- Dominant language
- Rust
- Stars
- 943
- Forks
- 109
- Avg merge
- 8d 3h
- Merged PRs (30d)
- 1
Description
A common use case is compressing a `&[u8]` into a `Vec` 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](https://users.rust-lang.org/t/brotli-compression/51645) with this code snippet:
```
use std::io::Write;
pub fn compress(input: &[u8]) -> Vec {
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` and to decompress a `Vec` 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.)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.