pub struct Decoder<'a, W: Write> {
writer: Writer<W, Decoder<'a>>,
}Expand description
A decoder that decompress and forward data to another writer.
Don’t forget to call finish() after writing your stream content: it
flushes the decompressed data, and is the only way to know whether the
input stopped in the middle of a frame.
You can also use auto_flush() to automatically flush the writer on
drop; note that this does not check for an incomplete frame.
Fields§
§writer: Writer<W, Decoder<'a>>Implementations§
Source§impl<W: Write> Decoder<'static, W>
impl<W: Write> Decoder<'static, W>
Sourcepub fn with_dictionary(writer: W, dictionary: &[u8]) -> Result<Self>
pub fn with_dictionary(writer: W, dictionary: &[u8]) -> Result<Self>
Creates a new decoder, using an existing dictionary.
(Provides better compression ratio for small files, but requires the dictionary to be present during decompression.)
Source§impl<'a, W: Write> Decoder<'a, W>
impl<'a, W: Write> Decoder<'a, W>
Sourcepub fn with_writer(writer: Writer<W, Decoder<'a>>) -> Self
pub fn with_writer(writer: Writer<W, Decoder<'a>>) -> Self
Creates a new decoder around the given prepared zio writer.
§Examples
fn wrap<W: std::io::Write>(writer: W) -> zstd::stream::write::Decoder<'static, W> {
let decoder = zstd::stream::raw::Decoder::new().unwrap();
let writer = zstd::stream::zio::Writer::new(writer, decoder);
zstd::stream::write::Decoder::with_writer(writer)
}Sourcepub fn with_decoder(writer: W, decoder: Decoder<'a>) -> Self
pub fn with_decoder(writer: W, decoder: Decoder<'a>) -> Self
Creates a new decoder around the given Write and raw decoder.
Sourcepub fn with_context(writer: W, context: &'a mut DCtx<'static>) -> Self
pub fn with_context(writer: W, context: &'a mut DCtx<'static>) -> Self
Creates a decoder that uses the provided context to decompress a stream.
Sourcepub fn with_prepared_dictionary<'b>(
writer: W,
dictionary: &'a DecoderDictionary<'b>,
) -> Result<Self>where
'b: 'a,
pub fn with_prepared_dictionary<'b>(
writer: W,
dictionary: &'a DecoderDictionary<'b>,
) -> Result<Self>where
'b: 'a,
Creates a new decoder, using an existing prepared DecoderDictionary.
(Provides better compression ratio for small files, but requires the dictionary to be present during decompression.)
Sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Acquires a mutable reference to the underlying writer.
Note that mutation of the writer may result in surprising results if this decoder is continued to be used.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Returns the inner Write.
Careful: this neither flushes the decompressed data nor checks that
the input ended on a complete frame.
Use finish(self) for that.
Sourcepub fn finish(self) -> Result<W>
pub fn finish(self) -> Result<W>
Finishes the stream.
This flushes all the decompressed data, and returns an UnexpectedEof
error if the data written so far does not end on a complete frame.
This returns the inner writer in case you need it.
Sourcepub fn do_finish(&mut self) -> Result<()>
pub fn do_finish(&mut self) -> Result<()>
Attempts to finish the stream.
Same as finish(self), but does not consume self.
write on this object will fail after do_finish has succeeded.
Sourcepub fn recommended_input_size() -> usize
pub fn recommended_input_size() -> usize
Return a recommendation for the size of data to write at once.
Sourcepub fn auto_flush(self) -> AutoFlushDecoder<'a, W> ⓘ
pub fn auto_flush(self) -> AutoFlushDecoder<'a, W> ⓘ
Returns a wrapper around self that will flush the stream on drop.
Sourcepub fn on_flush<F: FnMut(Result<()>)>(self, f: F) -> AutoFlushDecoder<'a, W, F> ⓘ
pub fn on_flush<F: FnMut(Result<()>)>(self, f: F) -> AutoFlushDecoder<'a, W, F> ⓘ
Returns a decoder that will flush the stream on drop.
Calls the given callback with the result from flush(). This runs during drop so it’s
important that the provided callback doesn’t panic. It is not called if the wrapped
writer panicked.
Sourcepub fn set_parameter(&mut self, parameter: DParameter) -> Result<()>
pub fn set_parameter(&mut self, parameter: DParameter) -> Result<()>
Sets a decompression parameter on the decompression stream.
Sourcepub fn window_log_max(&mut self, log_distance: u32) -> Result<()>
pub fn window_log_max(&mut self, log_distance: u32) -> Result<()>
Sets the maximum back-reference distance.
The actual maximum distance is going to be 2^log_distance.
This will need to at least match the value set when compressing.
Trait Implementations§
Source§impl<W: Write> Write for Decoder<'_, W>
impl<W: Write> Write for Decoder<'_, W>
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)