本文整理汇总了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();
}
示例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);
}
示例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);
}
}
示例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());
}
}
示例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);
}
}