1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use brotli2::CompressParams;
use bytes::Bytes;
use futures_core::stream::Stream;
use std::io::Result;
decoder! {
#[cfg_attr(docsrs, doc(cfg(feature = "brotli")))]
BrotliDecoder
}
encoder! {
#[cfg_attr(docsrs, doc(cfg(feature = "brotli")))]
BrotliEncoder
}
impl<S: Stream<Item = Result<Bytes>>> BrotliEncoder<S> {
pub fn new(stream: S, level: u32) -> BrotliEncoder<S> {
let mut params = CompressParams::new();
params.quality(level);
BrotliEncoder::from_params(stream, ¶ms)
}
pub fn from_params(stream: S, params: &CompressParams) -> BrotliEncoder<S> {
BrotliEncoder {
inner: crate::stream::generic::Encoder::new(
stream,
crate::codec::BrotliEncoder::new(params),
),
}
}
}