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


C# Deflater.Reset方法代码示例

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


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

示例1: Compress

        private const int CopyBufferSize = 32*1024;    // 32kb

        public void Compress(Stream source, Stream destination)
        {
            /*
            var deflater = new DeflaterOutputStream(destination, new Deflater(Deflater.DEFAULT_COMPRESSION, true));

            var dataBuffer = new byte[CopyBufferSize];
            StreamUtils.Copy(source, deflater, dataBuffer);
             */

            var def = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
            
            var inputData = new byte[source.Length - source.Position];
            source.Read(inputData, 0, inputData.Length);

            var buffer = new byte[CopyBufferSize];

            def.SetInput( inputData, 0, inputData.Length );
            def.Finish();

            while(!def.IsFinished)
            {
                int outputLen = def.Deflate(buffer, 0, buffer.Length);
                destination.Write( buffer, 0, outputLen );
            }

            def.Reset();
        }
开发者ID:tjhorner,项目名称:gtaivtools,代码行数:29,代码来源:CompressionDeflateCodec.cs

示例2: Compress

        public void Compress()
        {
            var deflater = new Deflater();
            byte[] packet = PacketData;
            deflater.SetInput(packet, 0, packet.Length);
            deflater.Finish();

            var compBuffer = new byte[1024];
            var ret = new List<byte>();

            while (!deflater.IsFinished)
            {
                try
                {
                    deflater.Deflate(compBuffer);
                    ret.AddRange(compBuffer);
                    Array.Clear(compBuffer, 0, compBuffer.Length);
                }
                catch (Exception ex)
                {
                    return;
                }
            }
            deflater.Reset();

            Seek((byte)_headerType, SeekOrigin.Begin);
            // Write the compressed bytes over whatever is there.
            Write(ret.ToArray());
            // Set the stream length to the end of the actual packet data.
            // This makes sure we don't have any 'junk' packets at the end.
            OutStream.SetLength(BaseStream.Position);
        }
开发者ID:Refuge89,项目名称:Vanilla,代码行数:32,代码来源:PacketWriter.cs

示例3: WriteWhole

        private void WriteWhole(Deflater def, int typeCode, byte[] data)
        {
            int sz = data.Length;
            int hdrlen = 0;
            _buffer[hdrlen++] = (byte)((typeCode << 4) | sz & 15);
            sz = (int)(((uint)sz) >> 4);

            while (sz > 0)
            {
                _buffer[hdrlen - 1] |= 0x80;
                _buffer[hdrlen++] = (byte)(sz & 0x7f);
                sz = (int)(((uint)sz) >> 7);
            }

            _packDigest.Update(_buffer, 0, hdrlen);
            _crc.Update(_buffer, 0, hdrlen);
            _packOut.Write(_buffer, 0, hdrlen);
            def.Reset();
            def.SetInput(data);
            def.Finish();

            while (!def.IsFinished)
            {
                int datlen = def.Deflate(_buffer);
                _packDigest.Update(_buffer, 0, datlen);
                _crc.Update(_buffer, 0, datlen);
                _packOut.Write(_buffer, 0, datlen);
            }
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:29,代码来源:IndexPack.cs

示例4: Deflate

        // make string smaller (or try it at least ;)
        public string Deflate(string input)
        {
            byte[] inputData = Convert.FromBase64String(input);
            Deflater deflater = new Deflater(Deflater.BEST_SPEED, false);
            deflater.SetInput(inputData);
            deflater.Finish();

            using (var ms = new MemoryStream())
            {
                var outputBuffer = new byte[65536 * 4];
                while (deflater.IsNeedingInput == false)
                {
                    var read = deflater.Deflate(outputBuffer);
                    ms.Write(outputBuffer, 0, read);

                    if (deflater.IsFinished == true)
                        break;
                }

                deflater.Reset();

                return Convert.ToBase64String( ms.ToArray());
            }
        }
开发者ID:noHero123,项目名称:guildchat.mod,代码行数:25,代码来源:Cryptomat.cs

示例5: WriteWhole

		/// <exception cref="System.IO.IOException"></exception>
		private void WriteWhole(Deflater def, int typeCode, byte[] data)
		{
			int sz = data.Length;
			int hdrlen = 0;
			buf[hdrlen++] = unchecked((byte)((typeCode << 4) | sz & 15));
			sz = (int)(((uint)sz) >> 4);
			while (sz > 0)
			{
				buf[hdrlen - 1] |= unchecked((int)(0x80));
				buf[hdrlen++] = unchecked((byte)(sz & unchecked((int)(0x7f))));
				sz = (int)(((uint)sz) >> 7);
			}
			packDigest.Update(buf, 0, hdrlen);
			crc.Update(buf, 0, hdrlen);
			packOut.Write(buf, 0, hdrlen);
			def.Reset();
			def.SetInput(data);
			def.Finish();
			while (!def.IsFinished)
			{
				int datlen = def.Deflate(buf);
				packDigest.Update(buf, 0, datlen);
				crc.Update(buf, 0, datlen);
				packOut.Write(buf, 0, datlen);
			}
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:27,代码来源:IndexPack.cs


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