Skip to content

Commit d3b09d7

Browse files
committed
add tar.lz
1 parent 24d414c commit d3b09d7

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/distribution.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::str::FromStr;
77
use bzip2::read::BzDecoder;
88
use flate2::read::GzDecoder;
99
#[cfg(feature = "xz")]
10-
use xz::read::XzDecoder;
10+
use xz::bufread::XzDecoder;
11+
#[cfg(feature = "xz")]
12+
use xz::stream::Stream as XzStream;
1113
use zip::ZipArchive;
1214

1315
use crate::{Error, Metadata};
@@ -32,6 +34,8 @@ enum SDistType {
3234
#[cfg(feature = "bzip2")]
3335
BzTar,
3436
#[cfg(feature = "xz")]
37+
LzTar,
38+
#[cfg(feature = "xz")]
3539
XzTar,
3640
}
3741

@@ -65,6 +69,8 @@ impl FromStr for SDistType {
6569
#[cfg(feature = "bzip2")]
6670
"bz2" | "tbz" => SDistType::BzTar,
6771
#[cfg(feature = "xz")]
72+
"lz" | "lzma" | "tlz" => SDistType::LzTar,
73+
#[cfg(feature = "xz")]
6874
"txz" | "xz" => SDistType::XzTar,
6975
_ => return Err(Error::UnknownDistributionType),
7076
};
@@ -160,6 +166,11 @@ impl Distribution {
160166
Self::parse_tar(BzDecoder::new(BufReader::new(fs_err::File::open(path)?)))
161167
}
162168
#[cfg(feature = "xz")]
169+
SDistType::LzTar => Self::parse_tar(XzDecoder::new_stream(
170+
BufReader::new(fs_err::File::open(path)?),
171+
XzStream::new_lzma_decoder(u64::max_value()).unwrap(),
172+
)),
173+
#[cfg(feature = "xz")]
163174
SDistType::XzTar => {
164175
Self::parse_tar(XzDecoder::new(BufReader::new(fs_err::File::open(path)?)))
165176
}

tests/fixtures/build-0.4.0.tar.lz

11.6 KB
Binary file not shown.

tests/test_distribution.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ fn test_parse_sdist_tar_bz2() {
8484
assert_eq!(dist.python_version(), "source");
8585
}
8686

87+
#[cfg(feature = "xz")]
88+
#[test]
89+
fn test_parse_sdist_tar_lz() {
90+
let dist = Distribution::new("tests/fixtures/build-0.4.0.tar.lz").unwrap();
91+
assert_eq!(dist.r#type(), DistributionType::SDist);
92+
let metadata = dist.metadata();
93+
assert_eq!(metadata.metadata_version, "2.1");
94+
assert_eq!(metadata.name, "build");
95+
assert!(metadata.home_page.is_none());
96+
assert!(metadata.download_url.is_none());
97+
}
98+
8799
#[cfg(feature = "xz")]
88100
#[test]
89101
fn test_parse_sdist_tar_xz() {

0 commit comments

Comments
 (0)