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.
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()
);
pub fn new(file_path: String) -> Result<BgzfReader, Box<dyn Error>>
Sourcepub fn seek(&self, pos: u64)
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());
Sourcepub fn total_uncompressed_length(&self) -> u64
pub fn total_uncompressed_length(&self) -> u64
This method calculates total uncompressed length
Sourcepub fn read_to(&self, b: &mut Vec<u8>) -> Result<i32, Box<dyn Error>>
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()
);
Sourcepub fn read(
&self,
b: &mut Vec<u8>,
off: usize,
len: usize,
) -> Result<i32, Box<dyn Error>>
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§
impl !Freeze for BgzfReader
impl !RefUnwindSafe for BgzfReader
impl Send for BgzfReader
impl !Sync for BgzfReader
impl Unpin for BgzfReader
impl UnwindSafe for BgzfReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more