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 48 49 50 51 52 53 54 55 56 57 58 59
use std::io::Write;
use super::{CompressionLevel, Writer, MAX_BUF_SIZE};
/// A BGZF writer builder.
#[derive(Debug, Default)]
pub struct Builder {
compression_level: CompressionLevel,
}
impl Builder {
/// Sets a compression level.
///
/// By default, the compression level is set to level 6.
///
/// # Examples
///
/// ```
/// use noodles_bgzf::{self as bgzf, writer::CompressionLevel};
///
/// let builder = bgzf::writer::Builder::default()
/// .set_compression_level(CompressionLevel::best());
/// ```
pub fn set_compression_level(mut self, compression_level: CompressionLevel) -> Self {
self.compression_level = compression_level;
self
}
/// Builds a BGZF writer from a writer.
///
/// # Examples
///
/// ```
/// # use std::io;
/// use noodles_bgzf as bgzf;
/// let writer = bgzf::writer::Builder::default().build_from_writer(io::sink());
/// ```
pub fn build_from_writer<W>(self, writer: W) -> Writer<W>
where
W: Write,
{
Writer {
inner: Some(writer),
position: 0,
staging_buf: Vec::with_capacity(MAX_BUF_SIZE),
compression_buf: Vec::new(),
compression_level: self.compression_level.into(),
}
}
/// Builds a BGZF writer from a writer.
#[deprecated(since = "0.33.0", note = "Use `Builder::build_from_writer` instead.")]
pub fn build_with_writer<W>(self, writer: W) -> Writer<W>
where
W: Write,
{
self.build_from_writer(writer)
}
}