Struct noodles_sam::AsyncReader [−][src]
pub struct AsyncReader<R> { /* fields omitted */ }
Expand description
An async SAM reader.
Implementations
Creates an async SAM reader.
Examples
use noodles_sam as sam;
let data = [];
let reader = sam::AsyncReader::new(&data[..]);
Returns the underlying reader.
Examples
use noodles_sam as sam;
let data = [];
let reader = sam::AsyncReader::new(&data[..]);
assert!(reader.into_inner().is_empty());
Reads the raw SAM header.
This reads all header lines prefixed with a @
(at sign).
The position of the stream is expected to be at the start.
This returns the raw SAM header as a String
, and as such, it is no necessarily valid.
The raw header can subsequently be parsed as a crate::Header
.
The SAM header is optional, and if it is missing, an empty string is returned.
Examples
use noodles_sam as sam;
let data = b"@HD\tVN:1.6
*\t4\t*\t0\t255\t*\t*\t0\t0\t*\t*
";
let mut reader = sam::AsyncReader::new(&data[..]);
let header = reader.read_header().await?;
assert_eq!(header, "@HD\tVN:1.6\n");
Reads a raw SAM record.
This reads from the underlying stream until a newline is reached and appends it to the
given buffer, sans the final newline. The buffer does not necessarily represent a valid
record but can subsequently be parsed as a crate::Record
.
The stream is expected to be directly after the header or at the start of another record.
It is more ergonomic to read records using a stream (see Self::records
), but using this
method allows control of the line buffer and whether the raw record should be parsed.
If successful, the number of bytes read is returned. If the number of bytes read is 0, the stream reached EOF.
Examples
use noodles_sam as sam;
let data = b"@HD\tVN:1.6
*\t4\t*\t0\t255\t*\t*\t0\t0\t*\t*
";
let mut reader = sam::AsyncReader::new(&data[..]);
reader.read_header().await?;
let mut buf = String::new();
reader.read_record(&mut buf).await?;
assert_eq!(buf, "*\t4\t*\t0\t255\t*\t*\t0\t0\t*\t*");
Returns an (async) stream over records starting from the current (input) stream position.
The (input) stream is expected to be directly after the header or at the start of another record.
Unlike Self::read_record
, each record is parsed as a Record
.
Examples
use futures::TryStreamExt;
use noodles_sam as sam;
let data = b"@HD\tVN:1.6
*\t4\t*\t0\t255\t*\t*\t0\t0\t*\t*
";
let mut reader = sam::AsyncReader::new(&data[..]);
reader.read_header().await?;
let mut records = reader.records();
while let Some(record) = records.try_next().await? {
// ...
}