Struct png::encoder::ChunkWriter
source · struct ChunkWriter<'a, W: Write> {
writer: ChunkOutput<'a, W>,
buffer: Vec<u8>,
index: usize,
curr_chunk: ChunkType,
}
Expand description
This writer is used between the actual writer and the ZlibEncoder and has the job of packaging the compressed data into a PNG chunk, based on the image metadata
Currently the way it works is that the specified buffer
will hold one chunk at the time and buffer the incoming
data until flush
is called or the maximum chunk size
is reached.
The maximum chunk is the smallest between the selected buffer size
and u32::MAX >> 1
(0x7fffffff
or 2147483647
dec)
When a chunk has to be flushed the length (that is now known) and the CRC will be written at the correct locations in the chunk.
Fields§
§writer: ChunkOutput<'a, W>
§buffer: Vec<u8>
§index: usize
keeps track of where the last byte was written
curr_chunk: ChunkType
Implementations§
source§impl<'a, W: Write> ChunkWriter<'a, W>
impl<'a, W: Write> ChunkWriter<'a, W>
fn new(writer: ChunkOutput<'a, W>, buf_len: usize) -> ChunkWriter<'a, W> ⓘ
sourcefn next_frame_info(&self) -> (usize, usize)
fn next_frame_info(&self) -> (usize, usize)
Returns the size of each scanline for the next frame paired with the size of the whole frame
This is used by the StreamWriter
to know when the scanline ends
so it can filter compress it and also to know when to start
the next one
sourcefn write_header(&mut self) -> Result<(), EncodingError>
fn write_header(&mut self) -> Result<(), EncodingError>
NOTE: this bypasses the internal buffer so the flush method should be called before this in the case there is some data left in the buffer when this is called, it will panic
sourcefn set_fctl(&mut self, f: FrameControl)
fn set_fctl(&mut self, f: FrameControl)
Set the FrameControl
for the following frame
It will ignore the sequence_number
of the parameter
as it is updated internally.
sourcefn flush_inner(&mut self) -> Result<()>
fn flush_inner(&mut self) -> Result<()>
Flushes the current chunk
Trait Implementations§
source§impl<W: Write> Drop for ChunkWriter<'_, W>
impl<W: Write> Drop for ChunkWriter<'_, W>
source§impl<'a, W: Write> Write for ChunkWriter<'a, W>
impl<'a, W: Write> Write for ChunkWriter<'a, W>
source§fn write(&mut self, data: &[u8]) -> Result<usize>
fn write(&mut self, data: &[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
)