pub struct BitOutputStream<W> { /* private fields */ }Expand description
Big-endian bit writer backed by a byte stream.
Implementations§
Source§impl<W: Write> BitOutputStream<W>
impl<W: Write> BitOutputStream<W>
Sourcepub fn new(output: W) -> Self
pub fn new(output: W) -> Self
Constructs a bit output stream writing big-endian bits to output.
Sourcepub fn write_bit(&mut self, bit: u8) -> Result<(), ArithError>
pub fn write_bit(&mut self, bit: u8) -> Result<(), ArithError>
Writes a single bit (0 or 1) to the stream.
§Errors
Returns ArithError::InvalidBit if bit > 1, or ArithError::Io on write failure.
Sourcepub fn finish_padding(&mut self) -> Result<(), ArithError>
pub fn finish_padding(&mut self) -> Result<(), ArithError>
Zero-pads any partial byte up to the next byte boundary and flushes the underlying writer.
§Errors
Returns ArithError::Io if writing or flushing fails.
Sourcepub fn flush(&mut self) -> Result<(), ArithError>
pub fn flush(&mut self) -> Result<(), ArithError>
Flushes the underlying writer without padding the current partial byte.
§Errors
Returns ArithError::Io if flushing fails.
Sourcepub fn into_inner(self) -> Result<W, ArithError>
pub fn into_inner(self) -> Result<W, ArithError>
Finishes padding, flushes, and returns the underlying writer.
§Errors
Returns ArithError::Io if padding or flushing fails.
Source§impl<W: Write + Seek> BitOutputStream<W>
impl<W: Write + Seek> BitOutputStream<W>
Sourcepub fn state(&mut self) -> Result<BitOutputState, ArithError>
pub fn state(&mut self) -> Result<BitOutputState, ArithError>
Flushes buffered full bytes and captures the exact output stream state for checkpointing.
§Errors
Returns ArithError::Io if flushing or querying stream position fails.
Sourcepub fn restore_state(&mut self, state: BitOutputState) -> Result<(), ArithError>
pub fn restore_state(&mut self, state: BitOutputState) -> Result<(), ArithError>
Restores a previously captured BitOutputState by seeking to state.file_position.
When resuming onto an existing file on disk, prefer Self::restore_file_state
so any bytes written after the checkpoint are truncated.
§Errors
Returns ArithError::InvalidStreamState if num_bits_filled >= 8, or
ArithError::Io on flush/seek errors.
Source§impl BitOutputStream<File>
impl BitOutputStream<File>
Sourcepub fn restore_file_state(
&mut self,
state: BitOutputState,
) -> Result<(), ArithError>
pub fn restore_file_state( &mut self, state: BitOutputState, ) -> Result<(), ArithError>
Restores a BitOutputState on a file, truncating any bytes beyond file_position.
§Errors
Returns ArithError::InvalidStreamState or ArithError::Io.
Source§impl BitOutputStream<BufWriter<File>>
impl BitOutputStream<BufWriter<File>>
Sourcepub fn restore_file_state(
&mut self,
state: BitOutputState,
) -> Result<(), ArithError>
pub fn restore_file_state( &mut self, state: BitOutputState, ) -> Result<(), ArithError>
Restores a BitOutputState on a buffered file, truncating any bytes beyond file_position.
§Errors
Returns ArithError::InvalidStreamState or ArithError::Io.