本文整理汇总了C#中System.IO.Compression.DeflateStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Dispose方法的具体用法?C# DeflateStream.Dispose怎么用?C# DeflateStream.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompressCanWrite
public static void CompressCanWrite()
{
var ms = new MemoryStream();
var zip = new DeflateStream(ms, CompressionMode.Compress);
Assert.True(zip.CanWrite);
zip.Dispose();
Assert.False(zip.CanWrite);
}
示例2: DeflateCompress
public static byte[] DeflateCompress(byte[] DATA)
{
MemoryStream ms = new MemoryStream();
DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, true);
stream.Write(DATA, 0, DATA.Length);
stream.Close();
stream.Dispose();
stream = null;
byte[] buffer = StreamDataHelper.ReadDataToBytes(ms);
ms.Close();
ms.Dispose();
ms = null;
return buffer;
}
示例3: 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, CompressionMode.Compress, 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;
}
示例4: CompressStream
public static Stream CompressStream(Stream instream)
{
MemoryStream outstream = new MemoryStream((int)instream.Length);
DeflateStream comp = new DeflateStream(outstream, CompressionMode.Compress, true);
int numBytes;
byte[] buffer = new byte[4096];
while ((numBytes = instream.Read(buffer, 0, 4096)) != 0) {
comp.Write(buffer, 0, numBytes);
}
comp.Flush();
comp.Dispose();
// return to the beginning of the stream
outstream.Position = 0;
//Debug.WriteLine("Compression: " + instream.Length.ToString() + " to " + outstream.Length.ToString());
return outstream;
}
示例5: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) {
Stream compressedStream = null;
switch (_contentEncoding) {
case "gzip":
compressedStream =
new GZipStream(stream, CompressionMode.Compress, leaveOpen: true);
break;
case "deflate":
compressedStream =
new DeflateStream(stream, CompressionMode.Compress, leaveOpen: true);
break;
}
return _initialContent.CopyToAsync(compressedStream).ContinueWith(tsk => {
if (compressedStream != null) {
compressedStream.Dispose();
}
});
}
示例6: ExtractFile
/// <summary>
/// Copy the contents of a stored file into an opened stream
/// </summary>
/// <param name="zfe">Entry information of file to extract</param>
/// <param name="stream">Stream to store the uncompressed data</param>
/// <returns>True if success, false if not.</returns>
/// <remarks>Unique compression methods are Store and Deflate</remarks>
public bool ExtractFile(ZipFileEntry zfe, Stream stream)
{
if (!stream.CanWrite)
throw new InvalidOperationException("Stream cannot be written");
// check signature
var signature = new byte[4];
_zipFileStream.Seek(zfe.HeaderOffset, SeekOrigin.Begin);
_zipFileStream.Read(signature, 0, 4);
if (BitConverter.ToUInt32(signature, 0) != 0x04034b50)
return false;
// Select input stream for inflating or just reading
Stream inStream;
switch (zfe.Method)
{
case Compression.Store:
inStream = _zipFileStream;
break;
case Compression.Deflate:
inStream = new DeflateStream(_zipFileStream, CompressionMode.Decompress, true);
break;
default:
return false;
}
// Buffered copy
var buffer = new byte[16384];
_zipFileStream.Seek(zfe.FileOffset, SeekOrigin.Begin);
var bytesPending = zfe.FileSize;
while (bytesPending > 0)
{
var bytesRead = inStream.Read(buffer, 0, (int) Math.Min(bytesPending, buffer.Length));
stream.Write(buffer, 0, bytesRead);
bytesPending -= (uint) bytesRead;
}
stream.Flush();
if (zfe.Method == Compression.Deflate)
inStream.Dispose();
return true;
}
示例7: SaveMap
//.........这里部分代码省略.........
{
if (Main.Map[num, j].Light > 18)
{
goto Label0;
}
num9++;
num2--;
num++;
}
}
Label0:
if (color > 0)
{
num7 = (byte)(num7 | (byte)(color << 1));
}
if (num7 != 0)
{
num8 = (byte)(num8 | 1);
}
num8 = (byte)(num8 | (byte)(num1 << 1));
if (flag1 && type > 255)
{
num8 = (byte)(num8 | 16);
}
if (flag2)
{
num8 = (byte)(num8 | 32);
}
if (num9 > 0)
{
num8 = (num9 <= 255 ? (byte)(num8 | 64) : (byte)(num8 | 128));
}
light[num3] = num8;
num3++;
if (num7 != 0)
{
light[num3] = num7;
num3++;
}
if (flag1)
{
light[num3] = (byte)type;
num3++;
if (type > 255)
{
light[num3] = (byte)(type >> 8);
num3++;
}
}
if (flag2)
{
light[num3] = item.Light;
num3++;
}
if (num9 > 0)
{
light[num3] = (byte)num9;
num3++;
if (num9 > 255)
{
light[num3] = (byte)(num9 >> 8);
num3++;
}
}
for (int l = num10; l < num11; l++)
{
light[num3] = Main.Map[l, j].Light;
num3++;
}
k = k + num9;
if (num3 >= 4096)
{
deflateStream.Write(light, 0, num3);
num3 = 0;
}
}
}
if (num3 > 0)
{
deflateStream.Write(light, 0, num3);
}
deflateStream.Dispose();
FileUtilities.WriteAllBytes(str, memoryStream.ToArray());
}
}
}
}
catch (Exception exception1)
{
Exception exception = exception1;
using (StreamWriter streamWriter = new StreamWriter("client-crashlog.txt", true))
{
streamWriter.WriteLine(DateTime.Now);
streamWriter.WriteLine(exception);
streamWriter.WriteLine("");
}
}
MapHelper.saveLock = false;
}
}
示例8: DisposeTest
public void DisposeTest ()
{
MemoryStream backing = new MemoryStream (compressed_data);
DeflateStream decompress = new DeflateStream (backing, CompressionMode.Decompress);
decompress.Dispose ();
decompress.Dispose ();
}
示例9: bitmapCompressData
public void bitmapCompressData() {
byte[] bm = new byte[data.Length/4];
byte[] dt = new byte[data.Length];
int bi = 0, di = 0;
for (int i=0; i<data.Length; i+=sizeof(UInt32))
if (data.buf[i+3] == 0)
bm[bi++]=0x00;
else {
bm[bi++]=0xFF;
dt[di++] = data.buf[i];
dt[di++] = data.buf[i+1];
dt[di++] = data.buf[i+2];
}
MemoryStream outbuf = new MemoryStream();
DeflateStream compress = new DeflateStream(outbuf, CompressionMode.Compress);
compress.Write(bm, 0, bi);
compress.Write(dt, 0, di);
compress.Close();
byte[] compData = outbuf.ToArray();
retvalue = compData.Length;
compress.Dispose();
outbuf.Dispose();
}
示例10: CompressTileBlock
public static int CompressTileBlock(int xStart, int yStart, short width, short height, byte[] buffer, int bufferStart)
{
using (MemoryStream memoryStream1 = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter((Stream)memoryStream1))
{
writer.Write(xStart);
writer.Write(yStart);
writer.Write(width);
writer.Write(height);
NetMessage.CompressTileBlock_Inner(writer, xStart, yStart, (int)width, (int)height);
int length = buffer.Length;
if ((long)bufferStart + memoryStream1.Length > (long)length)
return (int)((long)(length - bufferStart) + memoryStream1.Length);
memoryStream1.Position = 0L;
MemoryStream memoryStream2 = new MemoryStream();
using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream2, CompressionMode.Compress, true))
{
memoryStream1.CopyTo((Stream)deflateStream);
deflateStream.Flush();
deflateStream.Close();
deflateStream.Dispose();
}
if (memoryStream1.Length <= memoryStream2.Length)
{
memoryStream1.Position = 0L;
buffer[bufferStart] = (byte)0;
++bufferStart;
memoryStream1.Read(buffer, bufferStart, (int)memoryStream1.Length);
return (int)memoryStream1.Length + 1;
}
memoryStream2.Position = 0L;
buffer[bufferStart] = (byte)1;
++bufferStart;
memoryStream2.Read(buffer, bufferStart, (int)memoryStream2.Length);
return (int)memoryStream2.Length + 1;
}
}
}
示例11: GetDataStream
// **********************************************************************
public static Stream GetDataStream(FileStream fs)
{
byte[] buffer = new byte[prefix.Length];
if(CheckPrefix(fs, buffer))
return fs;
Stream stream = null;
try
{
fs.Position = 0;
stream = new GZipStream(fs, CompressionMode.Decompress, true);
if(CheckPrefix(stream, buffer))
return stream;
}
catch { }
if(stream != null)
{
stream.Dispose();
stream = null;
}
try
{
fs.Position = 0;
stream = new DeflateStream(fs, CompressionMode.Decompress, true);
if(CheckPrefix(stream, buffer))
return stream;
}
catch { }
if(stream != null)
{
stream.Dispose();
stream = null;
}
throw new FormatException("Неверный формат файла");
}
示例12: GetSaveString
/// <summary>
/// Gets the client-side save state as a string.
/// </summary>
/// <returns></returns>
string GetSaveString(Document document)
{
Contract.Requires<ArgumentNullException>(document != null);
using (var stream = new MemoryStream())
using (var encode = new CryptoStream(stream, new ToBase64Transform(), CryptoStreamMode.Write))
using (var deflate = new DeflateStream(encode, CompressionMode.Compress))
using (var writer = XmlDictionaryWriter.CreateBinaryWriter(deflate))
{
document.Save(writer);
// flush output
writer.Dispose();
deflate.Dispose();
encode.Dispose();
return Encoding.ASCII.GetString(stream.ToArray());
}
}
示例13: Compress
internal byte[] Compress(byte[] decompressedBuffer)
{
MemoryStream memStream = new MemoryStream();
DeflateStream zip = new DeflateStream(memStream, CompressionMode.Compress, true);
zip.Write(decompressedBuffer, 0, decompressedBuffer.Length);
zip.Close();
memStream.Position = 0;
byte[] buffer = new byte[memStream.Length + 2];
//Console.WriteLine(BitConverter.ToString(memStream.ToArray()));
memStream.Read(buffer, 2, buffer.Length - 2);
memStream.Close();
memStream.Dispose();
zip.Dispose();
System.Buffer.BlockCopy(new byte[] { 0x78, 0x9C }, 0, buffer, 0, 2);
return buffer;
}
示例14: DeflateDecompress
public static byte[] DeflateDecompress(byte[] data)
{
MemoryStream ms = new MemoryStream(data);
DeflateStream stream = new DeflateStream(ms, CompressionMode.Decompress);
byte[] buffer = StreamDataHelper.ReadDataToBytes(stream);
ms.Close();
ms.Dispose();
ms = null;
stream.Close();
stream.Dispose();
stream = null;
return buffer;
}
示例15: CanDisposeDeflateStream
public static void CanDisposeDeflateStream()
{
var ms = new MemoryStream();
var zip = new DeflateStream(ms, CompressionMode.Compress);
zip.Dispose();
// Base Stream should be null after dispose
Assert.Null(zip.BaseStream);
zip.Dispose(); // Should be a no-op
}