noodles_bam/io/writer/builder.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
use std::{
fs::File,
io::{self, Write},
path::Path,
};
use noodles_bgzf as bgzf;
use super::Writer;
/// A BAM writer builder.
#[derive(Debug, Default)]
pub struct Builder;
impl Builder {
/// Builds a BAM writer from a path.
///
/// # Examples
///
/// ```no_run
/// use noodles_bam as bam;
/// let writer = bam::io::writer::Builder::default().build_from_path("out.bam")?;
/// # Ok::<_, std::io::Error>(())
/// ```
pub fn build_from_path<P>(self, dst: P) -> io::Result<Writer<bgzf::Writer<File>>>
where
P: AsRef<Path>,
{
File::create(dst).map(Writer::new)
}
/// Builds a BAM writer from a writer.
///
/// # Examples
///
/// ```
/// # use std::io;
/// use noodles_bam as bam;
/// let writer = bam::io::writer::Builder::default().build_from_writer(io::sink());
/// ```
pub fn build_from_writer<W>(self, writer: W) -> Writer<bgzf::Writer<W>>
where
W: Write,
{
Writer::new(writer)
}
}