Example #1
0
        /// <summary>
        /// Create a zip archive sending output to the <paramref name="outputStream"/> passed.
        /// </summary>
        /// <param name="outputStream">The stream to write archive data to.</param>
        /// <param name="sourceDirectory">The directory to source files from.</param>
        /// <param name="recurse">True to recurse directories, false for no recursion.</param>
        /// <param name="fileFilter">The <see cref="PathFilter">file filter</see> to apply.</param>
        /// <param name="directoryFilter">The <see cref="PathFilter">directory filter</see> to apply.</param>
        /// <remarks>The <paramref name="outputStream"/> is closed after creation.</remarks>
        public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter)
        {
            NameTransform    = new ZipNameTransform(sourceDirectory);
            sourceDirectory_ = sourceDirectory;

            using (outputStream_ = new ZipOutputStream(outputStream)) {
                outputStream_.SetLevel((int)CompressionLevel);

                if (password_ != null)
                {
                    outputStream_.Password = password_;
                }

                outputStream_.UseZip64 = UseZip64;
                var scanner = new FileSystemScanner(fileFilter, directoryFilter);
                scanner.ProcessFile += ProcessFile;
                if (this.CreateEmptyDirectories)
                {
                    scanner.ProcessDirectory += ProcessDirectory;
                }

                if (events_ != null)
                {
                    if (events_.FileFailure != null)
                    {
                        scanner.FileFailure += events_.FileFailure;
                    }

                    if (events_.DirectoryFailure != null)
                    {
                        scanner.DirectoryFailure += events_.DirectoryFailure;
                    }
                }

                scanner.Scan(sourceDirectory, recurse);
            }
        }
Example #2
0
 /// <summary>
 /// Initialise a new instance of the <see cref="ZipEntryFactory"/> class.
 /// </summary>
 /// <remarks>A default <see cref="INameTransform"/>, and the LastWriteTime for files is used.</remarks>
 public ZipEntryFactory()
 {
     nameTransform_ = new ZipNameTransform();
     isUnicodeText_ = ZipStrings.UseUnicode;
 }