File tree 2 files changed +42
-1
lines changed
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,39 @@ mod tests {
292
292
// Note this useful idiom: importing names from outer (for mod tests) scope.
293
293
use super :: * ;
294
294
295
+ #[ test]
296
+ fn test_zip_type_api ( ) {
297
+ let zip = open_zip_via_read ( & PathBuf :: from (
298
+ "data/@babel-plugin-syntax-dynamic-import-npm-7.8.3-fb9ff5634a-8.zip" ,
299
+ ) )
300
+ . unwrap ( ) ;
301
+
302
+ assert_eq ! ( zip. file_type( "node_modules" ) . unwrap( ) , FileType :: Directory ) ;
303
+ assert_eq ! ( zip. file_type( "node_modules/" ) . unwrap( ) , FileType :: Directory ) ;
304
+ }
305
+
306
+ #[ test]
307
+ #[ should_panic( expected = "Kind(NotFound)" ) ]
308
+ fn test_zip_type_api_not_exist_dir_with_slash ( ) {
309
+ let zip = open_zip_via_read ( & PathBuf :: from (
310
+ "data/@babel-plugin-syntax-dynamic-import-npm-7.8.3-fb9ff5634a-8.zip" ,
311
+ ) )
312
+ . unwrap ( ) ;
313
+
314
+ zip. file_type ( "not_exists/" ) . unwrap ( ) ;
315
+ }
316
+
317
+ #[ test]
318
+ #[ should_panic( expected = "Kind(NotFound)" ) ]
319
+ fn test_zip_type_api_not_exist_dir_without_slash ( ) {
320
+ let zip = open_zip_via_read ( & PathBuf :: from (
321
+ "data/@babel-plugin-syntax-dynamic-import-npm-7.8.3-fb9ff5634a-8.zip" ,
322
+ ) )
323
+ . unwrap ( ) ;
324
+
325
+ zip. file_type ( "not_exists" ) . unwrap ( ) ;
326
+ }
327
+
295
328
#[ test]
296
329
fn test_zip_list ( ) {
297
330
let zip = open_zip_via_read ( & PathBuf :: from ( "data/@babel-plugin-syntax-dynamic-import-npm-7.8.3-fb9ff5634a-8.zip" ) )
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ where T : AsRef<[u8]> {
55
55
}
56
56
57
57
pub fn file_type ( & self , p : & str ) -> Result < FileType , std:: io:: Error > {
58
- if self . dirs . contains ( p) {
58
+ if self . is_dir ( p) {
59
59
Ok ( FileType :: Directory )
60
60
} else if self . files . contains_key ( p) {
61
61
Ok ( FileType :: File )
@@ -64,6 +64,14 @@ where T : AsRef<[u8]> {
64
64
}
65
65
}
66
66
67
+ fn is_dir ( & self , p : & str ) -> bool {
68
+ if p. ends_with ( '/' ) {
69
+ self . dirs . contains ( p)
70
+ } else {
71
+ self . dirs . contains ( & format ! ( "{}/" , p) )
72
+ }
73
+ }
74
+
67
75
pub fn read ( & self , p : & str ) -> Result < Vec < u8 > , std:: io:: Error > {
68
76
let entry = self . files . get ( p)
69
77
. ok_or ( std:: io:: Error :: from ( std:: io:: ErrorKind :: NotFound ) ) ?;
You can’t perform that action at this time.
0 commit comments