2021-02-11 22:39:54 +00:00
|
|
|
//! Content-Encoding support.
|
|
|
|
|
2019-03-26 22:14:32 +00:00
|
|
|
use std::io;
|
|
|
|
|
|
|
|
use bytes::{Bytes, BytesMut};
|
|
|
|
|
|
|
|
mod decoder;
|
|
|
|
mod encoder;
|
|
|
|
|
2023-07-17 01:38:12 +00:00
|
|
|
pub use self::{decoder::Decoder, encoder::Encoder};
|
2019-03-26 22:14:32 +00:00
|
|
|
|
2021-12-04 19:40:47 +00:00
|
|
|
/// Special-purpose writer for streaming (de-)compression.
|
|
|
|
///
|
|
|
|
/// Pre-allocates 8KiB of capacity.
|
2019-03-26 22:14:32 +00:00
|
|
|
pub(self) struct Writer {
|
|
|
|
buf: BytesMut,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Writer {
|
|
|
|
fn new() -> Writer {
|
|
|
|
Writer {
|
|
|
|
buf: BytesMut::with_capacity(8192),
|
|
|
|
}
|
|
|
|
}
|
2019-12-20 07:50:07 +00:00
|
|
|
|
2019-03-26 22:14:32 +00:00
|
|
|
fn take(&mut self) -> Bytes {
|
2019-12-05 17:35:43 +00:00
|
|
|
self.buf.split().freeze()
|
2019-03-26 22:14:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl io::Write for Writer {
|
|
|
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
|
|
|
self.buf.extend_from_slice(buf);
|
|
|
|
Ok(buf.len())
|
|
|
|
}
|
2019-12-20 07:50:07 +00:00
|
|
|
|
2019-03-26 22:14:32 +00:00
|
|
|
fn flush(&mut self) -> io::Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|