本文整理汇总了C#中Ionic.Zlib.DeflateStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Flush方法的具体用法?C# DeflateStream.Flush怎么用?C# DeflateStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zlib.DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.Flush方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeflateEncoder
/// <summary>Deflate encoder, compatible with .NET one but with bettern compression
/// ratio (in .NET 4.0, in .NET 4.5 they are identical).</summary>
/// <param name="input">The input.</param>
/// <returns>Compressed data.</returns>
public static byte[] DeflateEncoder(byte[] input)
{
using (var ostream = new MemoryStream())
{
using (var zstream = new DeflateStream(ostream, CompressionMode.Compress))
{
zstream.Write(input, 0, input.Length);
zstream.Flush();
}
return ostream.ToArray();
}
}
示例2: Save
public void Save()
{
if (!EnterSave())
return;
Stream zip = new DeflateStream(File.Create(DataFile + ".tmp"), CompressionMode.Compress);
try
{
zip.WriteByte(0); // version
zip.WriteByte(Convert.ToByte(LightToRecalculate));
for (int x = 0; x < 16; ++x)
{
for (int z = 0; z < 16; ++z)
{
zip.WriteByte(HeightMap[x, z]);
}
}
WriteAllBlocks(zip);
zip.Flush();
}
finally
{
try
{
zip.Dispose();
File.Delete(DataFile);
File.Move(DataFile + ".tmp", DataFile);
}
catch
{
}
finally
{
ExitSave();
}
}
}
示例3: Save
public void Save()
{
if (!EnterSave())
return;
Stream zip = new DeflateStream(File.Create(DataFile + ".tmp"), CompressionMode.Compress);
try
{
WriteAllBlocks(zip);
zip.Flush();
}
finally
{
try
{
zip.Dispose();
File.Delete(DataFile);
File.Move(DataFile + ".tmp", DataFile);
}
catch
{
}
finally
{
ExitSave();
}
}
}
示例4: 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;
}