Skip to main content

DeflateReader

Struct DeflateReader 

Source
pub struct DeflateReader<R> { /* private fields */ }
Expand description

A raw-DEFLATE encoder that reads uncompressed bytes from a source.

A read returns the compressed form of the source bytes. End of file comes after the end of the stream.

If the caller of a DeflateSink does not flush, the sink and the reader give the same bytes for one input and level. The reader runs the compressor in the same sequence of steps, each into an empty output buffer. The reader does not flush the stream before its end, because a flush changes the bytes.

The reader holds one compressor, an input buffer of 64 KiB, and an output buffer of 64 KiB. Its memory does not grow with the size of the source. The reader returns the compressed bytes that it holds before it reads the source again. reset starts a new stream in the same compressor and buffers, so one reader can encode many objects in turn.

The reader implements AsyncBufRead. A caller that reads through poll_fill_buf and consume takes the compressed bytes from the output buffer with no copy.

Implementations§

Source§

impl<R> DeflateReader<R>

Source

pub fn new(source: R, level: u8) -> DeflateReader<R>

Creates a raw-DEFLATE encoder that reads from source at level.

level has the meaning that DeflateSink::new states.

Source

pub fn reset(&mut self, source: R, level: u8) -> R

Starts a new stream over source at level and returns the previous source.

The reader resets the compressor in place with level and keeps the buffers. The reader discards the source bytes and the compressed bytes of the previous stream that it holds.

Source

pub fn get_ref(&self) -> &R

Returns a shared reference to the source.

Source

pub fn get_mut(&mut self) -> &mut R

Returns a mutable reference to the source.

Bytes that a caller reads from the source through this reference do not reach the stream.

Source

pub fn into_inner(self) -> R

Returns the source.

The reader discards the source bytes and the compressed bytes that it holds.

Trait Implementations§

Source§

impl<R: AsyncRead + Unpin> AsyncBufRead for DeflateReader<R>

Source§

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

Attempt to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Source§

fn consume(self: Pin<&mut Self>, amt: usize)

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Source§

impl<R: AsyncRead + Unpin> AsyncRead for DeflateReader<R>

Source§

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

Attempt to read from the AsyncRead into buf. Read more
Source§

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

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more

Auto Trait Implementations§

§

impl<R> Forget for DeflateReader<R>

§

impl<R> Freeze for DeflateReader<R>

§

impl<R> Move for DeflateReader<R>

§

impl<R> RefUnwindSafe for DeflateReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for DeflateReader<R>
where R: Send, BoxRaw<CompressorOxide>: Send, BoxRaw<[u8]>: Send,

§

impl<R> Sync for DeflateReader<R>
where R: Sync, BoxRaw<CompressorOxide>: Sync, BoxRaw<[u8]>: Sync,

§

impl<R> Unpin for DeflateReader<R>

§

impl<R> UnsafeUnpin for DeflateReader<R>

§

impl<R> UnwindSafe for DeflateReader<R>
where R: UnwindSafe, BoxRaw<CompressorOxide>: UnwindSafe, BoxRaw<[u8]>: 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.