@@ -7,7 +7,9 @@ use std::str::FromStr;
77use bzip2:: read:: BzDecoder ;
88use 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 ;
1113use zip:: ZipArchive ;
1214
1315use crate :: { Error , Metadata } ;
@@ -59,13 +61,13 @@ impl FromStr for SDistType {
5961 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
6062 let dist_type = match s {
6163 "zip" => SDistType :: Zip ,
62- "gz" => SDistType :: GzTar ,
64+ "gz" | "tgz" => SDistType :: GzTar ,
6365 #[ cfg( feature = "deprecated-formats" ) ]
6466 "tar" => SDistType :: Tar ,
6567 #[ cfg( feature = "bzip2" ) ]
66- "bz2" => SDistType :: BzTar ,
68+ "bz2" | "tbz" => SDistType :: BzTar ,
6769 #[ cfg( feature = "xz" ) ]
68- "xz" => SDistType :: XzTar ,
70+ "lz" | "lzma" | "tlz" | "txz" | " xz" => SDistType :: XzTar ,
6971 _ => return Err ( Error :: UnknownDistributionType ) ,
7072 } ;
7173 Ok ( dist_type)
@@ -76,25 +78,20 @@ impl Distribution {
7678 /// Open and parse a distribution from `path`
7779 pub fn new ( path : impl AsRef < Path > ) -> Result < Self , Error > {
7880 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" => {
9895 let parts: Vec < & str > = path
9996 . file_stem ( )
10097 . unwrap ( )
@@ -106,9 +103,13 @@ impl Distribution {
106103 [ _name, _version, py_ver] => py_ver,
107104 _ => "any" ,
108105 } ;
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+ }
110111 }
111- DistributionType :: Wheel => {
112+ "whl" => {
112113 let parts: Vec < & str > = path
113114 . file_stem ( )
114115 . unwrap ( )
@@ -120,16 +121,15 @@ impl Distribution {
120121 [ _name, _version, py_ver, _abi_tag, _plat_tag] => py_ver,
121122 _ => "any" ,
122123 } ;
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+ }
124129 }
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+ } )
133133 }
134134
135135 /// Returns distribution type
@@ -162,9 +162,10 @@ impl Distribution {
162162 Self :: parse_tar ( BzDecoder :: new ( BufReader :: new ( fs_err:: File :: open ( path) ?) ) )
163163 }
164164 #[ 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+ ) ) ,
168169 }
169170 }
170171
0 commit comments