• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CompressionLevel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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 )
        {
            Contract.Requires( directory != null );
            Contract.Requires( !String.IsNullOrWhiteSpace( zipFullPath ) );

            Compress( directory.FullName, zipFullPath, overWriteExistingZip, compressionLevel, includeBaseDirectory );
        }
开发者ID:Invisibility,项目名称:QuickIO,代码行数:17,代码来源:QuickIODirectory.Compress.cs


示例17: CreateFromDirectory

		public static void CreateFromDirectory (
			string sourceDirectoryName, string destinationArchiveFileName,
			CompressionLevel compressionLevel, bool includeBaseDirectory)
		{
			CreateFromDirectory (sourceDirectoryName, destinationArchiveFileName,
				compressionLevel, includeBaseDirectory, Encoding.UTF8);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:ZipFile.cs


示例18: CreateEntryFromFile

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


示例19: Compress

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


示例20: UpdateTarget

        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();
        }
开发者ID:Spanfile,项目名称:Backup-Utility-V2,代码行数:30,代码来源:Backup.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CompressionMethod类代码示例发布时间:2022-05-24
下一篇:
C# Compression类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap