use crate::Error;
use std::fs::File;
use std::path::Path;
impl crate::Reader {
pub fn open_bzip2<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
Self::open_bzip2_with_limit(
path,
crate::io::reader_common::DEFAULT_MAX_DECOMPRESSED_BYTES,
)
}
pub fn open_bzip2_with_limit<P: AsRef<Path>>(path: P, max_bytes: u64) -> Result<Self, Error> {
Self::_open_bzip2(path, false, max_bytes).map(|(r, _)| r)
}
pub fn open_bzip2_permissive<P: AsRef<Path>>(path: P) -> Result<(Self, Vec<String>), Error> {
Self::_open_bzip2(
path,
true,
crate::io::reader_common::DEFAULT_MAX_DECOMPRESSED_BYTES,
)
}
fn _open_bzip2<P: AsRef<Path>>(
path: P,
permissive: bool,
max_bytes: u64,
) -> Result<(Self, Vec<String>), Error> {
Self::_open_bzip2_file(File::open(path)?, permissive, max_bytes)
}
pub(crate) fn _open_bzip2_file(
file: File,
permissive: bool,
max_bytes: u64,
) -> Result<(Self, Vec<String>), Error> {
let decoder = bzip2::read::BzDecoder::new(file);
let d = crate::io::reader_common::open_compressed(decoder, permissive, max_bytes)?;
Self::_from_decompressed(d)
}
}