@@ -418,44 +418,64 @@ public void ExtractZip(string zipFileName, string targetDirectory, string fileFi
418418 /// <param name="confirmDelegate">A delegate to invoke when confirming overwriting.</param>
419419 /// <param name="fileFilter">A filter to apply to files.</param>
420420 /// <param name="directoryFilter">A filter to apply to directories.</param>
421- /// <param name="restoreDateTime">Flag indicating wether to restore the date and time for extracted files.</param>
421+ /// <param name="restoreDateTime">Flag indicating whether to restore the date and time for extracted files.</param>
422422 public void ExtractZip ( string zipFileName , string targetDirectory ,
423423 Overwrite overwrite , ConfirmOverwriteDelegate confirmDelegate ,
424424 string fileFilter , string directoryFilter , bool restoreDateTime )
425425 {
426- if ( ( overwrite == Overwrite . Prompt ) && ( confirmDelegate == null ) ) {
426+ Stream inputStream = File . Open ( zipFileName , FileMode . Open , FileAccess . Read , FileShare . Read ) ;
427+ ExtractZip ( inputStream , targetDirectory , overwrite , confirmDelegate , fileFilter , directoryFilter , restoreDateTime , true ) ;
428+ }
429+
430+ /// <summary>
431+ /// Extract the contents of a zip file held in a stream.
432+ /// </summary>
433+ /// <param name="inputStream">The seekable input stream containing the zip to extract from.</param>
434+ /// <param name="targetDirectory">The directory to save extracted information in.</param>
435+ /// <param name="overwrite">The style of <see cref="Overwrite">overwriting</see> to apply.</param>
436+ /// <param name="confirmDelegate">A delegate to invoke when confirming overwriting.</param>
437+ /// <param name="fileFilter">A filter to apply to files.</param>
438+ /// <param name="directoryFilter">A filter to apply to directories.</param>
439+ /// <param name="restoreDateTime">Flag indicating whether to restore the date and time for extracted files.</param>
440+ /// <param name="isStreamOwner">Flag indicating whether the inputStream will be closed by this method.</param>
441+ public void ExtractZip ( Stream inputStream , string targetDirectory ,
442+ Overwrite overwrite , ConfirmOverwriteDelegate confirmDelegate ,
443+ string fileFilter , string directoryFilter , bool restoreDateTime ,
444+ bool isStreamOwner )
445+ {
446+ if ( ( overwrite == Overwrite . Prompt ) && ( confirmDelegate == null ) ) {
427447 throw new ArgumentNullException ( "confirmDelegate" ) ;
428448 }
429449
430450 continueRunning_ = true ;
431451 overwrite_ = overwrite ;
432452 confirmDelegate_ = confirmDelegate ;
433453 extractNameTransform_ = new WindowsNameTransform ( targetDirectory ) ;
434-
454+
435455 fileFilter_ = new NameFilter ( fileFilter ) ;
436456 directoryFilter_ = new NameFilter ( directoryFilter ) ;
437457 restoreDateTimeOnExtract_ = restoreDateTime ;
438-
439- using ( zipFile_ = new ZipFile ( zipFileName ) ) {
458+
459+ using ( zipFile_ = new ZipFile ( inputStream ) ) {
440460
441461#if ! NETCF_1_0
442462 if ( password_ != null ) {
443463 zipFile_ . Password = password_ ;
444464 }
445465#endif
446-
466+ zipFile_ . IsStreamOwner = isStreamOwner ;
447467 System . Collections . IEnumerator enumerator = zipFile_ . GetEnumerator ( ) ;
448- while ( continueRunning_ && enumerator . MoveNext ( ) ) {
449- ZipEntry entry = ( ZipEntry ) enumerator . Current ;
450- if ( entry . IsFile )
468+ while ( continueRunning_ && enumerator . MoveNext ( ) ) {
469+ ZipEntry entry = ( ZipEntry ) enumerator . Current ;
470+ if ( entry . IsFile )
451471 {
452- // TODO Path.GetDirectory can fail here on invalid characters.
453- if ( directoryFilter_ . IsMatch ( Path . GetDirectoryName ( entry . Name ) ) && fileFilter_ . IsMatch ( entry . Name ) ) {
472+ // TODO Path.GetDirectory can fail here on invalid characters.
473+ if ( directoryFilter_ . IsMatch ( Path . GetDirectoryName ( entry . Name ) ) && fileFilter_ . IsMatch ( entry . Name ) ) {
454474 ExtractEntry ( entry ) ;
455475 }
456476 }
457- else if ( entry . IsDirectory ) {
458- if ( directoryFilter_ . IsMatch ( entry . Name ) && CreateEmptyDirectories ) {
477+ else if ( entry . IsDirectory ) {
478+ if ( directoryFilter_ . IsMatch ( entry . Name ) && CreateEmptyDirectories ) {
459479 ExtractEntry ( entry ) ;
460480 }
461481 }
0 commit comments