本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.Compression.Deflater类的典型用法代码示例。如果您正苦于以下问题:C# Deflater类的具体用法?C# Deflater怎么用?C# Deflater使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Deflater类属于ICSharpCode.SharpZipLib.Zip.Compression命名空间,在下文中一共展示了Deflater类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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
示例2: ChunkDataPacket
public ChunkDataPacket()
{
if (zLibDeflater == null)
zLibDeflater = new Deflater(CompressionLevel);
if (LockObject == null)
LockObject = new object();
}
开发者ID:keneo,项目名称:Craft.Net,代码行数:7,代码来源:ChunkDataPacket.cs
示例3: 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
示例4: 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
示例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: 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
示例7: Compress
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public byte[] Compress(Stream input)
{
String s = String.Format("Compressing output with level {0:d}", CompressionLevel);
//Log.Debug(this, s);
Deflater deflater = new Deflater(CompressionLevel, false);
byte[] uncompressedData = new byte[(Int32)input.Length];
input.Seek(0, SeekOrigin.Begin);
input.Read(uncompressedData, 0, uncompressedData.Length);
byte[] buffer = new byte[input.Length];
try
{
deflater.SetInput(uncompressedData);
deflater.Finish();
int bytesDeflated = deflater.Deflate(buffer, 0, buffer.Length);
byte[] compressedData = new byte[bytesDeflated];
Array.Copy(buffer, compressedData, bytesDeflated);
//Log.Debug(this, "Compression completed.");
return compressedData;
}
catch (Exception e)
{
Log.Error(this, e);
throw e;
}
}
开发者ID:rtezli,项目名称:Blitzableiter,代码行数:35,代码来源:CwsFile.cs
示例8: Compress
public static byte[] Compress(string str)
{
byte[] bytes = Encoding.Unicode.GetBytes(str);
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
deflater.SetInput(bytes);
deflater.Finish();
MemoryStream stream = new MemoryStream(bytes.Length);
try
{
byte[] output = new byte[0x400];
while (!deflater.IsFinished)
{
int count = deflater.Deflate(output);
stream.Write(output, 0, count);
}
}
finally
{
stream.Close();
}
byte[] buffer3 = stream.ToArray();
if ((buffer3.Length % 2) == 0)
{
return buffer3;
}
byte[] buffer4 = new byte[buffer3.Length + 1];
for (int i = 0; i < buffer3.Length; i++)
{
buffer4[i] = buffer3[i];
}
buffer4[buffer3.Length] = 0;
return buffer4;
}
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:33,代码来源:_String.cs
示例9: IOCompress
public static void IOCompress(byte[] input, int len, byte[] output, out int deflatedLength)
{
Deflater item = new Deflater();
item.SetInput(input, 0, len);
item.Finish();
deflatedLength = item.Deflate(output, 0, output.Length);
}
开发者ID:Pepsee,项目名称:WCell.SpecialTools,代码行数:7,代码来源:ZLib.cs
示例10: 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
示例11: ObjectWriter
/// <summary>
/// Construct an object writer for the specified repository.
/// </summary>
/// <param name="repo"> </param>
public ObjectWriter(Repository repo)
{
_r = repo;
_buf = new byte[0x2000];
_md = new MessageDigest();
_def = new Deflater(_r.Config.getCore().getCompression());
}
开发者ID:drothmaler,项目名称:GitSharp,代码行数:11,代码来源:ObjectWriter.cs
示例12: ObjectWriter
public ObjectWriter(Repository repo)
{
this.r = repo;
buf = new byte[8192];
md = new MessageDigest(); // [henon] Sha1 hash digest generator
def = new Deflater(r.Config.Core.Compression);
}
开发者ID:ArildF,项目名称:GitSharp,代码行数:7,代码来源:ObjectWriter.cs
示例13: CompressZLib
/// <summary>
/// Performs deflate compression on the given data.
/// </summary>
/// <param name="input">the data to compress</param>
/// <param name="output">the compressed data</param>
public static void CompressZLib(byte[] input, byte[] output, int compressionLevel, out int deflatedLength)
{
Deflater item = new Deflater(compressionLevel);
item.SetInput(input, 0, input.Length);
item.Finish();
deflatedLength = item.Deflate(output, 0, output.Length);
}
开发者ID:KroneckerX,项目名称:WCell,代码行数:13,代码来源:Compression.cs
示例14: ZlibStream
public ZlibStream(Stream inner, Inflater inflater, int buffSize)
{
_innerStream = inner;
_in = inflater;
_inBuff = new byte[buffSize];
_outBuff = _inBuff;
_out = new Deflater();
}
开发者ID:nickwhaley,项目名称:ubiety,代码行数:8,代码来源:ZlibStream.cs
示例15: 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
示例16: 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
示例17: Serialize
public static void Serialize(Stream stream, PiaFile piaFile)
{
if (stream == null)
throw new ArgumentNullException("Stream");
if (piaFile == null)
throw new ArgumentNullException("PiaFile");
try
{
// Header
var headerString = piaFile.Header.ToString();
var headerBytes = Encoding.Default.GetBytes(headerString);
stream.Write(headerBytes, 0, headerBytes.Length);
// Nodes
var nodeString = _serializeNode(piaFile);
var nodeBytes = Encoding.Default.GetBytes(nodeString);
// Deflation
byte[] deflatedBytes;
var deflater = new Deflater(Deflater.DEFAULT_COMPRESSION);
using (var ms = new MemoryStream())
{
var deflateStream = new DeflaterOutputStream(ms, deflater);
deflateStream.Write(nodeBytes, 0, nodeBytes.Length);
deflateStream.Finish();
deflatedBytes = ms.ToArray();
}
// Checksum
var checkSum = new byte[12];
BitConverter.GetBytes(deflater.Adler).CopyTo(checkSum, 0); // Adler
BitConverter.GetBytes(nodeBytes.Length).CopyTo(checkSum, 4); // InflatedSize
BitConverter.GetBytes(deflatedBytes.Length).CopyTo(checkSum, 8); // DeflatedSize
stream.Write(checkSum, 0, checkSum.Length);
// Final write
stream.Write(deflatedBytes, 0, deflatedBytes.Length);
}
catch (Exception)
{
throw;
}
}
开发者ID:phusband,项目名称:PiaNO,代码行数:46,代码来源:PiaSerializer.cs
示例18: SendTo
/// <summary>
/// Sends packet (might be compressed)
/// </summary>
/// <returns></returns>
public void SendTo(IRealmClient client)
{
if (TotalLength <= WCellDef.MAX_UNCOMPRESSED_UPDATE_PACKET)
{
client.Send(GetFinalizedPacket());
}
else
{
var segment = ((SegmentStream)BaseStream).Segment;
//var input = ((MemoryStream)BaseStream).ToArray();
var inputOffset = HeaderSize;
//Compression.CompressZLib(packetBuffer, outputBuffer, RealmServer.Instance.Configuration.CompressionLevel, out deflatedLength);
var length = ContentLength;
if (length > 0x7FFF)
{
log.Warn("Sent UpdatePacket with Length {0} to {1} in {2}", length, client,
client.ActiveCharacter.Zone as IWorldSpace ?? client.ActiveCharacter.Region);
}
var maxOutputLength = length + FullUpdatePacketHeaderSize;
var outSegment = BufferManager.GetSegment(maxOutputLength);
var deflater = new Deflater(RealmServerConfiguration.CompressionLevel);
deflater.SetInput(segment.Buffer.Array, segment.Offset + inputOffset, length);
//deflater.SetInput(input, 0 + inputOffset, length);
deflater.Finish();
int deflatedLength = deflater.Deflate(outSegment.Buffer.Array,
outSegment.Offset + FullUpdatePacketHeaderSize, length);
var totalLength = deflatedLength + FullUpdatePacketHeaderSize;
if (totalLength > MaxPacketSize)
{
//TODO: Split up packet if packet size exceeds max length
throw new Exception("Compressed Update packet exceeded max length: " + totalLength);
}
SendPacket(client, outSegment, totalLength, length);
outSegment.DecrementUsage();
}
}
开发者ID:pallmall,项目名称:WCell,代码行数:47,代码来源:UpdatePacket.cs
示例19: Compress
public static byte[] Compress(byte[] input, int level)
{
byte[] bytesOut;
byte[] temp = new byte[input.Length];
Deflater deflater = new Deflater(level, true);
try
{
deflater.SetInput(input, 0, input.Length);
deflater.Finish();
bytesOut = new byte[deflater.Deflate(temp)];
}
catch (Exception e)
{
throw e;
}
Array.Copy(temp, 0, bytesOut, 0, bytesOut.Length);
return bytesOut;
}
开发者ID:reditec,项目名称:RDR-Explorer,代码行数:20,代码来源:DataUtil.cs
示例20: 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
注:本文中的ICSharpCode.SharpZipLib.Zip.Compression.Deflater类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论