ICSharpCode.SharpZipLib.Zip.FastZip.ExtractZip C# (CSharp) Method

ExtractZip() public method

Extract the contents of a zip file held in a stream.
public ExtractZip ( Stream inputStream, string targetDirectory, Overwrite overwrite, ConfirmOverwriteDelegate confirmDelegate, string fileFilter, string directoryFilter, bool restoreDateTime, bool isStreamOwner ) : void
inputStream Stream The seekable input stream containing the zip to extract from.
targetDirectory string The directory to save extracted information in.
overwrite Overwrite The style of overwriting to apply.
confirmDelegate ConfirmOverwriteDelegate A delegate to invoke when confirming overwriting.
fileFilter string A filter to apply to files.
directoryFilter string A filter to apply to directories.
restoreDateTime bool Flag indicating whether to restore the date and time for extracted files.
isStreamOwner bool Flag indicating whether the inputStream will be closed by this method.
return void
        public void ExtractZip(Stream inputStream, string targetDirectory,
					   Overwrite overwrite, ConfirmOverwriteDelegate confirmDelegate,
					   string fileFilter, string directoryFilter, bool restoreDateTime,
					   bool isStreamOwner)
        {
            if ((overwrite == Overwrite.Prompt) && (confirmDelegate == null)) {
                throw new ArgumentNullException(nameof(confirmDelegate));
            }

            continueRunning_ = true;
            overwrite_ = overwrite;
            confirmDelegate_ = confirmDelegate;
            extractNameTransform_ = new WindowsNameTransform(targetDirectory);

            fileFilter_ = new NameFilter(fileFilter);
            directoryFilter_ = new NameFilter(directoryFilter);
            restoreDateTimeOnExtract_ = restoreDateTime;

            using (zipFile_ = new ZipFile(inputStream)) {

                if (password_ != null) {
                    zipFile_.Password = password_;
                }
                zipFile_.IsStreamOwner = isStreamOwner;
                System.Collections.IEnumerator enumerator = zipFile_.GetEnumerator();
                while (continueRunning_ && enumerator.MoveNext()) {
                    var entry = (ZipEntry)enumerator.Current;
                    if (entry.IsFile) {
                        // TODO Path.GetDirectory can fail here on invalid characters.
                        if (directoryFilter_.IsMatch(Path.GetDirectoryName(entry.Name)) && fileFilter_.IsMatch(entry.Name)) {
                            ExtractEntry(entry);
                        }
                    } else if (entry.IsDirectory) {
                        if (directoryFilter_.IsMatch(entry.Name) && CreateEmptyDirectories) {
                            ExtractEntry(entry);
                        }
                    } else {
                        // Do nothing for volume labels etc...
                    }
                }
            }
        }

Same methods

FastZip::ExtractZip ( string zipFileName, string targetDirectory, Overwrite overwrite, ConfirmOverwriteDelegate confirmDelegate, string fileFilter, string directoryFilter, bool restoreDateTime ) : void
FastZip::ExtractZip ( string zipFileName, string targetDirectory, string fileFilter ) : void

Usage Example

Example #1
1
 /// <summary>
 /// 解压zip文件
 /// </summary>
 /// <param name="_zipFile">需要解压的zip路径+名字</param>
 /// <param name="_outForlder">解压路径</param>
 public void UnZipFile(string _zipFile, string _outForlder)
 {
     if (Directory.Exists(_outForlder))
         Directory.Delete(_outForlder, true);
     Directory.CreateDirectory(_outForlder);
     progress = progressOverall = 0;
     Thread thread = new Thread(delegate ()
     {
         int fileCount = (int)new ZipFile(_zipFile).Count;
         int fileCompleted = 0;
         FastZipEvents events = new FastZipEvents();
         events.Progress = new ProgressHandler((object sender, ProgressEventArgs e) =>
         {
             progress = e.PercentComplete;
             if (progress == 100) { fileCompleted++; progressOverall = 100 * fileCompleted / fileCount; }
         });
         events.ProgressInterval = TimeSpan.FromSeconds(progressUpdateTime);
         events.ProcessFile = new ProcessFileHandler(
             (object sender, ScanEventArgs e) => { });
         FastZip fastZip = new FastZip(events);
         fastZip.ExtractZip(_zipFile, _outForlder, "");
     });
     thread.IsBackground = true;
     thread.Start();
 }
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.FastZip::ExtractZip