pub struct DeflateSink<W> { /* private fields */ }Expand description
A streaming raw-DEFLATE encoder over an async writer.
The sink is the encoder of archive-mode content objects. The stored
.filez payload is its output.
Each poll_write compresses the chunk of the caller into an output buffer
of 64 KiB. The sink writes this buffer to the inner writer, so a payload of
any size goes through in pieces of a fixed size.
poll_flush ends the current DEFLATE block with a sync flush, so a flush
changes the compressed bytes. poll_close ends the stream, flushes the
inner writer, and leaves it open. A caller can then still write to the
inner writer, for example to patch a header in front of the stream.
reset starts a new stream in the same compressor
and output buffer, so one sink can encode many objects in turn.
Implementations§
Source§impl<W> DeflateSink<W>
impl<W> DeflateSink<W>
Sourcepub fn new(inner: W, level: u8) -> DeflateSink<W>
pub fn new(inner: W, level: u8) -> DeflateSink<W>
Creates a raw-DEFLATE encoder that writes to inner at level.
An archive-mode repository uses a level from 1 through 9. The sink
passes level to the encoder with no check, and no level causes a
panic.
Sourcepub fn reset(&mut self, inner: W, level: u8) -> W
pub fn reset(&mut self, inner: W, level: u8) -> W
Starts a new stream into inner at level and returns the previous
writer.
The sink resets the compressor in place with level and keeps the
output buffer. A caller that compresses many objects can keep one sink
with no new allocation.
The sink discards the compressed bytes that it holds and did not write to the previous writer. A caller that needs the whole previous stream closes the sink before the reset.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Returns the inner writer.
The sink discards the compressed bytes that it holds and did not write.
Trait Implementations§
Source§impl<W: AsyncWrite + Unpin> AsyncWrite for DeflateSink<W>
impl<W: AsyncWrite + Unpin> AsyncWrite for DeflateSink<W>
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf into the object. Read more