Skip to content

Commit a710ae4

Browse files
committed
Add config option to switch to unstable liblzma fork
1 parent ca2245c commit a710ae4

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ libzstd = { package = "zstd", version = "0.13.1", optional = true, default-featu
4141
memchr = "2"
4242
pin-project-lite = "0.2"
4343
tokio = { version = "1.24.2", optional = true, default-features = false }
44-
xz2 = { version = "0.1.6", optional = true }
4544
zstd-safe = { version = "7", optional = true, default-features = false }
4645
deflate64 = { version = "0.1.5", optional = true }
4746

47+
[target.'cfg(not(async_compression_unstable_liblzma_fork))'.dependencies]
48+
xz2 = { version = "0.1.6", optional = true }
49+
[target.'cfg(async_compression_unstable_liblzma_fork)'.dependencies]
50+
xz2 = { package = "liblzma", version = "0.3.2", optional = true }
51+
4852
[dev-dependencies]
4953
bytes = "1"
5054
futures = "0.3.5"
@@ -103,3 +107,6 @@ required-features = ["zlib", "tokio"]
103107
[[example]]
104108
name = "zstd_gzip"
105109
required-features = ["zstd", "gzip", "tokio"]
110+
111+
[lints.rust]
112+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(async_compression_unstable_liblzma_fork)'] }

src/codec/xz2/decoder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use std::{fmt, io};
22

3+
#[cfg(async_compression_unstable_liblzma_fork)]
4+
use liblzma::stream::{Action, Status, Stream};
5+
#[cfg(not(async_compression_unstable_liblzma_fork))]
36
use xz2::stream::{Action, Status, Stream};
47

58
use crate::{codec::Decode, util::PartialBuffer};

src/codec/xz2/encoder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use std::{fmt, io};
22

3+
#[cfg(async_compression_unstable_liblzma_fork)]
4+
use liblzma::stream::{Action, Check, LzmaOptions, Status, Stream};
5+
#[cfg(not(async_compression_unstable_liblzma_fork))]
36
use xz2::stream::{Action, Check, LzmaOptions, Status, Stream};
47

58
use crate::{

tests/utils/algos.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,22 @@ algos! {
169169
pub use crate::utils::impls::sync::to_vec;
170170

171171
pub fn compress(bytes: &[u8]) -> Vec<u8> {
172+
#[cfg(not(async_compression_unstable_liblzma_fork))]
172173
use xz2::bufread::XzEncoder;
173174

175+
#[cfg(async_compression_unstable_liblzma_fork)]
176+
use liblzma::bufread::XzEncoder;
177+
174178
to_vec(XzEncoder::new(bytes, 0))
175179
}
176180

177181
pub fn decompress(bytes: &[u8]) -> Vec<u8> {
182+
#[cfg(not(async_compression_unstable_liblzma_fork))]
178183
use xz2::bufread::XzDecoder;
179184

185+
#[cfg(async_compression_unstable_liblzma_fork)]
186+
use liblzma::bufread::XzDecoder;
187+
180188
to_vec(XzDecoder::new(bytes))
181189
}
182190
}
@@ -187,8 +195,17 @@ algos! {
187195
pub use crate::utils::impls::sync::to_vec;
188196

189197
pub fn compress(bytes: &[u8]) -> Vec<u8> {
190-
use xz2::bufread::XzEncoder;
191-
use xz2::stream::{LzmaOptions, Stream};
198+
#[cfg(not(async_compression_unstable_liblzma_fork))]
199+
use xz2::{
200+
bufread::XzEncoder,
201+
stream::{LzmaOptions, Stream},
202+
};
203+
204+
#[cfg(async_compression_unstable_liblzma_fork)]
205+
use liblzma::{
206+
bufread::XzEncoder,
207+
stream::{LzmaOptions, Stream},
208+
};
192209

193210
to_vec(XzEncoder::new_stream(
194211
bytes,
@@ -197,8 +214,17 @@ algos! {
197214
}
198215

199216
pub fn decompress(bytes: &[u8]) -> Vec<u8> {
200-
use xz2::bufread::XzDecoder;
201-
use xz2::stream::Stream;
217+
#[cfg(not(async_compression_unstable_liblzma_fork))]
218+
use xz2::{
219+
bufread::XzDecoder,
220+
stream::Stream,
221+
};
222+
223+
#[cfg(async_compression_unstable_liblzma_fork)]
224+
use liblzma::{
225+
bufread::XzDecoder,
226+
stream::Stream,
227+
};
202228

203229
to_vec(XzDecoder::new_stream(
204230
bytes,

0 commit comments

Comments
 (0)