Skip to content

Commit

Permalink
Replace xz2 with liblzma
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Jun 8, 2024
1 parent a29c1ef commit 9be2ed1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ rust-version = "1.57"
[features]
default = ["bz2", "lzma", "xz", "gz", "bgz", "zstd"]
bz2 = ["bzip2"]
lzma = ["xz2"]
lzma = ["liblzma"]
gz = ["flate2"]
bgz = ["bgzip"]
xz = ["lzma"]
xz = ["liblzma"]

# bzip2 feature transitivity
bz2_tokio = ["bzip2/tokio"]
bz2_static = ["bzip2/static"]

# lzma feature transitivity
lzma_tokio = ["xz2/tokio"]
lzma_tokio = ["liblzma/tokio"]

# flate2 feature transitivity
gz_zlib = ["flate2/zlib"]
Expand All @@ -33,15 +33,15 @@ gz_cloudflare_zlib = ["flate2/cloudflare_zlib"]
gz_rust_backend = ["flate2/rust_backend"]

# xz feature transitivity
xz_tokio = ["xz2/tokio"]
xz_tokio = ["liblzma/tokio"]


[dependencies]
cfg-if = "1.0"
thiserror = "1.0"
bzip2 = { version = "0.4.3", optional = true }
flate2 = { version = "1.0", optional = true }
xz2 = { version = "0.1", optional = true }
liblzma = { version = "0.3.1", optional = true }
bgzip = { version = "0.2.2", optional = true }
zstd = { version = "0.12.2", optional = true }

Expand Down Expand Up @@ -86,4 +86,4 @@ denylist = [

# xz feature transitivity
"xz_tokio"
]
]
8 changes: 4 additions & 4 deletions benches/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn read_in_ram(c: &mut Criterion) {
b.iter(|| read_all_stream(niffler::get_reader(Box::new(LZMA_FILE)).unwrap().0))
});
g.bench_function("xz2", |b| {
b.iter(|| read_all_stream(Box::new(xz2::read::XzDecoder::new(LZMA_FILE))))
b.iter(|| read_all_stream(Box::new(liblzma::read::XzDecoder::new(LZMA_FILE))))
});
}

Expand All @@ -40,7 +40,7 @@ fn write_in_ram(c: &mut Criterion) {
g.bench_function("xz2", |b| {
b.iter(|| {
write_all_data(
Box::new(xz2::write::XzEncoder::new(&mut out, 1)),
Box::new(liblzma::write::XzEncoder::new(&mut out, 1)),
BASIC_FILE,
)
})
Expand Down Expand Up @@ -85,7 +85,7 @@ fn read_on_disk(c: &mut Criterion) {
b.iter(|| {
compress_file.seek(std::io::SeekFrom::Start(0)).unwrap();

read_all_stream(Box::new(xz2::read::XzDecoder::new(compress_file.as_file())));
read_all_stream(Box::new(liblzma::read::XzDecoder::new(compress_file.as_file())));
})
});
}
Expand Down Expand Up @@ -114,7 +114,7 @@ fn write_on_disk(c: &mut Criterion) {
g.bench_function("xz2", |b| {
b.iter(|| {
let wfile = compress_file.reopen().unwrap();
let mut writer = xz2::write::XzEncoder::new(wfile, 1);
let mut writer = liblzma::write::XzEncoder::new(wfile, 1);

for _ in 0..(8 * 1024) {
writer.write(&[42]).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/basic/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ cfg_if! {
cfg_if! {
if #[cfg(feature = "lzma")] {
pub(crate) fn new_lzma_encoder<'a>(out: Box<dyn io::Write + 'a>, level: Level) -> Result<Box<dyn io::Write + 'a>, Error> {
Ok(Box::new(xz2::write::XzEncoder::new(out, level.into())))
Ok(Box::new(liblzma::write::XzEncoder::new(out, level.into())))
}

pub(crate) fn new_lzma_decoder<'a>(
inp: Box<dyn io::Read + 'a>,
) -> Result<(Box<dyn io::Read + 'a>, Format), Error> {
Ok((
Box::new(xz2::read::XzDecoder::new(inp)),
Box::new(liblzma::read::XzDecoder::new(inp)),
Format::Lzma,
))
}
Expand Down
4 changes: 2 additions & 2 deletions src/send/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ cfg_if! {
cfg_if! {
if #[cfg(feature = "lzma")] {
pub(crate) fn new_lzma_encoder<'a>(out: Box<dyn io::Write + Send + 'a>, level: Level) -> Result<Box<dyn io::Write + Send + 'a>, Error> {
Ok(Box::new(xz2::write::XzEncoder::new(out, level.into())))
Ok(Box::new(liblzma::write::XzEncoder::new(out, level.into())))
}

pub(crate) fn new_lzma_decoder<'a>(
inp: Box<dyn io::Read + Send + 'a>,
) -> Result<(Box<dyn io::Read + Send + 'a>, Format), Error> {
Ok((
Box::new(xz2::read::XzDecoder::new(inp)),
Box::new(liblzma::read::XzDecoder::new(inp)),
Format::Lzma,
))
}
Expand Down

0 comments on commit 9be2ed1

Please sign in to comment.