本文整理汇总了C#中Ionic.Zlib.ZlibStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# ZlibStream.Write方法的具体用法?C# ZlibStream.Write怎么用?C# ZlibStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zlib.ZlibStream
的用法示例。
在下文中一共展示了ZlibStream.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compress
/// <summary>
/// 지정된 데이타를 압축한다.
/// </summary>
/// <param name="input">압축할 Data</param>
/// <returns>압축된 Data</returns>
public override byte[] Compress(byte[] input) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressStartMsg);
// check input data
if(input.IsZeroLength()) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.InvalidInputDataMsg);
return CompressorTool.EmptyBytes;
}
byte[] output;
using(var outStream = new MemoryStream(input.Length)) {
using(var zlib = new ZlibStream(outStream, CompressionMode.Compress)) {
zlib.Write(input, 0, input.Length);
}
output = outStream.ToArray();
}
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);
return output;
}
示例2: Compress
public static byte[] Compress(byte[] input)
{
using (MemoryStream ms = new MemoryStream()) {
using (ZlibStream zls = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestSpeed)) {
zls.Write(input, 0, input.Length);
}
return ms.ToArray();
}
}
示例3: Compress
/// <summary>
/// Compress to CompressedData
/// </summary>
public static MemoryStream Compress(byte[] buffer)
{
var output = new MemoryStream();
using (ZlibStream zout = new ZlibStream(output, CompressionMode.Compress))
{
zout.Write(buffer, 0, buffer.Length);
zout.Flush();
}
return output;
}
示例4: Compress
internal static byte[] Compress(byte[] buffer)
{
using (var output = new MemoryStream())
{
using (Stream compressor = new ZlibStream(output, CompressionMode.Compress, CompressionLevel.BestCompression))
{
compressor.Write(buffer, 0, buffer.Length);
}
return output.ToArray();
}
}
示例5: ZibCompress
public static byte[] ZibCompress(byte[] input)
{
using (var ms = new System.IO.MemoryStream())
{
using (var zs = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, true))
{
zs.Write(input, 0, input.Length);
}
return ms.ToArray();
}
}
示例6: ZibCompress
public static UnmanagedMemory ZibCompress(byte[] input)
{
using (var ms = new TraderMemoryStream(500 * 1024))
{
using (var zs = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, true))
{
zs.Write(input, 0, input.Length);
}
return ms.Buffer;
}
}
示例7: CompressZlib
public static byte[] CompressZlib(byte[] bytes)
{
using (var ms = new MemoryStream())
{
using (var zip = new ZlibStream(ms, CompressionMode.Compress, true))
{
zip.Write(bytes, 0, bytes.Length);
}
return ms.ToArray();
}
}
示例8: ZlibDecompress
static byte[] ZlibDecompress(byte[] input, int length)
{
using (var ms = new System.IO.MemoryStream())
{
using (var compressor = new Ionic.Zlib.ZlibStream(ms, CompressionMode.Decompress, CompressionLevel.BestCompression))
{
compressor.Write(input, 0, length);
}
return ms.ToArray();
}
}
示例9: Decomp
public static void Decomp(byte[] input, Stream outputStream)
{
using (var zipStream = new ZlibStream(outputStream, CompressionMode.Decompress))
{
using (var inputStream = new MemoryStream(input))
{
byte[] buffer = input.Length > 4096 ? new byte[4096] : new byte[input.Length];
int size;
while ((size = inputStream.Read(buffer, 0, buffer.Length)) != 0)
zipStream.Write(buffer, 0, size);
}
}
}
示例10: Compress
public static byte[] Compress(this byte[] uncompressed, int level)
{
if (level == 0)
return uncompressed;
byte[] result;
using (var ms = new MemoryStream())
{
using (var compressor =
new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.Level0+level))
compressor.Write(uncompressed, 0, uncompressed.Length);
result = ms.ToArray();
}
// If compression did not improve the situation, then use
// uncompressed bytes.
if (result.Length >= uncompressed.Length)
return uncompressed;
return result;
}
示例11: SubmitBulkOperationsAsync
public void SubmitBulkOperationsAsync(string callingUrl, Guid sessionId, OPS operations, object userState)
{
MemoryStream operationsXml = null;
MemoryStream compressedOperationsStream = null;
ZlibStream zipStream = null;
try
{
operationsXml = new MemoryStream();
DataContractSerializer serializer = new DataContractSerializer(typeof(OPS));
serializer.WriteObject(operationsXml, operations);
byte[] operationsXmlBytes = operationsXml.ToArray();
compressedOperationsStream = new MemoryStream();
using (zipStream = new ZlibStream(compressedOperationsStream, CompressionMode.Compress))
{
zipStream.Write(operationsXmlBytes, 0, operationsXmlBytes.Length);
}
byte[] compressedOperationsXmlBytes = compressedOperationsStream.ToArray();
string compressedOperations = Convert.ToBase64String(compressedOperationsXmlBytes);
BOCAsync(callingUrl, sessionId, compressedOperations, userState);
}
finally
{
if (operationsXml != null)
{
operationsXml.Dispose();
operationsXml = null;
}
}
}
示例12: ZCompressOSD
public static OSD ZCompressOSD(OSD inOsd, bool useHeader)
{
OSD osd = null;
byte[] data = OSDParser.SerializeLLSDBinary(inOsd, useHeader);
using (MemoryStream msSinkCompressed = new MemoryStream())
{
using (Ionic.Zlib.ZlibStream zOut = new Ionic.Zlib.ZlibStream(msSinkCompressed,
Ionic.Zlib.CompressionMode.Compress, CompressionLevel.BestCompression, true))
{
zOut.Write(data, 0, data.Length);
}
msSinkCompressed.Seek(0L, SeekOrigin.Begin);
osd = OSD.FromBinary(msSinkCompressed.ToArray());
}
return osd;
}
示例13: AddSlot
public void AddSlot(slot cv_slot)
{
AddShort(cv_slot.s_short);
if(slot.IsGziped(cv_slot.s_short))
{
ZlibStream Compress = new ZlibStream(stream, CompressionMode.Compress);
Compress.Write(cv_slot.GZipData, 0, cv_slot.GZipData.Length);
}
}
示例14: Compress
/// <summary>
/// Compresses the specified data.
/// </summary>
/// <param name="data">The data.</param>
/// <param name="compressionLevel">The compression level.</param>
/// <returns></returns>
private static byte[] Compress(byte[] data, CompressionLevel compressionLevel = CompressionLevel.Default)
{
// While the CgBI PNG image data is compressed with Deflate, a "real" PNG must use Zlib.
using (var output = new MemoryStream())
{
using (var deflateStream = new ZlibStream(output, CompressionMode.Compress, compressionLevel, true))
{
deflateStream.Write(data, 0, data.Length);
}
return output.ToArray();
}
}
示例15: writeToStreamOld
private void writeToStreamOld(Stream s, bool le, bool readOnly)
{
bool compress = true;
bool base64 = true;
using (var tw = new StreamWriter(s, System.Text.Encoding.ASCII))
{
tw.NewLine = "\n";
tw.WriteLine("Type: Floppy");
if (readOnly)
tw.WriteLine("Access: Read-Only");
else
tw.WriteLine("Access: Read-Write");
if (le)
tw.WriteLine("Byte-Order: Little-Endian");
else
tw.WriteLine("Byte-Order: Big-Endian");
int lb = 0, hb = 1;
if (!le)
{
lb = 1;
hb = 0;
}
byte[] bytes, cbytes;
bytes = new byte[1440 * 1024];
for (int i = 0; i < _words.Length; ++i)
{
var j = 2 * i;
bytes[j + lb] = (byte)_words[i];
bytes[j + hb] = (byte)(_words[i] >> 8);
}
if (compress)
{
tw.WriteLine("Compression: Zlib");
using (var ms = new MemoryStream())
{
using (var cmpr = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, leaveOpen: true))
{
cmpr.Write(bytes, 0, bytes.Length);
cmpr.Flush();
}
cbytes = ms.ToArray();
}
}
else
{
tw.WriteLine("Compression: None");
cbytes = bytes;
}
if (base64)
{
var encoded = Convert.ToBase64String(cbytes, Base64FormattingOptions.InsertLineBreaks);
tw.WriteLine("Encoding: Base64");
tw.WriteLine("Content-Length: {0}", encoded.Length);
tw.WriteLine();
tw.WriteLine(encoded);
}
else
{
tw.WriteLine("Encoding: None");
tw.WriteLine("Content-Length: {0}", cbytes.Length);
tw.WriteLine();
tw.Flush();
tw.BaseStream.Write(bytes, 0, cbytes.Length);
}
}
}