Skip to main content

DeflateSink

Struct DeflateSink 

Source
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>

Source

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.

Source

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.

Source

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>

Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to close the object. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more

Auto Trait Implementations§

§

impl<W> Freeze for DeflateSink<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for DeflateSink<W>
where W: RefUnwindSafe,

§

impl<W> Send for DeflateSink<W>
where W: Send,

§

impl<W> Sync for DeflateSink<W>
where W: Sync,

§

impl<W> Unpin for DeflateSink<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for DeflateSink<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for DeflateSink<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.