@@ -8,7 +8,7 @@ use crate::{Error, Metadata};
88#[ derive( Debug , Clone , Copy , PartialEq ) ]
99pub enum DistributionType {
1010 SDist ,
11- BDist ,
11+ Egg ,
1212 Wheel ,
1313}
1414
@@ -31,7 +31,7 @@ impl Distribution {
3131 if let Some ( ext) = path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) {
3232 let dist_type = match ext {
3333 "zip" | "gz" => DistributionType :: SDist ,
34- "egg" => DistributionType :: BDist ,
34+ "egg" => DistributionType :: Egg ,
3535 "whl" => DistributionType :: Wheel ,
3636 _ => return Err ( Error :: UnknownDistributionType ) ,
3737 } ;
@@ -44,7 +44,7 @@ impl Distribution {
4444 } ;
4545 Self :: parse_sdist ( path, sdist_type)
4646 }
47- DistributionType :: BDist => Self :: parse_bdist ( path) ,
47+ DistributionType :: Egg => Self :: parse_egg ( path) ,
4848 DistributionType :: Wheel => Self :: parse_wheel ( path) ,
4949 } ?;
5050 return Ok ( Self {
@@ -69,16 +69,20 @@ impl Distribution {
6969 todo ! ( )
7070 }
7171
72- fn parse_bdist ( path : & Path ) -> Result < Metadata , Error > {
73- todo ! ( )
72+ fn parse_egg ( path : & Path ) -> Result < Metadata , Error > {
73+ Self :: parse_zip ( path , "EGG-INFO/PKG-INFO" )
7474 }
7575
7676 fn parse_wheel ( path : & Path ) -> Result < Metadata , Error > {
77+ Self :: parse_zip ( path, ".dist-info/METADATA" )
78+ }
79+
80+ fn parse_zip ( path : & Path , metadata_file_suffix : & str ) -> Result < Metadata , Error > {
7781 let reader = BufReader :: new ( fs_err:: File :: open ( path) ?) ;
7882 let mut archive = ZipArchive :: new ( reader) ?;
7983 let metadata_files: Vec < _ > = archive
8084 . file_names ( )
81- . filter ( |name| name. ends_with ( ".dist-info/METADATA" ) )
85+ . filter ( |name| name. ends_with ( metadata_file_suffix ) )
8286 . map ( ToString :: to_string)
8387 . collect ( ) ;
8488 match metadata_files. as_slice ( ) {
0 commit comments