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


C# Deflater.SetLevel方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.Compression.Deflater.SetLevel方法的典型用法代码示例。如果您正苦于以下问题:C# Deflater.SetLevel方法的具体用法?C# Deflater.SetLevel怎么用?C# Deflater.SetLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Zip.Compression.Deflater的用法示例。


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

示例1: Compress

        public byte[] Compress(byte[] input)
        {
            // Create the compressor with highest level of compression
            Deflater compressor = new Deflater();
            compressor.SetLevel(Deflater.BEST_COMPRESSION);

            // Give the compressor the data to compress
            compressor.SetInput(input);
            compressor.Finish();

            /*
             * Create an expandable byte array to hold the compressed data.
             * You cannot use an array that's the same size as the orginal because
             * there is no guarantee that the compressed data will be smaller than
             * the uncompressed data.
             */
            MemoryStream bos = new MemoryStream(input.Length);

            // Compress the data
            byte[] buf = new byte[1024];
            while (!compressor.IsFinished)
            {
                int count = compressor.Deflate(buf);
                bos.Write(buf, 0, count);
            }

            // Get the compressed data
            return bos.ToArray();
        }
开发者ID:zweib730,项目名称:beagrep,代码行数:29,代码来源:SharpZipLibAdapter.cs

示例2: Compress

        /// <summary>Compresses the specified byte range using the
        /// specified compressionLevel (constants are defined in
        /// java.util.zip.Deflater). 
        /// </summary>
        public static byte[] Compress(byte[] value_Renamed, int offset, int length, int compressionLevel)
        {
            /* Create an expandable byte array to hold the compressed data.
            * You cannot use an array that's the same size as the orginal because
            * there is no guarantee that the compressed data will be smaller than
            * the uncompressed data. */
            System.IO.MemoryStream bos = new System.IO.MemoryStream(length);

            Deflater compressor = new Deflater();

            try
            {
                compressor.SetLevel(compressionLevel);
                compressor.SetInput(value_Renamed, offset, length);
                compressor.Finish();

                // Compress the data
                byte[] buf = new byte[1024];
                while (!compressor.IsFinished)
                {
                    int count = compressor.Deflate(buf);
                    bos.Write(buf, 0, count);
                }
            }
            finally
            {
            }

            return bos.ToArray();
        }
开发者ID:BackupTheBerlios,项目名称:lyra2-svn,代码行数:34,代码来源:CompressionTools.cs

示例3: Compress

		public static byte[] Compress(byte[] content)
		{
			//return content;
			Deflater compressor = new Deflater();
			compressor.SetLevel(Deflater.BEST_COMPRESSION);

			compressor.SetInput(content);
			compressor.Finish();

			using (MemoryStream bos = new MemoryStream(content.Length))
			{
				var buf = new byte[1024];
				while (!compressor.IsFinished)
				{
					int n = compressor.Deflate(buf);
					bos.Write(buf, 0, n);
				}
				return bos.ToArray();
			}
		}
开发者ID:egametang,项目名称:Egametang,代码行数:20,代码来源:ZipHelper.cs

示例4: ZipBytes

 public static byte[] ZipBytes(byte[] input)
 {
     MemoryStream ms = new MemoryStream();
     Deflater zipper = new Deflater();
     zipper.SetLevel(5);
     Stream st = new DeflaterOutputStream(ms, zipper);
     st.Write(input, 0, input.Length);
     st.Flush();
     st.Close();
     byte[] result = (byte[])ms.ToArray();
     return result;
 }
开发者ID:Hamsand,项目名称:Swf2XNA,代码行数:12,代码来源:SwfWriter.cs


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