Struct BgzfReader

Source
pub struct BgzfReader {
    pub input_length: u64,
    pub current_read_position: Cell<u64>,
    pub pos: Cell<u64>,
    /* private fields */
}
Expand description

Struct to read bgzf file

Fields description:

input_length: total length of the uncompressed version, current_read_position: current position of the compressed file, pos: current position of the uncompressed file,

Fields§

§input_length: u64§current_read_position: Cell<u64>§pos: Cell<u64>

Implementations§

Source§

impl BgzfReader

Below are the steps to use the bgzf Reader, 1st step is to create a BGZF instance with a new function after that read, and seek method can be used respectively.

§Example

use bgzf_rust_reader::BgzfReader;
use std::str;

 let reader = BgzfReader::new(String::from("bgzf_test.bgz")).unwrap();
 let mut vec = vec![0; 52];
 let data_read = reader.read_to(&mut vec);
 assert_eq!(data_read.unwrap(), 52);
 assert_eq!(
   "This is just a bgzf test,lets see how it reacts. :).",
   str::from_utf8(&vec).unwrap()
 );
Source

pub fn new(file_path: String) -> Result<BgzfReader, Box<dyn Error>>

Source

pub fn seek(&self, pos: u64)

This method can set the file position relative to uncompressed data

§Example
use bgzf_rust_reader::BgzfReader;

let reader = BgzfReader::new(String::from("bgzf_test.bgz")).unwrap();
reader.seek(33);
assert_eq!(0, reader.current_read_position.get());
assert_eq!(33, reader.pos.get());
Source

pub fn total_uncompressed_length(&self) -> u64

This method calculates total uncompressed length

Source

pub fn read_to(&self, b: &mut Vec<u8>) -> Result<i32, Box<dyn Error>>

this method reads data to the slice passed

§Example
use bgzf_rust_reader::BgzfReader;
use std::str;

 let reader = BgzfReader::new(String::from("bgzf_test.bgz")).unwrap();
 let mut vec = vec![0; 52];
 let data_read = reader.read_to(&mut vec);
 assert_eq!(data_read.unwrap(), 52);
 assert_eq!(
   "This is just a bgzf test,lets see how it reacts. :).",
   str::from_utf8(&vec).unwrap()
 );
Source

pub fn read( &self, b: &mut Vec<u8>, off: usize, len: usize, ) -> Result<i32, Box<dyn Error>>

this method reads data to the slice from offset position, up to the len position

§Example
use bgzf_rust_reader::BgzfReader;
use std::str;

let reader = BgzfReader::new(String::from("bgzf_test.bgz")).unwrap();
let mut content = vec![0; 10];
match reader.read(&mut content, 0, 10) {
 Ok(val) => {
  assert_eq!(10, val);
 }
 Err(e) => {
   assert!(false);
 }
};
let file_content = str::from_utf8(&content).unwrap();
 assert_eq!("This is ju", file_content);

Auto Trait Implementations§

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