本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream类的典型用法代码示例。如果您正苦于以下问题:C# DeflaterOutputStream类的具体用法?C# DeflaterOutputStream怎么用?C# DeflaterOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeflaterOutputStream类属于ICSharpCode.SharpZipLib.Zip.Compression.Streams命名空间,在下文中一共展示了DeflaterOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseDeflatorWithNestedUsing
public void CloseDeflatorWithNestedUsing()
{
string tempFile = null;
try
{
tempFile = Path.GetTempPath();
}
catch (SecurityException)
{
}
Assert.IsNotNull(tempFile, "No permission to execute this test?");
if (tempFile != null)
{
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
using (FileStream diskFile = File.Create(tempFile))
using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
using (StreamWriter txtFile = new StreamWriter(deflator))
{
txtFile.Write("Hello");
txtFile.Flush();
}
File.Delete(tempFile);
}
}
示例2: CompressString
/// <summary>
/// Compresses a string.
/// </summary>
/// <param name="value">The string to compress.</param>
/// <returns>The compressed string.</returns>
public string CompressString(string value)
{
// The input value must be non-null
if (value == null)
{
throw new ArgumentNullException("value");
}
var outputData = string.Empty;
var inputData = UTF8Encoding.UTF8.GetBytes(value);
using (var inputStream = new MemoryStream(inputData))
{
using (var outputStream = new MemoryStream())
{
// Zip the string
using (var zipStream = new DeflaterOutputStream(outputStream))
{
zipStream.IsStreamOwner = false;
StreamUtils.Copy(inputStream, zipStream, new byte[4096]);
}
// Convert to a string
outputData = Convert.ToBase64String(outputStream.GetBuffer(), 0, Convert.ToInt32(outputStream.Length));
}
}
// Return the compressed string
return outputData;
}
示例3: 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;
}
}
示例4: 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;
}
示例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]);
}
}
示例6: CloseInflatorWithNestedUsing
public void CloseInflatorWithNestedUsing()
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
string tempFile = Environment.TickCount.ToString();
store.CreateDirectory(tempFile);
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
using (IsolatedStorageFileStream diskFile = store.CreateFile(tempFile))
using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
using (StreamWriter textWriter = new StreamWriter(deflator))
{
textWriter.Write("Hello");
textWriter.Flush();
}
using (IsolatedStorageFileStream diskFile = store.OpenFile(tempFile, FileMode.Open))
using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
using (StreamReader textReader = new StreamReader(deflator))
{
char[] buffer = new char[5];
int readCount = textReader.Read(buffer, 0, 5);
Assert.AreEqual(5, readCount);
StringBuilder b = new StringBuilder();
b.Append(buffer);
Assert.AreEqual("Hello", b.ToString());
}
store.CreateFile(tempFile);
}
}
示例7: CloseInflatorWithNestedUsing
public void CloseInflatorWithNestedUsing()
{
string tempFile = null;
try {
tempFile = Path.GetTempPath();
} catch (SecurityException) {
}
Assert.IsNotNull(tempFile, "No permission to execute this test?");
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
using (FileStream diskFile = File.Create(tempFile))
using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
using (StreamWriter textWriter = new StreamWriter(deflator)) {
textWriter.Write("Hello");
textWriter.Flush();
}
using (FileStream diskFile = File.OpenRead(tempFile))
using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
using (StreamReader textReader = new StreamReader(deflator)) {
char[] buffer = new char[5];
int readCount = textReader.Read(buffer, 0, 5);
Assert.AreEqual(5, readCount);
var b = new StringBuilder();
b.Append(buffer);
Assert.AreEqual("Hello", b.ToString());
}
File.Delete(tempFile);
}
示例8: 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();
}
示例9: 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();
}
示例10: ZlibOutputStreamIs
public ZlibOutputStreamIs(Stream st, int compressLevel, EDeflateCompressStrategy strat, bool leaveOpen)
: base(st,compressLevel,strat,leaveOpen)
{
deflater=new Deflater(compressLevel);
setStrat(strat);
ost = new DeflaterOutputStream(st, deflater);
ost.IsStreamOwner = !leaveOpen;
}
示例11: 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();
}
示例12: 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();
}
示例13: 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();
}
示例14: 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();
}
示例15: 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);
}