mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-19 14:14:41 +01:00
36 lines
633 B
Rust
36 lines
633 B
Rust
|
//! Content-Encoding support
|
||
|
use std::io;
|
||
|
|
||
|
use bytes::{Bytes, BytesMut};
|
||
|
|
||
|
mod decoder;
|
||
|
mod encoder;
|
||
|
|
||
|
pub use self::decoder::Decoder;
|
||
|
pub use self::encoder::Encoder;
|
||
|
|
||
|
pub(self) struct Writer {
|
||
|
buf: BytesMut,
|
||
|
}
|
||
|
|
||
|
impl Writer {
|
||
|
fn new() -> Writer {
|
||
|
Writer {
|
||
|
buf: BytesMut::with_capacity(8192),
|
||
|
}
|
||
|
}
|
||
|
fn take(&mut self) -> Bytes {
|
||
|
self.buf.take().freeze()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl io::Write for Writer {
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||
|
self.buf.extend_from_slice(buf);
|
||
|
Ok(buf.len())
|
||
|
}
|
||
|
fn flush(&mut self) -> io::Result<()> {
|
||
|
Ok(())
|
||
|
}
|
||
|
}
|