Struct noodles_cram::AsyncReader
source · [−]pub struct AsyncReader<R> { /* private fields */ }
Expand description
An async CRAM reader.
Implementations
sourceimpl<R> Reader<R> where
R: AsyncRead + Unpin,
impl<R> Reader<R> where
R: AsyncRead + Unpin,
sourcepub fn new(inner: R) -> Self
pub fn new(inner: R) -> Self
Creates an async CRAM reader.
Examples
use noodles_cram as cram;
let data = [];
let reader = cram::AsyncReader::new(&data[..]);
sourcepub async fn read_file_definition(&mut self) -> Result<FileDefinition>
pub async fn read_file_definition(&mut self) -> Result<FileDefinition>
Reads the CRAM file definition.
This also checks the magic number.
The position of the stream is expected to be at the start.
Examples
use noodles_cram as cram;
use tokio::fs::File;
let mut reader = File::open("sample.cram").await.map(cram::AsyncReader::new)?;
let file_definition = reader.read_file_definition().await?;
sourcepub async fn read_file_header(&mut self) -> Result<String>
pub async fn read_file_header(&mut self) -> Result<String>
Reads the raw SAM header.
The position of the stream is expected to be at the CRAM header container, i.e., directly after the file definition.
This returns the raw SAM header as a String
. It can subsequently be parsed as a
noodles_sam::Header
.
Examples
use noodles_cram as cram;
use tokio::fs::File;
let mut reader = File::open("sample.cram").await.map(cram::AsyncReader::new)?;
reader.read_file_definition().await?;
let header = reader.read_file_header().await?;
sourcepub async fn read_data_container(&mut self) -> Result<Option<DataContainer>>
pub async fn read_data_container(&mut self) -> Result<Option<DataContainer>>
Reads a data container.
This returns None
if the container header is the EOF container header, which signals the
end of the stream.
Examples
use noodles_cram as cram;
use tokio::fs::File;
let mut reader = File::open("sample.cram").await.map(cram::AsyncReader::new)?;
reader.read_file_definition().await?;
reader.read_file_header().await?;
while let Some(container) = reader.read_data_container().await? {
// ...
}
sourceimpl<R> Reader<R> where
R: AsyncRead + AsyncSeek + Unpin,
impl<R> Reader<R> where
R: AsyncRead + AsyncSeek + Unpin,
sourcepub async fn seek(&mut self, pos: SeekFrom) -> Result<u64>
pub async fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Seeks the underlying reader to the given position.
Positions typically come from an associated CRAM index file.
Examples
use std::io::{Cursor, SeekFrom};
use noodles_cram as cram;
let mut reader = cram::AsyncReader::new(Cursor::new(Vec::new()));
reader.seek(SeekFrom::Start(0)).await?;
Auto Trait Implementations
impl<R> RefUnwindSafe for Reader<R> where
R: RefUnwindSafe,
impl<R> Send for Reader<R> where
R: Send,
impl<R> Sync for Reader<R> where
R: Sync,
impl<R> Unpin for Reader<R> where
R: Unpin,
impl<R> UnwindSafe for Reader<R> where
R: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more