Skip to main content

FastaStreamHasher

Struct FastaStreamHasher 

Source
pub struct FastaStreamHasher { /* private fields */ }
Expand description

A streaming FASTA hasher that processes data chunk-by-chunk.

This is designed for WASM environments where files are fetched in chunks. Memory usage is constant (~100KB) regardless of file size:

  • Internal state: ~200 bytes (hasher state, counters)
  • Line buffer: ~8KB (handles long lines)
  • Gzip decoder state: ~32KB if compressed
  • Results: grows only with number of sequences (not sequence length)

§Example

use gtars_refget::digest::stream::FastaStreamHasher;

let mut hasher = FastaStreamHasher::new();

// Process first chunk
hasher.update(b">chr1\nACGT").expect("update");

// Process second chunk
hasher.update(b"TGCA\n>chr2\nGGGG\n").expect("update");

// Finalize and get results
let collection = hasher.finish().expect("finish");
assert_eq!(collection.sequences.len(), 2);

Implementations§

Source§

impl FastaStreamHasher

Source

pub fn new() -> Self

Create a new streaming FASTA hasher.

Source

pub fn update(&mut self, chunk: &[u8]) -> Result<()>

Process a chunk of FASTA data.

This method can be called multiple times with successive chunks of data. Handles both plain text and gzip-compressed FASTA with true streaming decompression (constant memory usage).

§Arguments
  • chunk - A slice of bytes from the FASTA file
§Returns

Ok(()) on success, Err on parsing error

Source

pub fn finish(self) -> Result<SequenceCollection>

Finalize processing and return the SequenceCollection.

This must be called after all chunks have been processed via update().

Source

pub fn sequence_count(&self) -> usize

Get the current number of completed sequences.

Source

pub fn in_sequence(&self) -> bool

Check if currently processing a sequence.

Source

pub fn current_sequence_name(&self) -> Option<&str>

Get the name of the sequence currently being processed (if any).

Source

pub fn current_sequence_length(&self) -> usize

Get the current length of the sequence being processed.

Trait Implementations§

Source§

impl Default for FastaStreamHasher

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Same for T

Source§

type Output = T

Should always be Self
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.