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

C# Streams.DeflaterOutputStream类代码示例

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

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



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

示例1: CloseDeflatorWithNestedUsing

        public void CloseDeflatorWithNestedUsing()
        {
            string tempFile = null;
            try
            {
                tempFile = Path.GetTempPath();
            }
            catch (SecurityException)
            {
            }

            Assert.IsNotNull(tempFile, "No permission to execute this test?");
            if (tempFile != null)
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                using (FileStream diskFile = File.Create(tempFile))
                using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
                using (StreamWriter txtFile = new StreamWriter(deflator))
                {
                    txtFile.Write("Hello");
                    txtFile.Flush();
                }

                File.Delete(tempFile);
            }
        }
开发者ID:danygolden,项目名称:gianfratti,代码行数:26,代码来源:InflaterDeflaterTests.cs


示例2: CompressString

        /// <summary>
        /// Compresses a string.
        /// </summary>
        /// <param name="value">The string to compress.</param>
        /// <returns>The compressed string.</returns>
        public string CompressString(string value)
        {
            // The input value must be non-null
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var outputData = string.Empty;
            var inputData = UTF8Encoding.UTF8.GetBytes(value);
            using (var inputStream = new MemoryStream(inputData))
            {
                using (var outputStream = new MemoryStream())
                {
                    // Zip the string
                    using (var zipStream = new DeflaterOutputStream(outputStream))
                    {
                        zipStream.IsStreamOwner = false;
                        StreamUtils.Copy(inputStream, zipStream, new byte[4096]);
                    }

                    // Convert to a string
                    outputData = Convert.ToBase64String(outputStream.GetBuffer(), 0, Convert.ToInt32(outputStream.Length));
                }
            }

            // Return the compressed string
            return outputData;
        }
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:34,代码来源:ZipCompressionService.cs


示例3: Compress

        public byte[] Compress(byte[] bytData, params int[] ratio)
        {
            int compRatio = 9;
            try
            {
                if (ratio[0] > 0)

                {
                    compRatio = ratio[0];
                }
            }
            catch
            {
                throw;
            }

            try
            {
                var ms = new MemoryStream();
                var defl = new Deflater(compRatio, false);
                Stream s = new DeflaterOutputStream(ms, defl);
                s.Write(bytData, 0, bytData.Length);
                s.Close();
                byte[] compressedData = ms.ToArray();
                 return compressedData;
            }
            catch
            {
                throw;

            }
        }
开发者ID:jojozhuang,项目名称:Study,代码行数:32,代码来源:Wrapper.cs


示例4: Compress

		// netz.compress.ICompress implementation

		public long Compress(string file, string zipFile)
		{
			long length = -1;
			FileStream ifs = null;
			FileStream ofs = null;
			try
			{
				ifs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
				ofs = File.Open(zipFile, FileMode.Create, FileAccess.Write, FileShare.None);
				DeflaterOutputStream dos = new DeflaterOutputStream(ofs, new Deflater(Deflater.BEST_COMPRESSION));
				byte[] buff = new byte[ifs.Length];
				while(true)
				{
					int r = ifs.Read(buff, 0, buff.Length);
					if(r <= 0) break;
					dos.Write(buff, 0, r);
				}
				dos.Flush();
				dos.Finish();
				length = dos.Length;
				dos.Close();
			}
			finally
			{
				if(ifs != null) ifs.Close();
				if(ofs != null) ofs.Close();
			}
			return length;
		}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-msnet-netz-compressor-madebits,代码行数:31,代码来源:defcomp.cs


示例5: TestInflateDeflate

        public void TestInflateDeflate()
        {
            MemoryStream ms = new MemoryStream();
            Deflater deflater = new Deflater(6);
            DeflaterOutputStream outStream = new DeflaterOutputStream(ms, deflater);

            byte[] buf = new byte[1000000];
            System.Random rnd = new Random();
            rnd.NextBytes(buf);

            outStream.Write(buf, 0, buf.Length);
            outStream.Flush();
            outStream.Finish();

            ms.Seek(0, SeekOrigin.Begin);

            InflaterInputStream inStream = new InflaterInputStream(ms);
            byte[] buf2 = new byte[buf.Length];
            int    pos  = 0;
            while (true) {
                int numRead = inStream.Read(buf2, pos, 4096);
                if (numRead <= 0) {
                    break;
                }
                pos += numRead;
            }

            for (int i = 0; i < buf.Length; ++i) {
                Assertion.AssertEquals(buf2[i], buf[i]);
            }
        }
开发者ID:wuzhen,项目名称:SwfDecompiler,代码行数:31,代码来源:InflaterDeflaterTests.cs


示例6: CloseInflatorWithNestedUsing

        public void CloseInflatorWithNestedUsing()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string tempFile = Environment.TickCount.ToString();
                store.CreateDirectory(tempFile);

                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                using (IsolatedStorageFileStream diskFile = store.CreateFile(tempFile))
                using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
                using (StreamWriter textWriter = new StreamWriter(deflator))
                {
                    textWriter.Write("Hello");
                    textWriter.Flush();
                }

                using (IsolatedStorageFileStream diskFile = store.OpenFile(tempFile, FileMode.Open))
                using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
                using (StreamReader textReader = new StreamReader(deflator))
                {
                    char[] buffer = new char[5];
                    int readCount = textReader.Read(buffer, 0, 5);
                    Assert.AreEqual(5, readCount);

                    StringBuilder b = new StringBuilder();
                    b.Append(buffer);
                    Assert.AreEqual("Hello", b.ToString());

                }

                store.CreateFile(tempFile);
            }
        }
开发者ID:rollingthunder,项目名称:slsharpziplib,代码行数:33,代码来源:InflaterDeflaterTestSuite_FileSystem.cs


示例7: CloseInflatorWithNestedUsing

        public void CloseInflatorWithNestedUsing()
        {
            string tempFile = null;
            try {
                tempFile = Path.GetTempPath();
            } catch (SecurityException) {
            }

            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
            using (FileStream diskFile = File.Create(tempFile))
            using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
            using (StreamWriter textWriter = new StreamWriter(deflator)) {
                textWriter.Write("Hello");
                textWriter.Flush();
            }

            using (FileStream diskFile = File.OpenRead(tempFile))
            using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
            using (StreamReader textReader = new StreamReader(deflator)) {
                char[] buffer = new char[5];
                int readCount = textReader.Read(buffer, 0, 5);
                Assert.AreEqual(5, readCount);

                var b = new StringBuilder();
                b.Append(buffer);
                Assert.AreEqual("Hello", b.ToString());

            }

            File.Delete(tempFile);
        }
开发者ID:Zo0pZ,项目名称:SharpZipLib,代码行数:33,代码来源:InflaterDeflaterTests.cs


示例8: Compress

 public static byte[] Compress(byte[] Data)
 {
     MemoryStream ms = new MemoryStream();
     Stream s = new DeflaterOutputStream(ms);
     s.Write(Data, 0, Data.Length);
     s.Close();
     return ms.ToArray();
 }
开发者ID:remixod,项目名称:NetLibClient,代码行数:8,代码来源:Compression.cs


示例9: Deflate

 internal static byte[] Deflate(byte[] buffer)
 {
     MemoryStream compressedBufferStream = new MemoryStream();
     DeflaterOutputStream deflaterStream = new DeflaterOutputStream(compressedBufferStream);
     deflaterStream.Write(buffer, 0, buffer.Length);
     deflaterStream.Close();
     return compressedBufferStream.ToArray();
 }
开发者ID:kkkkyue,项目名称:FtexTool,代码行数:8,代码来源:ZipUtility.cs


示例10: ZlibOutputStreamIs

 public ZlibOutputStreamIs(Stream st, int compressLevel, EDeflateCompressStrategy strat, bool leaveOpen)
     : base(st,compressLevel,strat,leaveOpen)
 {
     deflater=new Deflater(compressLevel);
     setStrat(strat);
     ost = new DeflaterOutputStream(st, deflater);
     ost.IsStreamOwner = !leaveOpen;
 }
开发者ID:NoobsArePeople2,项目名称:pngcs,代码行数:8,代码来源:ZlibOutputStreamIs.cs


示例11: Compress

 public static byte[] Compress(byte[] bytes)
 {
     MemoryStream memory = new MemoryStream();
     DeflaterOutputStream stream = new DeflaterOutputStream(memory, new Deflater(Deflater.BEST_COMPRESSION), 131072);
     stream.Write(bytes, 0, bytes.Length);
     stream.Close();
     return memory.ToArray();
 }
开发者ID:mex868,项目名称:Nissi.Solution,代码行数:8,代码来源:Zip.cs


示例12: CompressZlib

 public static byte[] CompressZlib(byte[] input)
 {
     MemoryStream m = new MemoryStream();
     DeflaterOutputStream zipStream = new DeflaterOutputStream(m, new ICSharpCode.SharpZipLib.Zip.Compression.Deflater(8));
     zipStream.Write(input, 0, input.Length);
     zipStream.Finish();
     return m.ToArray();
 }
开发者ID:zeroKilo,项目名称:Zlibber,代码行数:8,代码来源:Form1.cs


示例13: Compress

 public byte[] Compress( byte[] bytes )
 {
     MemoryStream memory = new MemoryStream();
     Stream stream = new DeflaterOutputStream( memory,
         new ICSharpCode.SharpZipLib.Zip.Compression.Deflater(
         ICSharpCode.SharpZipLib.Zip.Compression.Deflater.BEST_COMPRESSION ), 131072 );
     stream.Write( bytes, 0, bytes.Length );
     stream.Close();
     return memory.ToArray();
 }
开发者ID:popovegor,项目名称:gt,代码行数:10,代码来源:GTCommonWebPage.cs


示例14: Encode

        public override byte[] Encode(byte[] data)
        {
            var o = new MemoryStream();

            var compressed = new DeflaterOutputStream(o, new Deflater(1));
            compressed.Write(data, 0, data.Length);
            compressed.Flush();
            compressed.Close();

            return o.ToArray();
        }
开发者ID:ademar,项目名称:melon-reports,代码行数:11,代码来源:FlateFilter.cs


示例15: Compress

        public string Compress(string uncompressedString)
        {
            var stringAsBytes = Encoding.UTF8.GetBytes(uncompressedString);
            var ms = new MemoryStream();
            var outputStream = new DeflaterOutputStream(ms);
            outputStream.Write(stringAsBytes, 0, stringAsBytes.Length);
            outputStream.Close();
            var compressedData = ms.ToArray();

            return Convert.ToBase64String(compressedData, 0, compressedData.Length);
        }
开发者ID:benaston,项目名称:NCacheFacade,代码行数:11,代码来源:SharpZipStringCompressor.cs


示例16: Compress

        /// <summary>
        /// Compress an array of bytes.
        /// </summary>
        /// <param name="_pBytes">An array of bytes to be compressed.</param>
        /// <returns>Compressed bytes.</returns>
        /// <example>
        /// Following example demonstrates the way of compressing an ASCII string text.
        /// <code>
        /// public void Compress()
        /// {
        ///     string source = "Hello, world!";
        ///     byte[] source_bytes = System.Text.Encoding.ASCII.GetBytes(source);
        ///     byte[] compressed = DataCompression.Compress(source_bytes);
        ///     
        ///     // Process the compressed bytes here.
        /// }
        /// </code>
        /// </example>
        /// <remarks>It is the best practice that use the overrided <b>DataCompression.Compress</b> method with <see cref="System.String"/> parameter to compress a string.</remarks>
        public static byte[] Compress(byte[] _pBytes)
        {
            MemoryStream ms = new MemoryStream();

            Deflater mDeflater = new Deflater(Deflater.BEST_COMPRESSION);
            DeflaterOutputStream outputStream = new DeflaterOutputStream(ms, mDeflater, 131072);

            outputStream.Write(_pBytes, 0, _pBytes.Length);
            outputStream.Close();

            return ms.ToArray();
        }
开发者ID:daxnet,项目名称:guluwin,代码行数:31,代码来源:DataCompression.cs


示例17: Compress

 /// <summary>
 /// Compress the specified data.
 /// </summary>
 /// <param name='data'>
 /// Data.
 /// </param>
 static string Compress(byte[] data)
 {
     MemoryStream ms = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(ms);
     DeflaterOutputStream zs = new DeflaterOutputStream(ms);
     bw.Write(data.Length);
     zs.Write(data,0,data.Length);
     zs.Flush();
     zs.Close ();
     bw.Close();
     return "ZipStream:" + Convert.ToBase64String(ms.GetBuffer());
 }
开发者ID:zombiepaladin,项目名称:CI-Team,代码行数:18,代码来源:BS.cs


示例18: Compress

        public static byte[] Compress(byte[] data)
        {
            byte[] result = null;

            using (MemoryStream ms = new MemoryStream())
                using (Stream s = new DeflaterOutputStream(ms))
                {
                    s.Write(data, 0, data.Length);
                    s.Close();
                    result = ms.ToArray();
                }

            return result;
        }
开发者ID:hollow87,项目名称:Arca4,代码行数:14,代码来源:ZipLib.cs


示例19: Deflate

		MemoryStream Deflate(byte[] data, int level, bool zlib)
		{
			MemoryStream memoryStream = new MemoryStream();
			
			Deflater deflater = new Deflater(level, !zlib);
			using ( DeflaterOutputStream outStream = new DeflaterOutputStream(memoryStream, deflater) )
			{
				outStream.IsStreamOwner = false;
				outStream.Write(data, 0, data.Length);
				outStream.Flush();
				outStream.Finish();
			}
			return memoryStream;
		}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:14,代码来源:InflaterDeflaterTests.cs


示例20: Deflate

		internal static Byte[] Deflate(Byte[] b)
		{
			System.IO.MemoryStream ms = new System.IO.MemoryStream();
			DeflaterOutputStream outStream =new DeflaterOutputStream( ms);
			
			outStream.Write(b, 0, b.Length);
			outStream.Flush();
			outStream.Finish();
			
			Byte[] result=ms.ToArray();
			outStream.Close();
			ms.Close();
			return result;
		}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:14,代码来源:Utility.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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