本文整理汇总了C#中System.IO.Compression.DeflateStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Flush方法的具体用法?C# DeflateStream.Flush怎么用?C# DeflateStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compress
/// <summary>
/// 压缩
/// </summary>
/// <param name="inStream">输入流</param>
/// <param name="outStream">输出流</param>
public static void Compress(this Stream inStream, Stream outStream)
{
Stream stream = new DeflateStream(outStream, CompressionMode.Compress, true);
CopyTo(inStream, stream);
stream.Flush();
stream.Close();
}
示例2: GetEditorsTableFromResponse
/// <summary>
/// Get EditorsTable from server response.
/// </summary>
/// <param name="subResponse">The sub response from server.</param>
/// <param name="site">Transfer ITestSite into this operation, for this operation to use ITestSite's function.</param>
/// <returns>The instance of EditorsTable.</returns>
public static EditorsTable GetEditorsTableFromResponse(FsshttpbResponse subResponse, ITestSite site)
{
if (subResponse == null || subResponse.DataElementPackage == null || subResponse.DataElementPackage.DataElements == null)
{
site.Assert.Fail("The parameter CellResponse is not valid, check whether the CellResponse::DataElementPackage or CellResponse::DataElementPackage::DataElements is null.");
}
foreach (DataElement de in subResponse.DataElementPackage.DataElements)
{
if (de.Data.GetType() == typeof(ObjectGroupDataElementData))
{
ObjectGroupDataElementData ogde = de.Data as ObjectGroupDataElementData;
if (ogde.ObjectGroupData == null || ogde.ObjectGroupData.ObjectGroupObjectDataList.Count == 0)
{
continue;
}
for (int i = 0; i < ogde.ObjectGroupData.ObjectGroupObjectDataList.Count; i++)
{
if (IsEditorsTableHeader(ogde.ObjectGroupData.ObjectGroupObjectDataList[i].Data.Content.ToArray()))
{
string editorsTableXml = null;
// If the current object group object data is the header byte array 0x1a, 0x5a, 0x3a, 0x30, 0, 0, 0, 0, then the immediate following object group object data will contain the Editor table xml.
byte[] buffer = ogde.ObjectGroupData.ObjectGroupObjectDataList[i + 1].Data.Content.ToArray();
System.IO.MemoryStream ms = null;
try
{
ms = new System.IO.MemoryStream();
ms.Write(buffer, 0, buffer.Length);
ms.Position = 0;
using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Decompress))
{
stream.Flush();
byte[] decompressBuffer = new byte[buffer.Length * 3];
stream.Read(decompressBuffer, 0, buffer.Length * 3);
stream.Close();
editorsTableXml = System.Text.Encoding.UTF8.GetString(decompressBuffer);
}
ms.Close();
}
finally
{
if (ms != null)
{
ms.Dispose();
}
}
return GetEditorsTable(editorsTableXml);
}
}
}
}
throw new InvalidOperationException("Cannot find any data group object data contain editor tables information.");
}
示例3: Compress
/// <summary>
/// Compresses the specified data.
/// </summary>
/// <param name="data">The data.</param>
/// <returns></returns>
public static byte[] Compress(byte[] data)
{
MemoryStream ms = new MemoryStream();
DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress);
ds.Write(data, 0, data.Length);
ds.Flush();
ds.Close();
return ms.ToArray();
}
示例4: Compress
public static byte[] Compress(byte[] data)
{
var memoryStream = new MemoryStream();
var deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress);
deflateStream.Write(data, 0, data.Length);
deflateStream.Flush();
deflateStream.Close();
return memoryStream.ToArray();
}
示例5: CompressFinalBlock
/// <summary>
/// 转换指定字节数组的指定区域。
/// </summary>
/// <param name="inputBuffer">要为其计算转换的输入。</param>
/// <param name="inputOffset">字节数组中的偏移量,从该位置开始使用数据。</param>
/// <param name="inputCount">字节数组中用作数据的字节数。</param>
/// <returns>计算所得的转换。</returns>
public override byte[] CompressFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
using (var ms = new MemoryStream()) {
using (var outStream = new DeflateStream(ms, CompressionMode.Compress)) {
outStream.Write(inputBuffer, inputOffset, inputCount);
outStream.Flush();
}
return ms.ToArray();
}
}
示例6: CompressBlock
/// <summary>
/// 转换指定字节数组的指定区域。
/// </summary>
/// <param name="inputBuffer">要为其计算转换的输入。</param>
/// <param name="inputOffset">字节数组中的偏移量,从该位置开始使用数据。</param>
/// <param name="inputCount">字节数组中用作数据的字节数。</param>
/// <param name="outputBuffer">将转换写入的输出。</param>
/// <param name="outputOffset">输出字节数组中的偏移量,从该位置开始写入数据。</param>
/// <returns>计算所得的转换的字节数。</returns>
public override int CompressBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
using (var ms = new MemoryStream(outputBuffer, outputOffset, outputBuffer.Length - outputOffset, true)) {
using (var outStream = new DeflateStream(ms, CompressionMode.Compress)) {
outStream.Write(inputBuffer, inputOffset, inputCount);
outStream.Flush();
}
return (int)ms.Position;
}
}
示例7: Compress
/// <summary>压缩数据流</summary>
/// <param name="inStream">输入流</param>
/// <param name="outStream">输出流</param>
public static void Compress(this Stream inStream, Stream outStream)
{
// 第三个参数为true,保持数据流打开,内部不应该干涉外部,不要关闭外部的数据流
using (Stream stream = new DeflateStream(outStream, CompressionMode.Compress, true))
{
inStream.CopyTo(stream);
stream.Flush();
stream.Close();
}
}
示例8: Compress
internal static byte[] Compress(byte[] data)
{
using (var ms = new MemoryStream())
{
var ds = new DeflateStream(ms, CompressionMode.Compress);
ds.Write(data, 0, data.Length);
ds.Flush();
ds.Close();
return ms.ToArray();
}
}
示例9: CompressToBinary
public static string CompressToBinary(object obj)
{
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, obj);
byte[] inbyt = ms.ToArray();
MemoryStream objStream = new MemoryStream();
DeflateStream objZS = new DeflateStream(objStream, CompressionMode.Compress);
objZS.Write(inbyt, 0, inbyt.Length);
objZS.Flush();
objZS.Close();
return Convert.ToBase64String(objStream.ToArray());
}
示例10: CompressData
/// <summary>
/// Compresses binary data with Deflate method.
/// </summary>
/// <param name="Data">Byte array with data to compress.</param>
/// <returns>Returns the result byte array with compressed data if successful, otherwise returns NULL.</returns>
public static byte[] CompressData(byte[] Data)
{
try
{
var MS = new MemoryStream();
var CS = new DeflateStream(MS, CompressionMode.Compress, true);
CS.Write(Data, 0, Data.Length);
CS.Flush();
CS.Close();
return MS.ToArray();
}
catch { return null; }
}
示例11: CompressionObject
public static byte[] CompressionObject(object DataOriginal) {
if (DataOriginal == null) return null;
var bFormatter = new BinaryFormatter();
var mStream = new MemoryStream();
bFormatter.Serialize(mStream, DataOriginal);
var bytes = mStream.ToArray();
var oStream = new MemoryStream();
var zipStream = new DeflateStream(oStream, CompressionMode.Compress);
zipStream.Write(bytes, 0, bytes.Length);
zipStream.Flush();
zipStream.Close();
return oStream.ToArray();
}
示例12: processChunk
static Patch processChunk(byte[] orig, byte[] mod, int chunkStart, int chunkEnd) {
int patchSize = chunkEnd - chunkStart;
Debug.Assert(patchSize < Patch.MaxPatchSize);
int matchAreaSize = Patch.MatchAreaSize(patchSize);
int matchBefore = (matchAreaSize - patchSize) / 2;
int matchAfter = matchAreaSize - (patchSize + matchBefore);
Debug.Assert(matchBefore <= chunkStart);
Debug.Assert(chunkEnd + matchAfter <= orig.Length);
byte[] origBytes = new byte[matchAreaSize];
byte[] patchBytes = new byte[patchSize];
Array.ConstrainedCopy(orig, chunkStart - matchBefore, origBytes, 0, matchAreaSize);
Array.ConstrainedCopy(mod, chunkStart, patchBytes, 0, patchSize);
MemoryStream ms = new MemoryStream();
DeflateStream comp = new DeflateStream(ms, CompressionMode.Compress);
comp.WriteByte(0);
comp.Flush();
long base_len = ms.Length;
comp.Write(origBytes, 0, origBytes.Length);
comp.Flush();
return new Patch(origBytes, patchBytes, matchBefore, Convert.ToInt32(ms.Length - base_len));
}
示例13: Main
static void Main(string[] args)
{
string file;
if (args.Length > 0) file = args[0];
else
{
Console.Write("File: ");
file = Console.ReadLine();
}
if (file == null || !File.Exists(file)) Environment.Exit(1);
var input = new FileStream(file, FileMode.Open);
var output = new FileStream(file + ".sd0", FileMode.Create);
using (var writer = new BinaryWriter(output, Encoding.UTF8))
{
writer.Write('s');
writer.Write('d');
writer.Write('0');
writer.Write((byte)0x01);
writer.Write((byte)0xff);
const int chunkMaxLength = 1024 * 256;
int read;
var buffer = new byte[chunkMaxLength];
var chunkNumber = 1;
while ((read = input.Read(buffer, 0, chunkMaxLength)) > 0)
{
Console.WriteLine("Writing chunk {0}...", chunkNumber);
using (var outputStream = new MemoryStream())
using (var compressionStream = new DeflateStream(outputStream, CompressionMode.Compress, true))
{
compressionStream.Write(buffer, 0, read);
compressionStream.Flush();
compressionStream.Close();
writer.Write(outputStream.ToArray().Length);
writer.Write(outputStream.ToArray());
}
Console.WriteLine(" ->OK");
chunkNumber++;
}
Console.WriteLine("Done.");
}
}
示例14: DecompressFromBinary
public static object DecompressFromBinary(string text)
{
byte[] bytCook = Convert.FromBase64String(text);
MemoryStream inMs = new MemoryStream(bytCook);
inMs.Seek(0, 0);
DeflateStream zipStream = new DeflateStream(inMs, CompressionMode.Decompress, true);
byte[] outByt = ReadFullStream(zipStream);
zipStream.Flush();
zipStream.Close();
MemoryStream outMs = new MemoryStream(outByt);
outMs.Seek(0, 0);
BinaryFormatter bf = new BinaryFormatter();
return (object)bf.Deserialize(outMs, null);
}
示例15: 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;
}