本文整理汇总了C#中Ionic.Zlib.DeflateStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Close方法的具体用法?C# DeflateStream.Close怎么用?C# DeflateStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zlib.DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.Close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: zlibDeflate
public static void zlibDeflate(
string pathInput,
string pathOutput,
CompressionMode mode,
CompressionLevel level
)
{
using (Stream input = File.OpenRead(pathInput))
using (Stream output = File.Create(pathOutput))
using (Stream deflateStream = new DeflateStream(
mode == CompressionMode.Compress ? output : input,
mode, level, true))
{
byte[] buff = new byte[ZLIB_BUFF_SIZE];
int n = 0;
Stream toRead = mode == CompressionMode.Compress ?
input : deflateStream;
Stream toWrite = mode == CompressionMode.Compress ?
deflateStream : output;
while (0 != (n = toRead.Read(buff, 0, buff.Length)))
{
toWrite.Write(buff, 0, n);
}
deflateStream.Close();
input.Close();
output.Close();
}
}
示例2: CompressBuffer
public static byte[] CompressBuffer(byte[] buffer)
{
byte[] compressed;
using (var input = new MemoryStream(buffer))
using (var compressStream = new MemoryStream())
using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
{
input.CopyTo(compressor);
compressor.Close();
compressed = compressStream.ToArray();
}
return compressed;
}
示例3: CompressBuffer
public static byte[] CompressBuffer(byte[] buffer, ushort key, uint keyend)
{
byte[] compressed;
using (var compressStream = new MemoryStream())
using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
{
compressor.Write(buffer, 0, buffer.Length);
compressor.Close();
compressed = compressStream.ToArray();
}
byte[] returnbytes = new byte[compressed.Length + 6];
byte[] kbyte = BitConverter.GetBytes(key);
byte[] kebyte = BitConverter.GetBytes(keyend);
Array.Copy(kbyte, 0, returnbytes, 0, kbyte.Length);
Array.Copy(compressed, 0, returnbytes, 2, compressed.Length);
Array.Copy(kebyte, 0, returnbytes, returnbytes.Length - 4, kebyte.Length);
return returnbytes;
}
示例4: Zlib_DisposedException_DeflateStream
public void Zlib_DisposedException_DeflateStream()
{
string TextToCompress = LetMeDoItNow;
MemoryStream ms1= new MemoryStream();
Stream compressor= new DeflateStream(ms1, CompressionMode.Compress, false);
TestContext.WriteLine("Text to compress is {0} bytes: '{1}'",
TextToCompress.Length, TextToCompress);
TestContext.WriteLine("using compressor: {0}", compressor.GetType().FullName);
StreamWriter sw = new StreamWriter(compressor, Encoding.ASCII);
sw.Write(TextToCompress);
sw.Close(); // implicitly closes compressor
sw.Close(); // implicitly closes compressor, again
compressor.Close(); // explicitly closes compressor
var a = ms1.ToArray();
TestContext.WriteLine("Compressed stream is {0} bytes long", a.Length);
var ms2 = new MemoryStream(a);
Stream decompressor = new DeflateStream(ms2, CompressionMode.Decompress, false);
TestContext.WriteLine("using decompressor: {0}", decompressor.GetType().FullName);
var sr = new StreamReader(decompressor, Encoding.ASCII);
string DecompressedText = sr.ReadToEnd();
sr.Close();
TestContext.WriteLine("decompressor.CanRead = {0}",decompressor.CanRead);
TestContext.WriteLine("Read {0} characters: '{1}'", DecompressedText.Length, DecompressedText);
TestContext.WriteLine("\n");
Assert.AreEqual<String>(TextToCompress, DecompressedText);
}
示例5: DecompressTileBlock
public static void DecompressTileBlock(byte[] buffer, int bufferStart, int bufferLength)
{
using (MemoryStream memoryStream = new MemoryStream())
{
memoryStream.Write(buffer, bufferStart, bufferLength);
memoryStream.Position = 0L;
bool flag = memoryStream.ReadByte() != 0;
MemoryStream memoryStream3;
if (flag)
{
MemoryStream memoryStream2 = new MemoryStream();
using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Decompress, CompressionLevel.BestCompression))
{
deflateStream.CopyTo(memoryStream2);
deflateStream.Close();
}
memoryStream3 = memoryStream2;
memoryStream3.Position = 0L;
}
else
{
memoryStream3 = memoryStream;
memoryStream3.Position = 1L;
}
using (BinaryReader binaryReader = new BinaryReader(memoryStream3))
{
int xStart = binaryReader.ReadInt32();
int yStart = binaryReader.ReadInt32();
short width = binaryReader.ReadInt16();
short height = binaryReader.ReadInt16();
NetMessage.DecompressTileBlock_Inner(binaryReader, xStart, yStart, (int)width, (int)height);
}
}
}
示例6: CompressTileBlock
public static int CompressTileBlock(int xStart, int yStart, short width, short height, byte[] buffer, int bufferStart)
{
int result;
using (MemoryStream memoryStream = new MemoryStream())
{
using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
{
binaryWriter.Write(xStart);
binaryWriter.Write(yStart);
binaryWriter.Write(width);
binaryWriter.Write(height);
NetMessage.CompressTileBlock_Inner(binaryWriter, xStart, yStart, (int)width, (int)height);
int num = buffer.Length;
if ((long)bufferStart + memoryStream.Length > (long)num)
{
result = (int)((long)(num - bufferStart) + memoryStream.Length);
}
else
{
memoryStream.Position = 0L;
MemoryStream memoryStream2 = new MemoryStream();
using (DeflateStream deflateStream = new DeflateStream(memoryStream2, 0, true))
{
memoryStream.CopyTo(deflateStream);
deflateStream.Flush();
deflateStream.Close();
deflateStream.Dispose();
}
if (memoryStream.Length <= memoryStream2.Length)
{
memoryStream.Position = 0L;
buffer[bufferStart] = 0;
bufferStart++;
memoryStream.Read(buffer, bufferStart, (int)memoryStream.Length);
result = (int)memoryStream.Length + 1;
}
else
{
memoryStream2.Position = 0L;
buffer[bufferStart] = 1;
bufferStart++;
memoryStream2.Read(buffer, bufferStart, (int)memoryStream2.Length);
result = (int)memoryStream2.Length + 1;
}
}
}
}
return result;
}
示例7: Save
public void Save(Stream Target,SaveFormatInfo Format,StreamProgress.ProgressFunction pfunction)
{
SerializationInfo sinfo;
try
{
Stream outstream = Target;
{
using (StreamProgress sp = new StreamProgress(outstream, pfunction))
{
if (Format is BinarySaveFormatInfo)
{
BinarySaveFormatInfo BinInfo = Format as BinarySaveFormatInfo;
//write out whether this is compressed.
IFormatter binformatter = BCBlockGameState.getFormatter<EditorSet>(BCBlockGameState.DataSaveFormats.Format_Binary);
outstream.WriteByte((byte)(BinInfo.CompressionType != CompressionTypeConstants.Compression_None ? 1 : 0));
Stream targetstream;
switch (BinInfo.CompressionType)
{
case CompressionTypeConstants.Compression_GZip:
targetstream = new GZipStream(outstream, CompressionMode.Compress);
break;
case CompressionTypeConstants.Compression_Deflate:
targetstream = new DeflateStream(outstream, CompressionMode.Compress, CompressionLevel.BestCompression);
break;
default:
targetstream = outstream;
break;
}
using (targetstream)
{
Cursor.Current = Cursors.WaitCursor;
binformatter.Serialize(targetstream, this);
targetstream.Close();
Cursor.Current = Cursors.Default;
}
}
else if(Format is XmlSaveFormatInfo)
{
Cursor.Current = Cursors.WaitCursor;
//almost forgot to change this code to save to XML properly. the SOAP stuff, we have to remove at some stage...
XElement BuildElement = this.GetXmlData("EditorSet",null);
XDocument buildDocument = new XDocument(BuildElement);
buildDocument.Save(outstream,SaveOptions.OmitDuplicateNamespaces);
/*IFormatter xmlformat = BCBlockGameState.getFormatter<EditorSet>(BCBlockGameState.DataSaveFormats.Format_XML);
Cursor.Current = Cursors.WaitCursor;
xmlformat.Serialize(outstream,this);*/
}
}
}
}
catch (Exception e)
{
Debug.Print("Exception in EditorSet.Save:" + e.ToString());
}
finally
{
Cursor.Current = Cursors.Default;
}
}
示例8: decompress
/*static void decompress()
{
decompress("C:/users/Luciano/Desktop/manifest.bin");
}*/
static void decompress(string inputfile, string outputPath)
{
FileStream f = File.Open(inputfile, FileMode.Open);
FileStream final = File.Create(outputPath);
StreamReader reader = new StreamReader(f);
StreamWriter writer = new StreamWriter(final);
DeflateStream a = new DeflateStream(f, CompressionMode.Decompress);
int read = 0;
byte[] buffer = new byte[1024 * 1024];
f.Position = 10;
while ((read = a.Read(buffer, 0, buffer.Length)) > 0)
{
final.Write(buffer, 0, read);
}
f.Close();
a.Close();
final.Close();
}
示例9: compress
public static void compress()
{
FileStream f = File.Open("C:/users/Luciano/Desktop/manifest.txt", FileMode.Open, FileAccess.ReadWrite);
FileStream final = File.Create("C:/users/Luciano/Desktop/manifest.bin");
int size = (int)f.Length;
StreamReader r = new StreamReader(f);
BinaryWriter w = new BinaryWriter(final);
w.Write("l33t".ToCharArray());
w.Write(size);
w.BaseStream.WriteByte(0x78);
w.BaseStream.WriteByte(0x9C);
DeflateStream a = new DeflateStream(f, CompressionMode.Compress);
int read = 0;
byte[] buffer = new byte[1024 * 1024];
while ((read = a.Read(buffer, 0, buffer.Length)) > 0)
{
w.Write(buffer, 0, read);
}
a.Close();
f.Close();
}