pub struct ZstdWriter<'dict, W>where
W: Write,{ /* private fields */ }Expand description
A writer that writes a compressed zstd stream to the underlying writer.
The underlying writer W must implement the following traits:
For async support, see crate::AsyncZstdWriter.
§Construction
Create a builder using ZstdWriter::builder. See ZstdWriterBuilder
for builder options. Call ZstdWriterBuilder::build to build the
ZstdWriter instance.
let mut writer = zstd_framed::ZstdWriter::builder(compressed_file)
.with_compression_level(3) // Set custom compression level
.with_seek_table(1024 * 1024) // Write zstd seekable format table
.build()?;
// ...
writer.shutdown()?; // Optional, will shut down automatically on drop§Writing multiple frames
To allow for efficient seeking (e.g. when using ZstdReaderBuilder::with_seek_table),
you can write multiple zstd frames to the underlying writer. If the
.with_seek_table() option is
given during construction, multiple frames will be created automatically
to fit within the given max_frame_size.
Alternatively, you can use ZstdWriter::finish_frame() to explicitly
split the underlying stream into multiple frames. .finish_frame()
can be used even when not using the .with_seek_table()
option (but note the seek table will only be written when using
.with_seek_table()).
§Clean shutdown
To ensure the writer shuts down cleanly (including flushing any in-memory
buffers and writing the seek table if enabled with .with_seek_table()),
you can explicitly call the ZstdWriter::shutdown method. This
method will also be called automatically on drop, but errors will
be ignored.
Implementations§
Source§impl<W> ZstdWriter<'_, W>where
W: Write,
impl<W> ZstdWriter<'_, W>where
W: Write,
Sourcepub fn builder(writer: W) -> ZstdWriterBuilder<W>
pub fn builder(writer: W) -> ZstdWriterBuilder<W>
Create a new zstd writer that writes a compressed zstd stream to the underlying writer.
Sourcepub fn finish_frame(&mut self) -> Result<()>
pub fn finish_frame(&mut self) -> Result<()>
Explicitly finish the current zstd frame. If more data is written, a new frame will be started.
When using ZstdWriterBuilder::with_seek_table, the just-finished
frame will be reflected in the resulting seek table.
Sourcepub fn shutdown(&mut self) -> Result<()>
pub fn shutdown(&mut self) -> Result<()>
Cleanly shut down the zstd stream. This will flush internal buffers,
finish writing any partially-written frames, and write the
seek table when using ZstdWriterBuilder::with_seek_table.
This method will be called automatically on drop, although any errors will be ignored.
Trait Implementations§
Source§impl<W> Drop for ZstdWriter<'_, W>where
W: Write,
impl<W> Drop for ZstdWriter<'_, W>where
W: Write,
Source§impl<W> Write for ZstdWriter<'_, W>where
W: Write,
impl<W> Write for ZstdWriter<'_, W>where
W: Write,
Source§fn write(&mut self, data: &[u8]) -> Result<usize, Error>
fn write(&mut self, data: &[u8]) -> Result<usize, Error>
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)