Beispiel #1
0
		public static ZipArchiveEntry CreateEntryFromFile (
			this ZipArchive destination, string sourceFileName,
			string entryName, CompressionLevel compressionLevel
			)
		{
			throw new NotImplementedException ();
		}
Beispiel #2
0
        /// <summary>
        /// Save a workbook to a MemoryStream
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if there are no <see cref="Worksheet">sheets</see> in the workbook.</exception>
        /// <returns></returns>
        internal static void Save(Workbook workbook, CompressionLevel compressionLevel, Stream outputStream)
        {
            if (workbook.SheetCount == 0)
            {
                throw new InvalidOperationException("You are trying to save a Workbook that does not contain any Worksheets.");
            }

            CompressionOption option;
            switch (compressionLevel)
            {
                case CompressionLevel.Balanced:
                    option = CompressionOption.Normal;
                    break;
                case CompressionLevel.Maximum:
                    option = CompressionOption.Maximum;
                    break;
                case CompressionLevel.NoCompression:
                default:
                    option = CompressionOption.NotCompressed;
                    break;
            }

            var writer = new XlsxWriterInternal(workbook, option);
            writer.Save(outputStream);
        }
Beispiel #3
0
 public void Compress(string sourceFilename, string targetFilename, FileMode fileMode, OutArchiveFormat archiveFormat,
     CompressionMethod compressionMethod, CompressionLevel compressionLevel, ZipEncryptionMethod zipEncryptionMethod,
     string password, int bufferSize, int preallocationPercent, bool check, Dictionary<string, string> customParameters)
 {
     bufferSize *= this._sectorSize;
     SevenZipCompressor compressor = new SevenZipCompressor();
     compressor.FastCompression = true;
     compressor.ArchiveFormat = archiveFormat;
     compressor.CompressionMethod = compressionMethod;
     compressor.CompressionLevel = compressionLevel;
     compressor.DefaultItemName = Path.GetFileName(sourceFilename);
     compressor.DirectoryStructure = false;
     compressor.ZipEncryptionMethod = zipEncryptionMethod;
     foreach (var pair in customParameters)
     {
         compressor.CustomParameters[pair.Key] = pair.Value;
     }
     using (FileStream sourceFileStream = new FileStream(sourceFilename,
         FileMode.Open, FileAccess.Read, FileShare.None, bufferSize,
         Win32.FileFlagNoBuffering | FileOptions.SequentialScan))
     {
         using (FileStream targetFileStream = new FileStream(targetFilename,
                fileMode, FileAccess.ReadWrite, FileShare.ReadWrite, 8,
                FileOptions.WriteThrough | Win32.FileFlagNoBuffering))
         {
             this.Compress(compressor, sourceFileStream, targetFileStream,
                 password, preallocationPercent, check, bufferSize);
         }
     }
 }
Beispiel #4
0
		public static void CreateFromDirectory (
			string sourceDirectoryName, string destinationArchiveFileName,
			CompressionLevel compressionLevel, bool includeBaseDirectory)
		{
			CreateFromDirectory (sourceDirectoryName, destinationArchiveFileName,
				compressionLevel, includeBaseDirectory, Encoding.UTF8);
		}
        /// <summary>
        /// Compresses a directory by using <see>
        ///         <cref>ZipFile.CreateFromDirectory</cref>
        ///     </see>
        /// </summary>
        /// <param name="directory">Directory to zip</param>
        /// <param name="zipFullPath">Zipfile fullname to save</param>
        /// <param name="overWriteExistingZip">true to overwrite existing zipfile</param>
        /// <param name="compressionLevel"><see cref="CompressionLevel"/></param>
        /// <param name="includeBaseDirectory">True to include basedirectory</param>
        public static void Compress( QuickIODirectoryInfo directory, String zipFullPath, bool overWriteExistingZip = false, CompressionLevel compressionLevel = CompressionLevel.Fastest, bool includeBaseDirectory = false )
        {
            Contract.Requires( directory != null );
            Contract.Requires( !String.IsNullOrWhiteSpace( zipFullPath ) );

            Compress( directory.FullName, zipFullPath, overWriteExistingZip, compressionLevel, includeBaseDirectory );
        }
Beispiel #6
0
		public static ZipArchiveEntry CreateEntryFromFile (
			this ZipArchive destination, string sourceFileName,
			string entryName, CompressionLevel compressionLevel)
		{
			if (destination == null)
				throw new ArgumentNullException ("destination");

			if (sourceFileName == null)
				throw new ArgumentNullException ("sourceFileName");

			if (entryName == null)
				throw new ArgumentNullException ("entryName");

			ZipArchiveEntry entry;
			using (Stream stream = File.Open (sourceFileName, FileMode.Open,
				FileAccess.Read, FileShare.Read))
			{
				var zipArchiveEntry = destination.CreateEntry (entryName, compressionLevel);

				using (Stream entryStream = zipArchiveEntry.Open ())
					stream.CopyTo (entryStream);

				entry = zipArchiveEntry;
			}

			return entry;
		}
        /// <summary>
        /// Internal constructor to specify the compressionlevel as well as the windowbits
        /// </summary>
        internal DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen, int windowBits)
        {
            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            InitializeDeflater(stream, leaveOpen, windowBits, compressionLevel);
        }
        // File : Create new, Append to existing, Raz existing
        // ArchiveType : Rar = 0, Zip = 1, Tar = 2, SevenZip = 3, GZip = 4
        // CompressionType : None = 0, GZip = 1, BZip2 = 2, PPMd = 3, Deflate = 4, Rar = 5, LZMA = 6, BCJ = 7, BCJ2 = 8, Unknown = 9,
        // Zip compression type : BZip2
        // GZip compression type : GZip
        // example from https://github.com/adamhathcock/sharpcompress/wiki/API-Examples
        // this example dont work to add file to an existing zip
        public static void Test_Compress(string compressFile, IEnumerable<string> files, string baseDirectory = null, ArchiveType archiveType = ArchiveType.Zip,
            CompressionType compressionType = CompressionType.BZip2, CompressionLevel compressionLevel = CompressionLevel.Default)
        {
            //FileOption
            if (baseDirectory != null && !baseDirectory.EndsWith("\\"))
                baseDirectory = baseDirectory + "\\";
            CompressionInfo compressionInfo = new CompressionInfo();
            compressionInfo.DeflateCompressionLevel = compressionLevel;
            compressionInfo.Type = compressionType;

            //Trace.WriteLine("SharpCompressManager : DeflateCompressionLevel {0}", compressionInfo.DeflateCompressionLevel);
            //Trace.WriteLine("SharpCompressManager : CompressionType {0}", compressionInfo.Type);

            Trace.WriteLine($"open compressed file \"{compressFile}\"");
            // File.OpenWrite ==> OpenOrCreate
            using (FileStream stream = File.OpenWrite(compressFile))
            using (IWriter writer = WriterFactory.Open(stream, archiveType, compressionInfo))
            //using (IWriter writer = WriterFactory.Open(stream, archiveType, CompressionType.BZip2))
            {
                foreach (string file in files)
                {
                    string entryPath;
                    if (baseDirectory != null && file.StartsWith(baseDirectory))
                        entryPath = file.Substring(baseDirectory.Length);
                    else
                        entryPath = zPath.GetFileName(file);
                    Trace.WriteLine($"add file \"{entryPath}\"  \"{file}\"");
                    writer.Write(entryPath, file);
                }
            }
        }
Beispiel #9
0
        private static async Task DoCreateFromDirectory(IStorageFolder source, Stream destinationArchive, CompressionLevel? compressionLevel,  Encoding entryNameEncoding)
        {
           // var notCreated = true;

            var fullName = source.Path;

            using (var destination = Open(destinationArchive, ZipArchiveMode.Create, entryNameEncoding))
            {
                foreach (var item in await source.GetStorageItemsRecursive())
                {
                 //   notCreated = false;
                    var length = item.Path.Length - fullName.Length;
                    var entryName = item.Path.Substring(fullName.Length, length).TrimStart('\\', '/');

                    if (item is IStorageFile)
                    {
                        var entry = await DoCreateEntryFromFile(destination, (IStorageFile)item, entryName, compressionLevel);
                    }
                    else
                    {
                        destination.CreateEntry(entryName + '\\');
                    }
                }
            }
        }
Beispiel #10
0
 public static void zlibDeflate(
     string pathInput,
     string pathOutput,
     CompressionMode mode,
     CompressionLevel level
 )
 {
     using (Stream input = File.OpenRead(pathInput))
     using (Stream output = File.Create(pathOutput))
     using (Stream deflateStream = new DeflateStream(
         mode == CompressionMode.Compress ? output : input,
         mode, level, true))
     {
         byte[] buff = new byte[ZLIB_BUFF_SIZE];
         int n = 0;
         Stream toRead = mode == CompressionMode.Compress ?
             input : deflateStream;
         Stream toWrite = mode == CompressionMode.Compress ?
             deflateStream : output;
         while (0 != (n = toRead.Read(buff, 0, buff.Length)))
         {
             toWrite.Write(buff, 0, n);
         }
         deflateStream.Close();
         input.Close();
         output.Close();
     }
 }
        public static ZipArchiveEntry CreateEntryFromFolder(this ZipArchive destination, string sourceFolderName, string entryName, CompressionLevel compressionLevel)
        {
            string sourceFolderFullPath = Path.GetFullPath(sourceFolderName);
            string basePath = entryName + "/";

            var createdFolders = new HashSet<string>();

            var entry = destination.CreateEntry(basePath);
            createdFolders.Add(basePath);

            foreach (string dirFolder in Directory.EnumerateDirectories(sourceFolderName, "*.*", SearchOption.AllDirectories))
            {
                string dirFileFullPath = Path.GetFullPath(dirFolder);
                string relativePath = (basePath + dirFileFullPath.Replace(sourceFolderFullPath + Path.DirectorySeparatorChar, ""))
                    .Replace(Path.DirectorySeparatorChar, '/');
                string relativePathSlash = relativePath + "/";

                if (!createdFolders.Contains(relativePathSlash))
                {
                    destination.CreateEntry(relativePathSlash, compressionLevel);
                    createdFolders.Add(relativePathSlash);
                }
            }

            foreach (string dirFile in Directory.EnumerateFiles(sourceFolderName, "*.*", SearchOption.AllDirectories))
            {
                string dirFileFullPath = Path.GetFullPath(dirFile);
                string relativePath = (basePath + dirFileFullPath.Replace(sourceFolderFullPath + Path.DirectorySeparatorChar, ""))
                    .Replace(Path.DirectorySeparatorChar, '/');
                destination.CreateEntryFromFile(dirFile, relativePath, compressionLevel);
            }

            return entry;
        }
        public void SetLevel(CompressionLevel level)
        {
            if (!Enum.IsDefined(typeof(CompressionLevel), level))
            {
                throw new InvalidEnumArgumentException();
            }
            switch (this.KnownFormat)
            {
                case KnownSevenZipFormat.Xz:
                case KnownSevenZipFormat.BZip2:
                    if (level == CompressionLevel.Store)
                    {
                        throw new NotSupportedException();
                    }
                    break;

                case KnownSevenZipFormat.Tar:
                    if (level != CompressionLevel.Store)
                    {
                        throw new NotSupportedException();
                    }
                    break;

                case KnownSevenZipFormat.GZip:
                    switch (level)
                    {
                        case CompressionLevel.Store:
                        case CompressionLevel.Fast:
                            throw new NotSupportedException();
                    }
                    break;
            }
            this.Properties["x"] = Convert.ToUInt32(level);
        }
Beispiel #13
0
        // Implies mode = Compress
        public DeflateManagedStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen)
        {
            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            InitializeDeflater(stream, leaveOpen, compressionLevel);
        }
        /// <summary>
        /// Compresses a directory by using <see>
        ///         <cref>ZipFile.CreateFromDirectory</cref>
        ///     </see>
        /// </summary>
        /// <param name="directory">Directory to zip</param>
        /// <param name="zipFullPath">Zipfile fullname to save</param>
        /// <param name="overWriteExistingZip">true to overwrite existing zipfile</param>
        /// <param name="compressionLevel"><see cref="CompressionLevel"/></param>
        /// <param name="includeBaseDirectory">True to include basedirectory</param>
        public static void Compress( QuickIODirectoryInfo directory, String zipFullPath, bool overWriteExistingZip = false, CompressionLevel compressionLevel = CompressionLevel.Fastest, bool includeBaseDirectory = false )
        {
            Invariant.NotNull( directory );
            Invariant.NotEmpty( zipFullPath );

            Compress( directory.FullName, zipFullPath, overWriteExistingZip, compressionLevel, includeBaseDirectory );
        }
Beispiel #15
0
 public Packer(string path, FileStream fs, CompressionLevel level)
 {
     _path = path.TrimEnd('\\') + "\\";
     _pathPrefixLength = _path.Length;
     _fs = fs;
     _level = level;
 }
 public ZlibBaseStream(System.IO.Stream stream,
                       CompressionMode compressionMode,
                       CompressionLevel level,
                       ZlibStreamFlavor flavor,
                       bool leaveOpen)
     :this(stream, compressionMode, level, flavor,leaveOpen, ZlibConstants.WindowBitsDefault)
 { }
 public ZOutputStream(Stream output, CompressionLevel level, bool nowrap)
     : this()
 {
     this._output = output;
     this._compressor = new Deflate(level, nowrap);
     this._compressionMode = CompressionMode.Compress;
 }
 public void Compress_Canterbury(int innerIterations, string fileName, CompressionLevel compressLevel)
 {
     byte[] bytes = File.ReadAllBytes(Path.Combine("GZTestData", "Canterbury", fileName));
     PerfUtils utils = new PerfUtils();
     FileStream[] filestreams = new FileStream[innerIterations];
     GZipStream[] gzips = new GZipStream[innerIterations];
     string[] paths = new string[innerIterations];
     foreach (var iteration in Benchmark.Iterations)
     {
         for (int i = 0; i < innerIterations; i++)
         {
             paths[i] = utils.GetTestFilePath();
             filestreams[i] = File.Create(paths[i]);
         }
         using (iteration.StartMeasurement())
             for (int i = 0; i < innerIterations; i++)
             {
                 gzips[i] = new GZipStream(filestreams[i], compressLevel);
                 gzips[i].Write(bytes, 0, bytes.Length);
                 gzips[i].Flush();
                 gzips[i].Dispose();
                 filestreams[i].Dispose();
             }
         for (int i = 0; i < innerIterations; i++)
             File.Delete(paths[i]);
     }
 }
Beispiel #19
0
        internal Deflater(CompressionLevel compressionLevel, int windowBits)
        {
            Debug.Assert(windowBits >= minWindowBits && windowBits <= maxWindowBits);
            ZLibNative.CompressionLevel zlibCompressionLevel;
            int memLevel;

            switch (compressionLevel)
            {
                // See the note in ZLibNative.CompressionLevel for the recommended combinations.

                case CompressionLevel.Optimal:
                    zlibCompressionLevel = ZLibNative.CompressionLevel.DefaultCompression;
                    memLevel = ZLibNative.Deflate_DefaultMemLevel;
                    break;

                case CompressionLevel.Fastest:
                    zlibCompressionLevel = ZLibNative.CompressionLevel.BestSpeed;
                    memLevel = ZLibNative.Deflate_DefaultMemLevel;
                    break;

                case CompressionLevel.NoCompression:
                    zlibCompressionLevel = ZLibNative.CompressionLevel.NoCompression;
                    memLevel = ZLibNative.Deflate_NoCompressionMemLevel;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("compressionLevel");
            }

            ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;

            DeflateInit(zlibCompressionLevel, windowBits, memLevel, strategy);
        }
Beispiel #20
0
        public static void UpdateTarget(
            string what,
            string newWhere,
            bool newCompressed,
            CompressionAlgo newAlgo,
            CompressionLevel newLevel,
            DateTime newStart,
            TimeSpan newInterval)
        {
            BackupTarget target;
            if ((target = GetTarget(what)) == null)
                throw new ArgumentException(nameof(what));

            // make sure there aren't any minutes or seconds
            newInterval = new TimeSpan(newInterval.Days, newInterval.Hours, 0, 0);

            target.Where = newWhere;
            target.Compressed = newCompressed;
            target.Algo = newAlgo;
            target.Level = newLevel;
            target.Interval = newInterval;
            target.Start = newStart;

            target.CalculateNextBackup(true);

            var index = targets.IndexOf(target);
            targets.RemoveAt(index);
            targets.Insert(index, target);
            SaveTargets();
        }
 public static void CompressDirectory(string compressDirectory, string archFileName, OutArchiveFormat archiveFormat, CompressionLevel compressionLevel)
 {
     SevenZipCompressor.SetLibraryPath(LibraryPath);
     SevenZipCompressor cmp = new SevenZipCompressor();
     cmp.ArchiveFormat = archiveFormat;
     cmp.CompressionLevel = compressionLevel;
     cmp.BeginCompressDirectory(compressDirectory, archFileName);
 }
Beispiel #22
0
 /// <summary>Create a <c>GZipStream</c> using the specified <c>CompressionMode</c> and the specified <c>CompressionLevel</c>, and explicitly specify whether the stream should be left open after Deflation or Inflation.</summary>
 /// <remarks><para>This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs.  By default, after<c>Close()</c> is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it.  Specify true for the <paramref name="leaveOpen" /> parameter to leave the stream open.</para><para>As noted in the class documentation, the <c>CompressionMode</c> (Compress or Decompress) also establishes the "direction" of the stream.  A<c>GZipStream</c> with <c>CompressionMode.Compress</c> works only through<c>Write()</c>.  A <c>GZipStream</c> with <c>CompressionMode.Decompress</c> works only through <c>Read()</c>.</para></remarks>
 /// <example>
 ///   This example shows how to use a <c>GZipStream</c> to compress data.
 ///   <code>using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress)) { using (var raw = System.IO.File.Create(outputFile)) { using (Stream compressor = new GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression, true)) { byte[] buffer = new byte[WORKING_BUFFER_SIZE]; int n; while ((n= input.Read(buffer, 0, buffer.Length)) != 0) { compressor.Write(buffer, 0, n); } } } }</code>
 ///   <code lang = "VB">
 ///     Dim outputFile As String = (fileToCompress &amp; ".compressed") Using input As Stream =
 ///     File.OpenRead(fileToCompress) Using raw As FileStream = File.Create(outputFile) Using compressor As
 ///     Stream = New GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression, True) Dim
 ///     buffer As Byte() = New Byte(4096) {} Dim n As Integer = -1 Do While (n &lt;&gt; 0) If (n &gt; 0) Then
 ///     compressor.Write(buffer, 0, n) End If n = input.Read(buffer, 0, buffer.Length) Loop End Using End Using
 ///     End Using
 ///   </code>
 /// </example>
 /// <param name="stream">The stream which will be read or written.</param>
 /// <param name="mode">Indicates whether the GZipStream will compress or decompress.</param>
 /// <param name="level">A tuning knob to trade speed for effectiveness.</param>
 /// <param name="leaveOpen">true if the application would like the stream to remain open after inflation/deflation.</param>
 public GZipStream(
     Stream stream, 
     CompressionMode mode, 
     CompressionLevel level = CompressionLevel.Default, 
     bool leaveOpen = false)
 {
     this.baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.Gzip, leaveOpen);
 }
Beispiel #23
0
 public ZOutputStream(Stream output, CompressionLevel level, bool nowrap)
     : base()
 {
     this.FlushMode = FlushType.Z_PARTIAL_FLUSH;
     this._output = output;
     this.deflateInit(level, nowrap);
     this.compress = true;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ZlibStream"/> class by using the specified stream and compression level, and optionally leaves the stream open.
        /// </summary>
        /// <param name="stream">The stream to compress or decompress.</param>
        /// <param name="compressionLevel">One of the enumeration values that indicates whether to emphasize speed or compression efficiency when compressing the stream.</param>
        /// <param name="leaveOpen">true to leave the stream open after disposing the DeflateStream object; otherwise, false.</param>
        public ZlibStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen)
            : base(stream, compressionLevel, true)
        {
            _stream = stream;
            _leaveOpen = leaveOpen;

            WriteHeader();
        }
Beispiel #25
0
        //Initializes, attaches it to archive
        internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd, CompressionLevel compressionLevel)

            : this(archive, cd)
        {
            // Checking of compressionLevel is passed down to DeflateStream and the IDeflater implementation
            // as it is a pugable component that completely encapsulates the meaning of compressionLevel.

            _compressionLevel = compressionLevel;
        }
Beispiel #26
0
		public static void CreateFromDirectory (
			string sourceDirectoryName,
			string destinationArchiveFileName,
			CompressionLevel compressionLevel,
			bool includeBaseDirectory,
			Encoding entryNameEncoding)
		{
			throw new NotImplementedException ();
		}
Beispiel #27
0
        /// <summary>
        /// Creates a cabinet.
        /// </summary>
        /// <param name="cabName">Name of cabinet to create.</param>
        /// <param name="cabDir">Directory to create cabinet in.</param>
        /// <param name="maxSize">Maximum size of cabinet.</param>
        /// <param name="maxThresh">Maximum threshold for each cabinet.</param>
        /// <param name="compressionLevel">Level of compression to apply.</param>
        public WixCreateCab(string cabName, string cabDir, int maxSize, int maxThresh, CompressionLevel compressionLevel)
        {
            int error = CabInterop.CreateCabBegin(cabName, cabDir, (uint)maxSize, (uint)maxThresh, (uint)compressionLevel, out this.handle);

            if (0 != error)
            {
                throw new WixCabCreationException(error);
            }
        }
Beispiel #28
0
 internal ZipPackagePart(ZipPackage package, Uri partUri, string contentType, CompressionLevel compressionLevel)
 {
     Package = package;
     //Entry = new ZipEntry();
     //Entry.FileName = partUri.OriginalString.Replace('/','\\');
     Uri = partUri;
     ContentType = contentType;
     CompressionLevel = compressionLevel;
 }
Beispiel #29
0
        /// <summary>
        /// Creates a new InstallPackage object, specifying an alternate file source
        /// directory and/or working directory.
        /// </summary>
        /// <param name="packagePath">Path to the install package to be created or opened</param>
        /// <param name="openMode">Open mode for the database</param>
        /// <param name="sourceDir">Location to obtain source files and cabinets when extracting
        /// or updating files in the working directory. This is often the location of an original
        /// copy of the package that is not meant to be modified. If this parameter is null, it
        /// defaults to the directory of <paramref name="packagePath"/>.</param>
        /// <param name="workingDir">Location where files will be extracted to/updated from. Also
        /// the location where a temporary folder is created during some operations. If this
        /// parameter is null, it defaults to the directory of <paramref name="packagePath"/>.</param>
        /// <remarks>If the source location is different than the working directory, then
        /// no files will be modified at the source location.
        /// </remarks>
        public InstallPackage(string packagePath, DatabaseOpenMode openMode,
        string sourceDir, string workingDir)
            : base(packagePath, openMode)
        {
            this.sourceDir  = (sourceDir  != null ? sourceDir  : Path.GetDirectoryName(packagePath));
            this.workingDir = (workingDir != null ? workingDir : Path.GetDirectoryName(packagePath));
            this.compressionLevel = CompressionLevel.Normal;

            this.DeleteOnClose(this.TempDirectory);
        }
Beispiel #30
0
        public void AddMessage(Stream msg, string filename, CompressionLevel compressionLevel = CompressionLevel.Optimal)
        {
            var entry = _zipArchive.CreateEntry(filename, compressionLevel);

            using (var entryStream = entry.Open())
            {
                msg.CopyTo(entryStream);
            }

        }
 /// <summary>
 /// Creates a new instance of the compression engine base class.
 /// </summary>
 protected CompressionEngine()
 {
     this.compressionLevel = CompressionLevel.Normal;
 }
Beispiel #32
0
 internal DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen, bool gzip)
     : this(stream, CompressionMode.Compress, leaveOpen, gzip)
 {
 }
 public ParallelDeflateOutputStream(Stream stream, CompressionLevel level, bool leaveOpen)
     : this(stream, CompressionLevel.Default, CompressionStrategy.Default, leaveOpen)
 {
 }
Beispiel #34
0
        private static void Backup(
            StorageEnvironment env, CompressionLevel compression, Action <string> infoNotify,
            Action backupStarted, AbstractPager dataPager, ZipArchive package, string basePath, DataCopier copier)
        {
            var  usedJournals       = new List <JournalFile>();
            long lastWrittenLogPage = -1;
            long lastWrittenLogFile = -1;
            LowLevelTransaction txr = null;
            var backupSuccess       = false;

            try
            {
                long allocatedPages;
                var  writePesistentContext = new TransactionPersistentContext(true);
                var  readPesistentContext  = new TransactionPersistentContext(true);
                using (var txw = env.NewLowLevelTransaction(writePesistentContext, TransactionFlags.ReadWrite)) // so we can snapshot the headers safely
                {
                    txr            = env.NewLowLevelTransaction(readPesistentContext, TransactionFlags.Read);   // now have snapshot view
                    allocatedPages = dataPager.NumberOfAllocatedPages;

                    Debug.Assert(HeaderAccessor.HeaderFileNames.Length == 2);
                    infoNotify("Voron copy headers for " + basePath);
                    VoronBackupUtil.CopyHeaders(compression, package, copier, env.Options, basePath);

                    // journal files snapshot
                    var files = env.Journal.Files; // thread safety copy

                    JournalInfo journalInfo = env.HeaderAccessor.Get(ptr => ptr->Journal);
                    for (var journalNum = journalInfo.CurrentJournal - journalInfo.JournalFilesCount + 1;
                         journalNum <= journalInfo.CurrentJournal;
                         journalNum++)
                    {
                        var journalFile = files.FirstOrDefault(x => x.Number == journalNum);
                        // first check journal files currently being in use
                        if (journalFile == null)
                        {
                            long journalSize;
                            using (var pager = env.Options.OpenJournalPager(journalNum))
                            {
                                journalSize = Bits.NextPowerOf2(pager.NumberOfAllocatedPages * Constants.Storage.PageSize);
                            }

                            journalFile = new JournalFile(env, env.Options.CreateJournalWriter(journalNum, journalSize), journalNum);
                        }

                        journalFile.AddRef();
                        usedJournals.Add(journalFile);
                    }

                    if (env.Journal.CurrentFile != null)
                    {
                        lastWrittenLogFile = env.Journal.CurrentFile.Number;
                        lastWrittenLogPage = env.Journal.CurrentFile.WritePosIn4KbPosition - 1;
                    }

                    // txw.Commit(); intentionally not committing
                }

                backupStarted?.Invoke();

                // data file backup
                var dataPart = package.CreateEntry(Path.Combine(basePath, Constants.DatabaseFilename), compression);
                Debug.Assert(dataPart != null);

                if (allocatedPages > 0) //only true if dataPager is still empty at backup start
                {
                    using (var dataStream = dataPart.Open())
                    {
                        // now can copy everything else
                        copier.ToStream(dataPager, 0, allocatedPages, dataStream);
                    }
                }

                try
                {
                    long lastBackedupJournal = 0;
                    foreach (var journalFile in usedJournals)
                    {
                        var entryName   = StorageEnvironmentOptions.JournalName(journalFile.Number);
                        var journalPart = package.CreateEntry(Path.Combine(basePath, entryName), compression);

                        Debug.Assert(journalPart != null);

                        long pagesToCopy = journalFile.JournalWriter.NumberOfAllocated4Kb;
                        if (journalFile.Number == lastWrittenLogFile)
                        {
                            pagesToCopy = lastWrittenLogPage + 1;
                        }

                        using (var stream = journalPart.Open())
                        {
                            copier.ToStream(env, journalFile, 0, pagesToCopy, stream);
                            infoNotify(string.Format("Voron copy journal file {0}", entryName));
                        }

                        lastBackedupJournal = journalFile.Number;
                    }

                    if (env.Options.IncrementalBackupEnabled)
                    {
                        env.HeaderAccessor.Modify(header =>
                        {
                            header->IncrementalBackup.LastBackedUpJournal = lastBackedupJournal;

                            //since we backed-up everything, no need to start next incremental backup from the middle
                            header->IncrementalBackup.LastBackedUpJournalPage = -1;
                        });
                    }
                    backupSuccess = true;
                }
                catch (Exception)
                {
                    backupSuccess = false;
                    throw;
                }
                finally
                {
                    var lastSyncedJournal = env.HeaderAccessor.Get(header => header->Journal).LastSyncedJournal;
                    foreach (var journalFile in usedJournals)
                    {
                        if (backupSuccess)                                 // if backup succeeded we can remove journals
                        {
                            if (journalFile.Number < lastWrittenLogFile && // prevent deletion of the current journal and journals with a greater number
                                journalFile.Number < lastSyncedJournal)    // prevent deletion of journals that aren't synced with the data file
                            {
                                journalFile.DeleteOnClose = true;
                            }
                        }

                        journalFile.Release();
                    }
                }
            }
            finally
            {
                txr?.Dispose();
            }
        }
Beispiel #35
0
 public DeflateStream(Stream stream, CompressionLevel compressionLevel)
     : this(stream, compressionLevel, false, false)
 {
 }
Beispiel #36
0
 /// <summary>
 /// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel.
 /// </summary>
 /// <remarks>
 /// The codec will use the maximum window bits (15) and the specified
 /// CompressionLevel.  It will emit a ZLIB stream as it compresses.
 /// </remarks>
 /// <param name="level">The compression level for the codec.</param>
 /// <returns>Z_OK if all goes well.</returns>
 public int InitializeDeflate(CompressionLevel level)
 {
     this.CompressLevel = level;
     return(_InternalInitializeDeflate(true));
 }
Beispiel #37
0
 /// <summary>
 ///   Create a <c>ZlibStream</c> using the specified <c>CompressionMode</c>
 ///   and the specified <c>CompressionLevel</c>, and explicitly specify
 ///   whether the stream should be left open after Deflation or Inflation.
 /// </summary>
 ///
 /// <remarks>
 ///
 /// <para>
 ///   This constructor allows the application to request that the captive
 ///   stream remain open after the deflation or inflation occurs.  By
 ///   default, after <c>Close()</c> is called on the stream, the captive
 ///   stream is also closed. In some cases this is not desired, for example
 ///   if the stream is a <see cref="System.IO.MemoryStream"/> that will be
 ///   re-read after compression.  Specify true for the <paramref
 ///   name="leaveOpen"/> parameter to leave the stream open.
 /// </para>
 ///
 /// <para>
 ///   When mode is <c>CompressionMode.Decompress</c>, the level parameter is
 ///   ignored.
 /// </para>
 ///
 /// </remarks>
 ///
 /// <example>
 ///
 /// This example shows how to use a ZlibStream to compress the data from a file,
 /// and store the result into another file. The filestream remains open to allow
 /// additional data to be written to it.
 ///
 /// <code>
 /// using (var output = System.IO.File.Create(fileToCompress + ".zlib"))
 /// {
 ///     using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
 ///     {
 ///         using (Stream compressor = new ZlibStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, true))
 ///         {
 ///             byte[] buffer = new byte[WORKING_BUFFER_SIZE];
 ///             int n;
 ///             while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
 ///             {
 ///                 compressor.Write(buffer, 0, n);
 ///             }
 ///         }
 ///     }
 ///     // can write additional data to the output stream here
 /// }
 /// </code>
 /// <code lang="VB">
 /// Using output As FileStream = File.Create(fileToCompress &amp; ".zlib")
 ///     Using input As Stream = File.OpenRead(fileToCompress)
 ///         Using compressor As Stream = New ZlibStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, True)
 ///             Dim buffer As Byte() = New Byte(4096) {}
 ///             Dim n As Integer = -1
 ///             Do While (n &lt;&gt; 0)
 ///                 If (n &gt; 0) Then
 ///                     compressor.Write(buffer, 0, n)
 ///                 End If
 ///                 n = input.Read(buffer, 0, buffer.Length)
 ///             Loop
 ///         End Using
 ///     End Using
 ///     ' can write additional data to the output stream here.
 /// End Using
 /// </code>
 /// </example>
 ///
 /// <param name="stream">The stream which will be read or written.</param>
 ///
 /// <param name="mode">Indicates whether the ZlibStream will compress or decompress.</param>
 ///
 /// <param name="leaveOpen">
 /// true if the application would like the stream to remain open after
 /// inflation/deflation.
 /// </param>
 ///
 /// <param name="level">
 /// A tuning knob to trade speed for effectiveness. This parameter is
 /// effective only when mode is <c>CompressionMode.Compress</c>.
 /// </param>
 public ZlibStream(System.IO.Stream stream, CompressionMode mode, CompressionLevel level, bool leaveOpen)
 {
     _baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.ZLIB, leaveOpen);
 }
 /// <summary>
 /// <p>Adds a file from the file system to the archive under the specified entry name.
 /// The new entry in the archive will contain the contents of the file.
 /// The last write time of the archive entry is set to the last write time of the file on the file system.
 /// If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.
 /// If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format
 /// (midnight on January 1, 1980) will be used.</p>
 /// <p>If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.</p>
 /// </summary>
 /// <exception cref="ArgumentException">sourceFileName is a zero-length string, contains only whitespace, or contains one or more
 /// invalid characters as defined by InvalidPathChars. -or- entryName is a zero-length string.</exception>
 /// <exception cref="ArgumentNullException">sourceFileName or entryName is null.</exception>
 /// <exception cref="PathTooLongException">In sourceFileName, the specified path, file name, or both exceed the system-defined maximum length.
 /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.</exception>
 /// <exception cref="DirectoryNotFoundException">The specified sourceFileName is invalid, (for example, it is on an unmapped drive).</exception>
 /// <exception cref="IOException">An I/O error occurred while opening the file specified by sourceFileName.</exception>
 /// <exception cref="UnauthorizedAccessException">sourceFileName specified a directory.
 /// -or- The caller does not have the required permission.</exception>
 /// <exception cref="FileNotFoundException">The file specified in sourceFileName was not found. </exception>
 /// <exception cref="NotSupportedException">sourceFileName is in an invalid format or the ZipArchive does not support writing.</exception>
 /// <exception cref="ObjectDisposedException">The ZipArchive has already been closed.</exception>
 ///
 /// <param name="destination">The zip archive to add the file to.</param>
 /// <param name="sourceFileName">The path to the file on the file system to be copied from. The path is permitted to specify relative
 /// or absolute path information. Relative path information is interpreted as relative to the current working directory.</param>
 /// <param name="entryName">The name of the entry to be created.</param>
 /// <param name="compressionLevel">The level of the compression (speed/memory vs. compressed size trade-off).</param>
 /// <returns>A wrapper for the newly created entry.</returns>
 public static ZipArchiveEntry CreateEntryFromFile(this ZipArchive destination,
                                                   string sourceFileName, string entryName, CompressionLevel compressionLevel) =>
 DoCreateEntryFromFile(destination, sourceFileName, entryName, compressionLevel);
 public DeflateStream(Stream stream, CompressionMode mode,
                      CompressionLevel level = CompressionLevel.Default,
                      bool leaveOpen         = false)
 {
     _baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.DEFLATE, leaveOpen);
 }
 public BrotliCompressionProvider(CompressionLevel compressionLevel = CompressionLevel.Fastest)
 {
     _compressionLevel = compressionLevel;
 }
        public void Compress_Canterbury(int innerIterations, string uncompressedFileName, CompressionLevel compressLevel)
        {
            byte[]         bytes = File.ReadAllBytes(uncompressedFileName);
            MemoryStream[] compressedDataStreams = new MemoryStream[innerIterations];
            foreach (var iteration in Benchmark.Iterations)
            {
                // resizing a memory stream during compression will throw off our results, so pre-size it to the
                // size of our input
                for (int i = 0; i < innerIterations; i++)
                {
                    compressedDataStreams[i] = new MemoryStream(bytes.Length);
                }
                using (iteration.StartMeasurement())
                    for (int i = 0; i < innerIterations; i++)
                    {
                        using (Stream compressor = CreateStream(compressedDataStreams[i], compressLevel))
                            compressor.Write(bytes, 0, bytes.Length);
                    }

                for (int i = 0; i < innerIterations; i++)
                {
                    compressedDataStreams[i].Dispose();
                }
            }
        }
Beispiel #42
0
 public int InitializeDeflate(CompressionLevel level, int bits)
 {
     CompressLevel = level;
     WindowBits    = bits;
     return(_InternalInitializeDeflate(wantRfc1950Header: true));
 }
 public override Stream CreateStream(Stream stream, CompressionLevel level) => new BrotliStream(stream, level);
Beispiel #44
0
 /// <summary>
 /// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel,
 /// and the explicit flag governing whether to emit an RFC1950 header byte pair.
 /// </summary>
 /// <remarks>
 /// The codec will use the maximum window bits (15) and the specified CompressionLevel.
 /// If you want to generate a zlib stream, you should specify true for
 /// wantRfc1950Header. In this case, the library will emit a ZLIB
 /// header, as defined in <see href="http://www.ietf.org/rfc/rfc1950.txt">RFC
 /// 1950</see>, in the compressed stream.
 /// </remarks>
 /// <param name="level">The compression level for the codec.</param>
 /// <param name="wantRfc1950Header">whether to emit an initial RFC1950 byte pair in the compressed stream.</param>
 /// <returns>Z_OK if all goes well.</returns>
 public int InitializeDeflate(CompressionLevel level, bool wantRfc1950Header)
 {
     this.CompressLevel = level;
     return(_InternalInitializeDeflate(wantRfc1950Header));
 }
Beispiel #45
0
 /// <summary>
 /// Returns a stream to the file at the specified location. Blocks other writes until stream is closed.
 /// </summary>
 /// <param name="path">Path to save.</param>
 /// <param name="compressionLevel">Sets the compression level for the file.</param>
 /// <returns>Writable stream.</returns>
 protected Stream WriteGetStream(string path,
                                 CompressionLevel compressionLevel)
 {
     return(CreateEntityStream(path, true, compressionLevel));
 }
Beispiel #46
0
 /// <summary>
 /// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel,
 /// and the specified number of window bits.
 /// </summary>
 /// <remarks>
 /// The codec will use the specified number of window bits and the specified CompressionLevel.
 /// </remarks>
 /// <param name="level">The compression level for the codec.</param>
 /// <param name="bits">the number of window bits to use.  If you don't know what this means, don't use this method.</param>
 /// <returns>Z_OK if all goes well.</returns>
 public int InitializeDeflate(CompressionLevel level, int bits)
 {
     this.CompressLevel = level;
     this.WindowBits    = bits;
     return(_InternalInitializeDeflate(true));
 }
Beispiel #47
0
 internal DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen, int windowsBits)
     : this(stream, compressionLevel, leaveOpen, true)
 {
 }
Beispiel #48
0
 /// <summary>
 /// Initialize the ZlibCodec for deflation operation, using the specified
 /// CompressionLevel, the specified number of window bits, and the explicit flag
 /// governing whether to emit an RFC1950 header byte pair.
 /// </summary>
 ///
 /// <param name="level">The compression level for the codec.</param>
 /// <param name="wantRfc1950Header">whether to emit an initial RFC1950 byte pair in the compressed stream.</param>
 /// <param name="bits">the number of window bits to use.  If you don't know what this means, don't use this method.</param>
 /// <returns>Z_OK if all goes well.</returns>
 public int InitializeDeflate(CompressionLevel level, int bits, bool wantRfc1950Header)
 {
     this.CompressLevel = level;
     this.WindowBits    = bits;
     return(_InternalInitializeDeflate(wantRfc1950Header));
 }
Beispiel #49
0
 public DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen)
     : this(stream, compressionLevel, leaveOpen, false)
 {
 }
 public static void Compress(ISource source, byte[] data, CompressionLevel level = CompressionLevel.Optimal)
 {
     using var stream = new MemoryStream(data);
     Compress(source, stream, level);
 }
Beispiel #51
0
        /// <summary>
        /// <p>Adds a file from the file system to the archive under the specified entry name.
        /// The new entry in the archive will contain the contents of the file.
        /// The last write time of the archive entry is set to the last write time of the file on the file system.
        /// If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.
        /// If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format
        /// (midnight on January 1, 1980) will be used.</p>
        /// <p>If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.</p>
        /// </summary>
        /// <exception cref="ArgumentException">sourceFileName is a zero-length string, contains only white space, or contains one or more
        /// invalid characters as defined by InvalidPathChars. -or- entryName is a zero-length string.</exception>
        /// <exception cref="ArgumentNullException">sourceFileName or entryName is null.</exception>
        /// <exception cref="PathTooLongException">In sourceFileName, the specified path, file name, or both exceed the system-defined maximum length.
        /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.</exception>
        /// <exception cref="DirectoryNotFoundException">The specified sourceFileName is invalid, (for example, it is on an unmapped drive).</exception>
        /// <exception cref="IOException">An I/O error occurred while opening the file specified by sourceFileName.</exception>
        /// <exception cref="UnauthorizedAccessException">sourceFileName specified a directory.
        /// -or- The caller does not have the required permission.</exception>
        /// <exception cref="FileNotFoundException">The file specified in sourceFileName was not found. </exception>
        /// <exception cref="NotSupportedException">sourceFileName is in an invalid format or the ZipArchive does not support writing.</exception>
        /// <exception cref="ObjectDisposedException">The ZipArchive has already been closed.</exception>
        ///
        /// <param name="sourceFileName">The path to the file on the file system to be copied from. The path is permitted to specify relative
        /// or absolute path information. Relative path information is interpreted as relative to the current working directory.</param>
        /// <param name="entryName">The name of the entry to be created.</param>
        /// <param name="compressionLevel">The level of the compression (speed/memory vs. compressed size trade-off).</param>
        /// <returns>A wrapper for the newly created entry.</returns>
        public static ZipArchiveEntry CreateEntryFromFile(this ZipArchive destination,
                                                          String sourceFileName, String entryName, CompressionLevel compressionLevel)
        {
            // Checking of compressionLevel is passed down to DeflateStream and the IDeflater implementation
            // as it is a pugable component that completely encapsulates the meaning of compressionLevel.

            Contract.Ensures(Contract.Result <ZipArchiveEntry>() != null);
            Contract.EndContractBlock();

            return(DoCreateEntryFromFile(destination, sourceFileName, entryName, compressionLevel));
        }
Beispiel #52
0
 public int InitializeDeflate(CompressionLevel level)
 {
     CompressLevel = level;
     return(_InternalInitializeDeflate(wantRfc1950Header: true));
 }
Beispiel #53
0
 public ZLibStream(Stream stream, CompressionLevel level, bool leaveOpen)
     : base(stream, level, leaveOpen)
 {
 }
Beispiel #54
0
 public ParallelDeflateOutputStream(Stream stream, CompressionLevel level)
     : this(stream, level, CompressionStrategy.Default, false)
 {
 }
 public static void Compress(ISource source, Stream stream, CompressionLevel level = CompressionLevel.Optimal)
 {
     Compressor.Compress(source.RootDirectory, source.Files, stream, level);
 }
Beispiel #56
0
 /// <summary>
 /// Creates an empty entry in the Zip archive with the specified entry name. There are no restrictions on the names of entries. The last write time of the entry is set to the current time. If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.
 /// </summary>
 /// <exception cref="ArgumentException">entryName is a zero-length string.</exception>
 /// <exception cref="ArgumentNullException">entryName is null.</exception>
 /// <exception cref="NotSupportedException">The ZipArchive does not support writing.</exception>
 /// <exception cref="ObjectDisposedException">The ZipArchive has already been closed.</exception>
 /// <param name="entryName">A path relative to the root of the archive, indicating the name of the entry to be created.</param>
 /// <param name="compressionLevel">The level of the compression (speed/memory vs. compressed size trade-off).</param>
 /// <returns>A wrapper for the newly created file entry in the archive.</returns>
 public ZipArchiveEntry CreateEntry(string entryName, CompressionLevel compressionLevel)
 {
     return(DoCreateEntry(entryName, compressionLevel));
 }
 public static void Compress(ISource source, FileInfo file, CompressionLevel level = CompressionLevel.Optimal)
 {
     using var stream = new FileStream(file.FullName, FileMode.Create, FileAccess.Write);
     Compress(source, stream, level);
 }
 public override Stream CreateStream(Stream stream, CompressionLevel level, bool leaveOpen) => new BrotliStream(stream, level, leaveOpen);
Beispiel #59
0
 /// <summary>
 /// Create a DeflateStream using the specified CompressionMode and the specified CompressionLevel.
 /// </summary>
 ///
 /// <remarks>
 ///
 /// <para>
 ///   When mode is <c>CompressionMode.Decompress</c>, the level parameter is
 ///   ignored.  The "captive" stream will be closed when the DeflateStream is
 ///   closed.
 /// </para>
 ///
 /// </remarks>
 ///
 /// <example>
 ///
 ///   This example uses a DeflateStream to compress data from a file, and writes
 ///   the compressed data to another file.
 ///
 /// <code>
 /// using (System.IO.Stream input = System.IO.File.Open(fileToCompress, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
 /// {
 ///	 using (var raw = System.IO.File.Create(fileToCompress + ".deflated"))
 ///	 {
 ///		 using (Stream compressor = new DeflateStream(raw,
 ///													  CompressionMode.Compress,
 ///													  CompressionLevel.BestCompression))
 ///		 {
 ///			 byte[] buffer = new byte[WORKING_BUFFER_SIZE];
 ///			 int n= -1;
 ///			 while (n != 0)
 ///			 {
 ///				 if (n &gt; 0)
 ///					 compressor.Write(buffer, 0, n);
 ///				 n= input.Read(buffer, 0, buffer.Length);
 ///			 }
 ///		 }
 ///	 }
 /// }
 /// </code>
 ///
 /// <code lang="VB">
 /// Using input As Stream = File.Open(fileToCompress, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
 ///	 Using raw As FileStream = File.Create(fileToCompress &amp; ".deflated")
 ///		 Using compressor As Stream = New DeflateStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression)
 ///			 Dim buffer As Byte() = New Byte(4096) {}
 ///			 Dim n As Integer = -1
 ///			 Do While (n &lt;&gt; 0)
 ///				 If (n &gt; 0) Then
 ///					 compressor.Write(buffer, 0, n)
 ///				 End If
 ///				 n = input.Read(buffer, 0, buffer.Length)
 ///			 Loop
 ///		 End Using
 ///	 End Using
 /// End Using
 /// </code>
 /// </example>
 /// <param name="stream">The stream to be read or written while deflating or inflating.</param>
 /// <param name="mode">Indicates whether the <c>DeflateStream</c> will compress or decompress.</param>
 /// <param name="level">A tuning knob to trade speed for effectiveness.</param>
 public DeflateStream(System.IO.Stream stream, CompressionMode mode, CompressionLevel level)
     : this(stream, mode, level, false)
 {
 }
Beispiel #60
0
 /// <summary>
 ///   Create a <c>DeflateStream</c> using the specified <c>CompressionMode</c>
 ///   and the specified <c>CompressionLevel</c>, and explicitly specify whether
 ///   the stream should be left open after Deflation or Inflation.
 /// </summary>
 ///
 /// <remarks>
 ///
 /// <para>
 ///   When mode is <c>CompressionMode.Decompress</c>, the level parameter is ignored.
 /// </para>
 ///
 /// <para>
 ///   This constructor allows the application to request that the captive stream
 ///   remain open after the deflation or inflation occurs.  By default, after
 ///   <c>Close()</c> is called on the stream, the captive stream is also
 ///   closed. In some cases this is not desired, for example if the stream is a
 ///   <see cref="System.IO.MemoryStream"/> that will be re-read after
 ///   compression.  Specify true for the <paramref name="leaveOpen"/> parameter
 ///   to leave the stream open.
 /// </para>
 ///
 /// </remarks>
 ///
 /// <example>
 ///
 ///   This example shows how to use a <c>DeflateStream</c> to compress data from
 ///   a file, and store the compressed data into another file.
 ///
 /// <code>
 /// using (var output = System.IO.File.Create(fileToCompress + ".deflated"))
 /// {
 ///	 using (System.IO.Stream input = System.IO.File.Open(fileToCompress, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
 ///	 {
 ///		 using (Stream compressor = new DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, true))
 ///		 {
 ///			 byte[] buffer = new byte[WORKING_BUFFER_SIZE];
 ///			 int n= -1;
 ///			 while (n != 0)
 ///			 {
 ///				 if (n &gt; 0)
 ///					 compressor.Write(buffer, 0, n);
 ///				 n= input.Read(buffer, 0, buffer.Length);
 ///			 }
 ///		 }
 ///	 }
 ///	 // can write additional data to the output stream here
 /// }
 /// </code>
 ///
 /// <code lang="VB">
 /// Using output As FileStream = File.Create(fileToCompress &amp; ".deflated")
 ///	 Using input As Stream = File.Open(fileToCompress, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
 ///		 Using compressor As Stream = New DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, True)
 ///			 Dim buffer As Byte() = New Byte(4096) {}
 ///			 Dim n As Integer = -1
 ///			 Do While (n &lt;&gt; 0)
 ///				 If (n &gt; 0) Then
 ///					 compressor.Write(buffer, 0, n)
 ///				 End If
 ///				 n = input.Read(buffer, 0, buffer.Length)
 ///			 Loop
 ///		 End Using
 ///	 End Using
 ///	 ' can write additional data to the output stream here.
 /// End Using
 /// </code>
 /// </example>
 /// <param name="stream">The stream which will be read or written.</param>
 /// <param name="mode">Indicates whether the DeflateStream will compress or decompress.</param>
 /// <param name="leaveOpen">true if the application would like the stream to remain open after inflation/deflation.</param>
 /// <param name="level">A tuning knob to trade speed for effectiveness.</param>
 public DeflateStream(System.IO.Stream stream, CompressionMode mode, CompressionLevel level, bool leaveOpen)
 {
     _innerStream = stream;
     _baseStream  = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.DEFLATE, leaveOpen);
 }