pub struct Encoder<W: Write> { /* private fields */ }Expand description
Streaming compressor implementing std::io::Write.
Writes are forwarded through a CStream and the resulting ZXC frame is
flushed to the inner writer. The frame is finalised (residual block, EOF
marker, and footer) by Encoder::finish. Drop performs a best-effort
finish but cannot surface errors — prefer Encoder::finish when error
handling matters.
Encoder is single-threaded; one stream per writer.
§Example
use std::io::Write;
use zxc::Encoder;
let sink = Vec::new();
let mut enc = Encoder::new(sink).unwrap();
enc.write_all(b"hello world").unwrap();
let compressed: Vec<u8> = enc.finish().unwrap();Implementations§
Source§impl<W: Write> Encoder<W>
impl<W: Write> Encoder<W>
Sourcepub fn new(writer: W) -> Result<Self, Error>
pub fn new(writer: W) -> Result<Self, Error>
Creates an encoder with default compression options: no checksum.
Sourcepub fn with_options(
writer: W,
opts: Option<&CompressOptions>,
) -> Result<Self, Error>
pub fn with_options( writer: W, opts: Option<&CompressOptions>, ) -> Result<Self, Error>
Creates an encoder honouring opts. opts.seekable is ignored (push
API is single-threaded and never emits a seek table).
Trait Implementations§
Source§impl<W: Write> Write for Encoder<W>
impl<W: Write> Write for Encoder<W>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush is a no-op on the inner writer side: the ZXC frame is only valid
once finalised, so partial flushes would produce a corrupted frame.
Use Encoder::finish to complete the frame.
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)