Block

Struct Block 

Source
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

Source

pub fn new() -> Self

Creates an empty block.

Source

pub fn reset(&mut self)

Resets a block (clears both compressed and uncompressed data).

Source

pub fn reset_compression(&mut self)

Resets compressed data, if present. This function is needed if you want to update uncompressed contents.

Source

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.

Source

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).

Source

pub fn uncompressed_size(&self) -> u32

Returns the size of the uncompressed data (this works even if the block was not decompressed).

Source

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.

Source

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.

Source

pub fn offset(&self) -> Option<u64>

Returns a block offset, if present.

Source

pub fn state(&self) -> BlockState

Returns the state of the block.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn uncompressed_data(&self) -> &[u8]

Access uncompressed data.

Source

pub fn compressed_data(&self) -> &[u8]

Access compressed data (without header and footer). Panics if the block is not compressed.

Source

pub fn crc32(&self) -> u32

Returns CRC32 hash of the uncompressed data. Panics if the block is not compressed.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Block

Source§

fn clone(&self) -> Block

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnwindSafe for Block

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.