1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

migrate to brotli crate (#2538)

This commit is contained in:
Rob Ede
2022-01-15 14:03:16 +00:00
committed by GitHub
parent 455d5c460d
commit e7cae5a95b
7 changed files with 40 additions and 26 deletions

View File

@ -41,16 +41,22 @@ pub mod deflate {
pub mod brotli {
use super::*;
use ::brotli2::{read::BrotliDecoder, write::BrotliEncoder};
use ::brotli::{reader::Decompressor as BrotliDecoder, CompressorWriter as BrotliEncoder};
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
let mut encoder = BrotliEncoder::new(Vec::new(), 3);
let mut encoder = BrotliEncoder::new(
Vec::new(),
8 * 1024, // 32 KiB buffer
3, // BROTLI_PARAM_QUALITY
22, // BROTLI_PARAM_LGWIN
);
encoder.write_all(bytes.as_ref()).unwrap();
encoder.finish().unwrap()
encoder.flush().unwrap();
encoder.into_inner()
}
pub fn decode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
let mut decoder = BrotliDecoder::new(bytes.as_ref());
let mut decoder = BrotliDecoder::new(bytes.as_ref(), 8_096);
let mut buf = Vec::new();
decoder.read_to_end(&mut buf).unwrap();
buf