gwseq-io 0.2.0

Rust library for processing bigWig, bigBed, BAM and HiC files
Documentation
//! Read a byte range through the real source stack and write it to stdout.
//!
//! `cargo run --example cat -- <path> [offset] [length] [block_size]`
//!
//! Exists to be diffed against `dd`, which is the Phase 0 acceptance check:
//! whatever `LocalSource` + `CachedSource` hand back for a range has to be the
//! bytes that are there, at every block size and across every block boundary.
//! It is also the quickest way to look at a header while debugging a parser.

use std::io::Write;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args: Vec<String> = std::env::args().skip(1).collect();
    let path = args
        .first()
        .ok_or("usage: cat <path> [offset] [len] [block_size]")?;
    let offset: u64 = args.get(1).map_or(Ok(0), |a| a.parse())?;
    let block_size: Option<u64> = args.get(3).map(|a| a.parse()).transpose()?;

    let source = gwseq_io::source::open(path, block_size, None)?;
    let len: usize = match args.get(2) {
        Some(a) => a.parse()?,
        None => (source.len()? - offset.min(source.len()?)) as usize,
    };

    let data = source.read_at(offset, len)?;
    std::io::stdout().write_all(&data)?;
    Ok(())
}