pub struct Writer<W, D> {
operation: D,
writer: W,
offset: usize,
buffer: Vec<u8>,
finished: bool,
finished_frame: bool,
}Expand description
Fields§
§operation: DEither an encoder or a decoder.
writer: WWhere we send the output of the operation.
offset: usizeOffset into the buffer
Only things after this matter. Things before have already been sent to the writer.
buffer: Vec<u8>Output buffer
Where the operation writes, before it gets flushed to the writer
finished: bool§finished_frame: boolWhen true, the operation just finished a frame.
Only happens when decompressing. The context needs to be re-initialized to process the next frame.
Implementations§
Source§impl<W, D> Writer<W, D>
impl<W, D> Writer<W, D>
Sourcepub fn new(writer: W, operation: D) -> Self
pub fn new(writer: W, operation: D) -> Self
Creates a new Writer with a fixed buffer capacity of 32KB
All output from the given operation will be forwarded to writer.
Sourcepub fn new_with_capacity(writer: W, operation: D, capacity: usize) -> Self
pub fn new_with_capacity(writer: W, operation: D, capacity: usize) -> Self
Creates a new Writer with user defined capacity.
All output from the given operation will be forwarded to writer.
Sourcepub fn with_output_buffer(
output_buffer: Vec<u8>,
writer: W,
operation: D,
) -> Self
pub fn with_output_buffer( output_buffer: Vec<u8>, writer: W, operation: D, ) -> Self
Creates a new Writer using the given output buffer.
The output buffer must have pre-allocated capacity (its capacity will not be changed after).
Usually you would use Vec::with_capacity(desired_buffer_size).
Sourcepub fn finish(&mut self) -> Result<()>
pub fn finish(&mut self) -> Result<()>
Ends the stream.
This must be called after all data has been written to finish the stream.
If you forget to call this and just drop the Writer, you will have
an incomplete output.
Keep calling it until it returns Ok(()), then don’t call it again.
Sourcefn with_buffer<F, T>(&mut self, f: F) -> T
fn with_buffer<F, T>(&mut self, f: F) -> T
Run the given closure on self.buffer.
The buffer will be cleared, and made available wrapped in an OutBuffer.
Sourcefn write_from_offset(&mut self) -> Result<()>
fn write_from_offset(&mut self) -> Result<()>
Attempt to write self.buffer to the wrapped writer.
Returns Ok(()) once all the buffer has been written.
Sourcepub fn into_inner(self) -> (W, D)
pub fn into_inner(self) -> (W, D)
Return the wrapped Writer and Operation.
Careful: if you call this before calling Writer::finish(), the
output may be incomplete.
Sourcepub fn writer_mut(&mut self) -> &mut W
pub fn writer_mut(&mut self) -> &mut W
Gives a mutable reference to the inner writer.
Sourcepub fn operation_mut(&mut self) -> &mut D
pub fn operation_mut(&mut self) -> &mut D
Gives a mutable reference to the inner operation.
Trait Implementations§
Source§impl<W, D> Write for Writer<W, D>
impl<W, D> Write for Writer<W, D>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
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)