Skip to content

Commit

Permalink
Honor individual compression features (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
jguhlin authored Mar 21, 2024
1 parent a00f944 commit 08101cb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::fs::File;
use std::io::{stdin, Cursor, Read};
use std::path::Path;

#[cfg(feature = "compression")]
#[cfg(feature = "bzip2")]
use bzip2::read::BzDecoder;
#[cfg(feature = "compression")]
#[cfg(feature = "flate2")]
use flate2::read::MultiGzDecoder;
#[cfg(feature = "compression")]
#[cfg(feature = "xz2")]
use xz2::read::XzDecoder;

use crate::errors::ParseError;
Expand All @@ -23,11 +23,11 @@ mod fastq;
pub use crate::parser::utils::FastxReader;

// Magic bytes for each compression format
#[cfg(feature = "compression")]
#[cfg(feature = "flate2")]
const GZ_MAGIC: [u8; 2] = [0x1F, 0x8B];
#[cfg(feature = "compression")]
#[cfg(feature = "bzip2")]
const BZ_MAGIC: [u8; 2] = [0x42, 0x5A];
#[cfg(feature = "compression")]
#[cfg(feature = "xz2")]
const XZ_MAGIC: [u8; 2] = [0xFD, 0x37];

fn get_fastx_reader<'a, R: 'a + io::Read + Send>(
Expand Down Expand Up @@ -88,23 +88,23 @@ pub fn parse_fastx_reader<'a, R: 'a + io::Read + Send>(
let new_reader = first_two_cursor.chain(reader);

match first_two_bytes {
#[cfg(feature = "compression")]
#[cfg(feature = "flate2")]
GZ_MAGIC => {
let mut gz_reader = MultiGzDecoder::new(new_reader);
let mut first = [0; 1];
gz_reader.read_exact(&mut first)?;
let r = Cursor::new(first).chain(gz_reader);
get_fastx_reader(r, first[0])
}
#[cfg(feature = "compression")]
#[cfg(feature = "bzip2")]
BZ_MAGIC => {
let mut bz_reader = BzDecoder::new(new_reader);
let mut first = [0; 1];
bz_reader.read_exact(&mut first)?;
let r = Cursor::new(first).chain(bz_reader);
get_fastx_reader(r, first[0])
}
#[cfg(feature = "compression")]
#[cfg(feature = "xz2")]
XZ_MAGIC => {
let mut xz_reader = XzDecoder::new(new_reader);
let mut first = [0; 1];
Expand Down

0 comments on commit 08101cb

Please sign in to comment.