actix_http/encoding/
mod.rs

1//! Content-Encoding support.
2
3use std::io;
4
5use bytes::{Bytes, BytesMut};
6
7mod decoder;
8mod encoder;
9
10pub use self::{decoder::Decoder, encoder::Encoder};
11
12/// Special-purpose writer for streaming (de-)compression.
13///
14/// Pre-allocates 8KiB of capacity.
15struct Writer {
16    buf: BytesMut,
17}
18
19impl Writer {
20    fn new() -> Writer {
21        Writer {
22            buf: BytesMut::with_capacity(8192),
23        }
24    }
25
26    fn take(&mut self) -> Bytes {
27        self.buf.split().freeze()
28    }
29}
30
31impl io::Write for Writer {
32    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
33        self.buf.extend_from_slice(buf);
34        Ok(buf.len())
35    }
36
37    fn flush(&mut self) -> io::Result<()> {
38        Ok(())
39    }
40}