Skip to main content

wrap_sync_writer

Function wrap_sync_writer 

Source
pub fn wrap_sync_writer<'a, W>(
    w: W,
    c: Compression,
) -> Box<dyn Write + Send + 'a>
where W: Write + Send + 'a,
Available on crate feature compression only.
Expand description

Wrap a sync writer with a streaming encoder. None passes through.

The returned writer finalises the encoder when dropped (gzip writes its 8-byte trailer; zstd’s auto_finish adapter writes the frame epilogue). Because the concrete encoder type is erased behind Box<dyn Write>, callers cannot invoke flate2’s or zstd’s finish() to capture the trailer-write io::Error. Callers can flush() to drain the encoder’s internal buffer mid-stream, but trailer-write errors on drop are negligibly rare and are silently swallowed.

Connectors using this wrapper should drop the box inside a spawn_blocking task body so the trailer write does not block the async runtime, and rely on the surrounding write_all / flush calls to surface earlier I/O errors.