当前位置: 首页>>代码示例>>C#>>正文


C# CompressionLevel类代码示例

本文整理汇总了C#中CompressionLevel的典型用法代码示例。如果您正苦于以下问题:C# CompressionLevel类的具体用法?C# CompressionLevel怎么用?C# CompressionLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CompressionLevel类属于命名空间,在下文中一共展示了CompressionLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateEntryFromFile

		public static ZipArchiveEntry CreateEntryFromFile (
			this ZipArchive destination, string sourceFileName,
			string entryName, CompressionLevel compressionLevel
			)
		{
			throw new NotImplementedException ();
		}
开发者ID:frje,项目名称:SharpLang,代码行数:7,代码来源:ZipFileExtensions.cs

示例2: Save

        /// <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);
        }
开发者ID:mstum,项目名称:Simplexcel,代码行数:30,代码来源:XlsxWriter.cs

示例3: ZlibBaseStream

 public ZlibBaseStream(System.IO.Stream stream,
                       CompressionMode compressionMode,
                       CompressionLevel level,
                       ZlibStreamFlavor flavor,
                       bool leaveOpen)
     :this(stream, compressionMode, level, flavor,leaveOpen, ZlibConstants.WindowBitsDefault)
 { }
开发者ID:JohnMalmsteen,项目名称:mobile-apps-tower-defense,代码行数:7,代码来源:ZlibBaseStream.cs

示例4: zlibDeflate

 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();
     }
 }
开发者ID:alejandro-varela,项目名称:AleNet,代码行数:28,代码来源:ZlibHelper.cs

示例5: Test_Compress

        // 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);
                }
            }
        }
开发者ID:labeuze,项目名称:source,代码行数:38,代码来源:Test_SharpCompressManager.cs

示例6: DeflateManagedStream

        // Implies mode = Compress
        public DeflateManagedStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen)
        {
            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            InitializeDeflater(stream, leaveOpen, compressionLevel);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:DeflateManagedStream.cs

示例7: DoCreateFromDirectory

        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 + '\\');
                    }
                }
            }
        }
开发者ID:mqmanpsy,项目名称:MetroLog,代码行数:25,代码来源:ZipFile.cs

示例8: CreateEntryFromFolder

        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;
        }
开发者ID:rzhw,项目名称:MoreZipFileExtensions,代码行数:34,代码来源:MoreZipFileExtensions.cs

示例9: SetLevel

        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);
        }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:34,代码来源:SevenZipPropertiesBuilder.cs

示例10: DeflateStream

        /// <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);
        }
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:10,代码来源:DeflateStream.cs

示例11: Compress

        /// <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 );
        }
开发者ID:Kudach,项目名称:QuickIO,代码行数:17,代码来源:QuickIODirectory_Compress.cs

示例12: Packer

 public Packer(string path, FileStream fs, CompressionLevel level)
 {
     _path = path.TrimEnd('\\') + "\\";
     _pathPrefixLength = _path.Length;
     _fs = fs;
     _level = level;
 }
开发者ID:AndrewSav,项目名称:ReisUnpack,代码行数:7,代码来源:Packer.cs

示例13: ZOutputStream

 public ZOutputStream(Stream output, CompressionLevel level, bool nowrap)
     : this()
 {
     this._output = output;
     this._compressor = new Deflate(level, nowrap);
     this._compressionMode = CompressionMode.Compress;
 }
开发者ID:imbavirus,项目名称:TrinityCoreAdmin,代码行数:7,代码来源:ZOutputStream.cs

示例14: Compress_Canterbury

 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]);
     }
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:27,代码来源:Perf.GZipStream.cs

示例15: Deflater

        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);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:33,代码来源:Deflater.cs


注:本文中的CompressionLevel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。