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