pub struct Block { /* private fields */ }Expand description
A bgzip block, that can contain compressed, uncompressed data, or both.
You can extend uncompressed data using extend_contents, and and then compress the block using compress.
Implementations§
Source§impl Block
impl Block
Sourcepub fn reset_compression(&mut self)
pub fn reset_compression(&mut self)
Resets compressed data, if present. This function is needed if you want to update uncompressed contents.
Sourcepub fn make_empty(&mut self)
pub fn make_empty(&mut self)
Makes a block a compressed block with empty contents. It is different from reset as the block will have valid compressed data and can be written.
Sourcepub fn extend_contents(&mut self, buf: &[u8]) -> usize
pub fn extend_contents(&mut self, buf: &[u8]) -> usize
Extends uncompressed contents and returns the number of consumed bytes. The only case when
the number of consumed bytes is less then the size of the buf is when the content size
reaches maximum size MAX_BLOCK_SIZE.
However, it is not recommended to fill the
contents completely to MAX_BLOCK_SIZE
as the compressed size may become too big
(bigger than MAX_COMPRESSED_SIZE).
This function panics if the block contains compressed data (see reset_compression).
Sourcepub fn uncompressed_size(&self) -> u32
pub fn uncompressed_size(&self) -> u32
Returns the size of the uncompressed data (this works even if the block was not decompressed).
Sourcepub fn compressed_size(&self) -> u32
pub fn compressed_size(&self) -> u32
Returns the size of the compressed data. If the block was not compressed, the function returns zero. Note, that the compressed size does not include header and footer of the bgzip block.
Sourcepub fn block_size(&self) -> Option<u32>
pub fn block_size(&self) -> Option<u32>
Returns the size of the block (sum size of compressed data, header and footer). Returns None if the block was not compressed yet.
Sourcepub fn state(&self) -> BlockState
pub fn state(&self) -> BlockState
Returns the state of the block.
Sourcepub fn compress(&mut self, compression: Compression) -> Result<()>
pub fn compress(&mut self, compression: Compression) -> Result<()>
Compresses block contents. Note that if the contents are empty, the function will compress them into a valid block (see make_empty).
If the compressed size is bigger than
MAX_COMPRESSED_SIZE, the function returns
WriteZero. Function panics if the block is already compressed.
Sourcepub fn dump<W: Write>(&self, stream: &mut W) -> Result<()>
pub fn dump<W: Write>(&self, stream: &mut W) -> Result<()>
Writes the compressed block to stream. The function panics if the block was not compressed.
Sourcepub fn load<R: Read>(
&mut self,
offset: Option<u64>,
stream: &mut R,
) -> Result<(), BlockError>
pub fn load<R: Read>( &mut self, offset: Option<u64>, stream: &mut R, ) -> Result<(), BlockError>
Reads the compressed contents from stream. Panics if the block is non-empty
(consider using reset).
Sourcepub fn decompress(&mut self) -> Result<(), BlockError>
pub fn decompress(&mut self) -> Result<(), BlockError>
Decompresses block contents. This function panics if the block was already decompressed or if the block is empty.
Sourcepub fn uncompressed_data(&self) -> &[u8] ⓘ
pub fn uncompressed_data(&self) -> &[u8] ⓘ
Access uncompressed data.
Sourcepub fn compressed_data(&self) -> &[u8] ⓘ
pub fn compressed_data(&self) -> &[u8] ⓘ
Access compressed data (without header and footer). Panics if the block is not compressed.
Sourcepub fn crc32(&self) -> u32
pub fn crc32(&self) -> u32
Returns CRC32 hash of the uncompressed data. Panics if the block is not compressed.
Sourcepub fn split_contents(
&mut self,
first_size: usize,
second_part: &mut [u8],
) -> usize
pub fn split_contents( &mut self, first_size: usize, second_part: &mut [u8], ) -> usize
Truncates uncompressed contents on first_size,
writes the remaining data into second_part, and
returns the number of bytes written into second_part.
Panics, if the second_part is not big enough.
Sourcepub fn split_into_two(&mut self) -> Block
pub fn split_into_two(&mut self) -> Block
The function trims the contents of self, and returns the second half in a new Block.
The function panics if the initial block was compressed
or its uncompressed size is less than 2 bytes.