@@ -7,7 +7,9 @@ use std::str::FromStr;
7
7
use bzip2:: read:: BzDecoder ;
8
8
use flate2:: read:: GzDecoder ;
9
9
#[ cfg( feature = "xz" ) ]
10
- use xz:: read:: XzDecoder ;
10
+ use xz:: bufread:: XzDecoder ;
11
+ #[ cfg( feature = "xz" ) ]
12
+ use xz:: stream:: Stream as XzStream ;
11
13
use zip:: ZipArchive ;
12
14
13
15
use crate :: { Error , Metadata } ;
@@ -59,13 +61,13 @@ impl FromStr for SDistType {
59
61
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
60
62
let dist_type = match s {
61
63
"zip" => SDistType :: Zip ,
62
- "gz" => SDistType :: GzTar ,
64
+ "gz" | "tgz" => SDistType :: GzTar ,
63
65
#[ cfg( feature = "deprecated-formats" ) ]
64
66
"tar" => SDistType :: Tar ,
65
67
#[ cfg( feature = "bzip2" ) ]
66
- "bz2" => SDistType :: BzTar ,
68
+ "bz2" | "tbz" => SDistType :: BzTar ,
67
69
#[ cfg( feature = "xz" ) ]
68
- "xz" => SDistType :: XzTar ,
70
+ "lz" | "lzma" | "tlz" | "txz" | " xz" => SDistType :: XzTar ,
69
71
_ => return Err ( Error :: UnknownDistributionType ) ,
70
72
} ;
71
73
Ok ( dist_type)
@@ -76,25 +78,20 @@ impl Distribution {
76
78
/// Open and parse a distribution from `path`
77
79
pub fn new ( path : impl AsRef < Path > ) -> Result < Self , Error > {
78
80
let path = path. as_ref ( ) ;
79
- if let Some ( ext) = path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) {
80
- let dist_type = match ext {
81
- "zip" | "gz" => DistributionType :: SDist ,
82
- "egg" => DistributionType :: Egg ,
83
- "whl" => DistributionType :: Wheel ,
84
- #[ cfg( feature = "deprecated-formats" ) ]
85
- "tar" => DistributionType :: SDist ,
86
- #[ cfg( feature = "bzip2" ) ]
87
- "bz2" => DistributionType :: SDist ,
88
- #[ cfg( feature = "xz" ) ]
89
- "xz" => DistributionType :: SDist ,
90
- _ => return Err ( Error :: UnknownDistributionType ) ,
91
- } ;
92
- let ( metadata, python_version) = match dist_type {
93
- DistributionType :: SDist => {
94
- let sdist_type: SDistType = ext. parse ( ) ?;
95
- ( Self :: parse_sdist ( path, sdist_type) ?, "source" . to_string ( ) )
96
- }
97
- DistributionType :: Egg => {
81
+ let ext = path
82
+ . extension ( )
83
+ . and_then ( |ext| ext. to_str ( ) )
84
+ . ok_or ( Error :: UnknownDistributionType ) ?;
85
+
86
+ Ok ( if let Ok ( sdist_type) = ext. parse ( ) {
87
+ Self {
88
+ dist_type : DistributionType :: SDist ,
89
+ metadata : Self :: parse_sdist ( path, sdist_type) ?,
90
+ python_version : "source" . to_string ( ) ,
91
+ }
92
+ } else {
93
+ match ext {
94
+ "egg" => {
98
95
let parts: Vec < & str > = path
99
96
. file_stem ( )
100
97
. unwrap ( )
@@ -106,9 +103,13 @@ impl Distribution {
106
103
[ _name, _version, py_ver] => py_ver,
107
104
_ => "any" ,
108
105
} ;
109
- ( Self :: parse_egg ( path) ?, python_version. to_string ( ) )
106
+ Self {
107
+ dist_type : DistributionType :: Egg ,
108
+ metadata : Self :: parse_egg ( path) ?,
109
+ python_version : python_version. to_string ( ) ,
110
+ }
110
111
}
111
- DistributionType :: Wheel => {
112
+ "whl" => {
112
113
let parts: Vec < & str > = path
113
114
. file_stem ( )
114
115
. unwrap ( )
@@ -120,16 +121,15 @@ impl Distribution {
120
121
[ _name, _version, py_ver, _abi_tag, _plat_tag] => py_ver,
121
122
_ => "any" ,
122
123
} ;
123
- ( Self :: parse_wheel ( path) ?, python_version. to_string ( ) )
124
+ Self {
125
+ dist_type : DistributionType :: Wheel ,
126
+ metadata : Self :: parse_wheel ( path) ?,
127
+ python_version : python_version. to_string ( ) ,
128
+ }
124
129
}
125
- } ;
126
- return Ok ( Self {
127
- dist_type,
128
- metadata,
129
- python_version,
130
- } ) ;
131
- }
132
- Err ( Error :: UnknownDistributionType )
130
+ _ => return Err ( Error :: UnknownDistributionType ) ,
131
+ }
132
+ } )
133
133
}
134
134
135
135
/// Returns distribution type
@@ -162,9 +162,10 @@ impl Distribution {
162
162
Self :: parse_tar ( BzDecoder :: new ( BufReader :: new ( fs_err:: File :: open ( path) ?) ) )
163
163
}
164
164
#[ cfg( feature = "xz" ) ]
165
- SDistType :: XzTar => {
166
- Self :: parse_tar ( XzDecoder :: new ( BufReader :: new ( fs_err:: File :: open ( path) ?) ) )
167
- }
165
+ SDistType :: XzTar => Self :: parse_tar ( XzDecoder :: new_stream (
166
+ BufReader :: new ( fs_err:: File :: open ( path) ?) ,
167
+ XzStream :: new_auto_decoder ( u64:: max_value ( ) , 0 ) . unwrap ( ) ,
168
+ ) ) ,
168
169
}
169
170
}
170
171
0 commit comments