本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DeflaterOutputStream.Close方法的具体用法?C# DeflaterOutputStream.Close怎么用?C# DeflaterOutputStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream
的用法示例。
在下文中一共展示了DeflaterOutputStream.Close方法的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: 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;
}
示例3: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: 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);
}
示例9: 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();
}
示例10: 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;
}
示例11: 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;
}
示例12: Compress
public static string Compress(byte[] data)
{
using(var m = new MemoryStream())
{
switch(technique)
{
case "ZipStream":
var br = new BinaryWriter(m);
var z = new DeflaterOutputStream(m);
br.Write(data.Length);
z.Write(data, 0, data.Length);
z.Flush();
z.Close();
break;
}
return technique + ":" + Convert.ToBase64String(m.GetBuffer());
}
}
示例13: Deflate
public byte[] Deflate(string text)
{
var buffer = Encoding.UTF8.GetBytes(text);
using (var ms = new MemoryStream())
{
using (var zipStream = new DeflaterOutputStream(ms, new Deflater(9)))
{
zipStream.Write(buffer, 0, buffer.Length);
zipStream.Close();
var compressed = ms.ToArray();
var gzBuffer = new byte[compressed.Length + 4];
Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
return gzBuffer;
}
}
}
示例14: Compress
public static string Compress(byte[] data, ICodeProgress progress)
{
using(var m = new MemoryStream())
{
switch(technique)
{
case "ZipStream":
var br = new BinaryWriter(m);
var z = new DeflaterOutputStream(m);
br.Write(data.Length);
z.Write(data, 0, data.Length);
z.Flush();
z.Close();
break;
case "7Zip":
default:
return Convert.ToBase64String(SevenZipRadical.Compression.LZMA.SevenZipRadicalHelper.Compress(data, progress));
}
return technique + ":" + Convert.ToBase64String(m.GetBuffer());
}
}
示例15: Compress
public static string Compress(byte[] data)
{
string result;
using (MemoryStream memoryStream = new MemoryStream())
{
string text = CompressionHelper.technique;
if (text != null)
{
if (CompressionHelper.<>f__switch$map1F == null)
{
CompressionHelper.<>f__switch$map1F = new Dictionary<string, int>(1)
{
{
"ZipStream",
0
}
};
}
int num;
if (CompressionHelper.<>f__switch$map1F.TryGetValue(text, out num))
{
if (num == 0)
{
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(memoryStream);
binaryWriter.Write(data.Length);
deflaterOutputStream.Write(data, 0, data.Length);
deflaterOutputStream.Flush();
deflaterOutputStream.Close();
}
}
}
result = CompressionHelper.technique + ":" + Convert.ToBase64String(memoryStream.GetBuffer());
}
return result;
}