Skip to main content

read_chunks

Function read_chunks 

Source
pub fn read_chunks<P, F>(path: P, chunk_size: usize, callback: F) -> Result<()>
where P: AsRef<Path>, F: FnMut(&[u8]) -> Result<()>,
Expand description

Read a file in chunks, applying a function to each chunk

This is useful for processing large files without loading them entirely into memory.

ยงExamples

use embeddenator_io::read_chunks;

let mut total_size = 0;
read_chunks("large_file.bin", 4096, |chunk| {
    total_size += chunk.len();
    Ok(())
}).unwrap();
println!("Total size: {} bytes", total_size);