@@ -28,6 +28,7 @@ impl<R: Read + Seek> Read for ArchiveReader<R> {
2828}
2929
3030impl < R : Read + Seek > ArchiveReader < R > {
31+ #[ allow( dead_code) ]
3132 fn get_mut ( & mut self ) -> & mut R {
3233 match self {
3334 Self :: Plain ( r) => r,
@@ -192,24 +193,27 @@ impl<'a, R: Read + Seek> Extract<'a, R> {
192193 }
193194
194195 ArchiveFormat :: Zip => {
195- let mut archive = zip:: ZipArchive :: new ( self . reader . get_mut ( ) ) ?;
196- let file_names = archive
197- . file_names ( )
198- . map ( |f| f. to_string ( ) )
199- . collect :: < Vec < String > > ( ) ;
200- for path in file_names {
201- let mut zip_file = archive. by_name ( & path) ?;
202- let is_dir = zip_file. is_dir ( ) ;
203- let mut file_contents = Vec :: new ( ) ;
204- zip_file. read_to_end ( & mut file_contents) ?;
205- let stop = f ( Entry :: Zip ( ZipEntry {
206- path : path. into ( ) ,
207- is_dir,
208- file_contents,
209- } ) )
210- . map_err ( Into :: into) ?;
211- if stop {
212- break ;
196+ #[ cfg( feature = "fs-extract-api" ) ]
197+ {
198+ let mut archive = zip:: ZipArchive :: new ( self . reader . get_mut ( ) ) ?;
199+ let file_names = archive
200+ . file_names ( )
201+ . map ( |f| f. to_string ( ) )
202+ . collect :: < Vec < String > > ( ) ;
203+ for path in file_names {
204+ let mut zip_file = archive. by_name ( & path) ?;
205+ let is_dir = zip_file. is_dir ( ) ;
206+ let mut file_contents = Vec :: new ( ) ;
207+ zip_file. read_to_end ( & mut file_contents) ?;
208+ let stop = f ( Entry :: Zip ( ZipEntry {
209+ path : path. into ( ) ,
210+ is_dir,
211+ file_contents,
212+ } ) )
213+ . map_err ( Into :: into) ?;
214+ if stop {
215+ break ;
216+ }
213217 }
214218 }
215219 }
@@ -229,30 +233,33 @@ impl<'a, R: Read + Seek> Extract<'a, R> {
229233 }
230234
231235 ArchiveFormat :: Zip => {
232- let mut archive = zip:: ZipArchive :: new ( self . reader . get_mut ( ) ) ?;
233- for i in 0 ..archive. len ( ) {
234- let mut file = archive. by_index ( i) ?;
235- // Decode the file name from raw bytes instead of using file.name() directly.
236- // file.name() uses String::from_utf8_lossy() which may return messy characters
237- // such as: 爱交易.app/, that does not work as expected.
238- // Here we require the file name must be a valid UTF-8.
239- let file_name = String :: from_utf8 ( file. name_raw ( ) . to_vec ( ) ) ?;
240- let out_path = into_dir. join ( & file_name) ;
241- if file. is_dir ( ) {
242- fs:: create_dir_all ( & out_path) ?;
243- } else {
244- if let Some ( out_path_parent) = out_path. parent ( ) {
245- fs:: create_dir_all ( & out_path_parent) ?;
236+ #[ cfg( feature = "fs-extract-api" ) ]
237+ {
238+ let mut archive = zip:: ZipArchive :: new ( self . reader . get_mut ( ) ) ?;
239+ for i in 0 ..archive. len ( ) {
240+ let mut file = archive. by_index ( i) ?;
241+ // Decode the file name from raw bytes instead of using file.name() directly.
242+ // file.name() uses String::from_utf8_lossy() which may return messy characters
243+ // such as: 爱交易.app/, that does not work as expected.
244+ // Here we require the file name must be a valid UTF-8.
245+ let file_name = String :: from_utf8 ( file. name_raw ( ) . to_vec ( ) ) ?;
246+ let out_path = into_dir. join ( & file_name) ;
247+ if file. is_dir ( ) {
248+ fs:: create_dir_all ( & out_path) ?;
249+ } else {
250+ if let Some ( out_path_parent) = out_path. parent ( ) {
251+ fs:: create_dir_all ( & out_path_parent) ?;
252+ }
253+ let mut out_file = fs:: File :: create ( & out_path) ?;
254+ io:: copy ( & mut file, & mut out_file) ?;
246255 }
247- let mut out_file = fs:: File :: create ( & out_path) ?;
248- io:: copy ( & mut file, & mut out_file) ?;
249- }
250- // Get and Set permissions
251- #[ cfg( unix) ]
252- {
253- use std:: os:: unix:: fs:: PermissionsExt ;
254- if let Some ( mode) = file. unix_mode ( ) {
255- fs:: set_permissions ( & out_path, fs:: Permissions :: from_mode ( mode) ) ?;
256+ // Get and Set permissions
257+ #[ cfg( unix) ]
258+ {
259+ use std:: os:: unix:: fs:: PermissionsExt ;
260+ if let Some ( mode) = file. unix_mode ( ) {
261+ fs:: set_permissions ( & out_path, fs:: Permissions :: from_mode ( mode) ) ?;
262+ }
256263 }
257264 }
258265 }
0 commit comments