本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# DeflaterOutputStream.Write方法的具体用法?C# DeflaterOutputStream.Write怎么用?C# DeflaterOutputStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream
的用法示例。
在下文中一共展示了DeflaterOutputStream.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: 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]);
}
}
示例3: 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;
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: 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);
}
示例11: 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());
}
示例12: 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();
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}
}