本文整理汇总了C#中System.IO.Compression.DeflateStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Close方法的具体用法?C# DeflateStream.Close怎么用?C# DeflateStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compress
public static byte[] Compress(string data)
{
byte[] input = Encoding.ASCII.GetBytes(data);
MemoryStream ms = new MemoryStream();
DeflateStream zipper = new DeflateStream(ms, CompressionMode.Compress, true);
zipper.Write(input, 0, input.Length);
zipper.Close();
byte[] output;
if (ms.Length < input.Length)
{
output = new byte[ms.Length + 8];
SetLength(input.Length, output, 0);
SetLength((int)ms.Length, output, 4);
ms.Position = 0;
ms.Read(output, 8, output.Length - 8);
}
else
{
output = new byte[input.Length + 8];
SetLength(input.Length, output, 0);
SetLength(input.Length, output, 4);
input.CopyTo(output, 8);
}
return output;
}
示例2: 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();
}
示例3: Main
static void Main(string[] args)
{
GZipStream gzOut = new GZipStream(File.Create(@"C:\Writing1mb.zip"), CompressionMode.Compress);
DeflateStream dfOut = new DeflateStream(File.Create(@"C:\Writing1mb2.zip"), CompressionMode.Compress);
TextWriter tw = new StreamWriter(gzOut);
TextWriter tw2 = new StreamWriter(dfOut);
try
{
for(int i = 0; i < 1000000; i++)
{
tw.WriteLine("Writing until more than 1mb to ZIP it!");
tw2.WriteLine("Writing until more than 1mb to ZIP it!");
}
}
catch(Exception)
{
throw;
}
finally
{
tw.Close();
gzOut.Close();
tw2.Close();
dfOut.Close();
}
}
示例4: Compress
public static byte[] Compress(byte[] data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
using (var output = new MemoryStream())
{
// ZLib Header 0x78 0x9C
output.WriteByte(0x78);
output.WriteByte(0x9C);
using (var input = new MemoryStream(data))
{
using (var compressionStream = new DeflateStream(output, CompressionMode.Compress, true))
{
input.CopyTo(compressionStream);
compressionStream.Close();
// Adler32 hash of the uncompressed data
var adler32 = new Adler32();
adler32.Update(data);
byte[] hash = BitConverter.GetBytes((int) adler32.Value);
Array.Reverse(hash);
output.Write(hash, 0, hash.Length);
return output.ToArray();
}
}
}
}
示例5: Decrypt
public static StreamReader Decrypt(string source, int key)
{
byte[] data = System.Convert.FromBase64String(source);
byte[] dec = AES.DecryptData(data, GetTrueKey(key), key.ToString() + "P8xvDLzPHvNiwVMkS3kPzQStAEDqdTMD", System.Security.Cryptography.PaddingMode.ISO10126);
int d_len = System.BitConverter.ToInt32(dec, 40);
MemoryStream ms = new MemoryStream(dec);
ms.Position = 44;
// Use the newly created memory stream for the compressed data.
DeflateStream compressedzipStream = new DeflateStream(ms, CompressionMode.Decompress, true);
//Console.WriteLine("Compression");
byte[] zdec = new byte[d_len];
int cnt = compressedzipStream.Read(zdec, 0, d_len);
// Close the stream.
compressedzipStream.Close();
dec = new byte[cnt];
System.Array.ConstrainedCopy(zdec, 0, dec, 0, cnt);
MemoryStream mem_stream = new System.IO.MemoryStream(dec);
StreamReader output = new System.IO.StreamReader((System.IO.Stream)mem_stream);
return output;
}
示例6: CompressTest
public void CompressTest()
{
var s = "StartTime:13.4.201213:15:26;RunTime:00:01:24";
var ms = new MemoryStream();
var ds = new DeflateStream(ms, CompressionMode.Compress);
var encoding = System.Text.Encoding.UTF8;
var byteData = encoding.GetBytes(s);
Trace.WriteLine("original : {0}", s);
ds.Write(byteData, 0, byteData.Length);
ds.Close();
byte[] compressed = ms.ToArray();
Trace.WriteLine("compressed : {0}", System.Convert.ToBase64String(compressed));
ms = new MemoryStream(compressed);
ds = new DeflateStream(ms, CompressionMode.Decompress);
compressed = new byte[compressed.Length + 100];
var offset = 0;
while (true)
{
int bytesRead = ds.Read(compressed, offset, 1);
if (bytesRead == 0) { break; }
offset += bytesRead;
}
ds.Close();
string uncompressed = encoding.GetString(compressed);
Trace.WriteLine("uncompressed: {0}\n", uncompressed);
}
示例7: 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.");
}
示例8: Deflate
/// <summary>
/// Compresses a data buffer using a simple huffman deflate algorithem.
/// </summary>
/// <param name="data">Data buffer to compress.</param>
/// <returns>Compressed version of data buffer.</returns>
public static byte[] Deflate(byte[] data)
{
MemoryStream memoryStream = new MemoryStream();
DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress, true);
deflateStream.Write(data, 0, data.Length);
deflateStream.Close();
return memoryStream.ToArray();
}
示例9: Compress
/// <summary>
/// Compresses the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>The compressed data.</returns>
public static byte[] Compress(this byte[] input)
{
var inputStream = new MemoryStream(input);
var outputStream = new MemoryStream();
var compressor = new DeflateStream(outputStream, CompressionMode.Compress);
inputStream.CopyTo(compressor);
compressor.Close();
return outputStream.ToArray();
}
示例10: 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();
}
示例11: Decompress
/// <summary>
/// Decompresses the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>The decompressed data.</returns>
public static byte[] Decompress(this byte[] input)
{
var inflatedStream = new MemoryStream(input);
var outputStream = new MemoryStream();
var decompressor = new DeflateStream(inflatedStream, CompressionMode.Decompress);
decompressor.CopyTo(outputStream);
decompressor.Close();
return outputStream.ToArray();
}
示例12: Decompress
/// <summary>解压缩数据流</summary>
/// <param name="inStream">输入流</param>
/// <param name="outStream">输出流</param>
public static void Decompress(this Stream inStream, Stream outStream)
{
// 第三个参数为true,保持数据流打开,内部不应该干涉外部,不要关闭外部的数据流
using (Stream stream = new DeflateStream(inStream, CompressionMode.Decompress, true))
{
stream.CopyTo(outStream);
stream.Close();
}
}
示例13: Encode
public byte[] Encode(byte[] data)
{
MemoryStream ms = new MemoryStream(data.Length);
ms.WriteByte(0x78); // ZLib Header for compression level 3.
ms.WriteByte(0x5e);
DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress);
ds.Write(data, 0, data.Length);
ds.Close();
return ms.ToArray();
}
示例14: Compress
public static byte[] Compress(byte[] data)
{
using (var compressedStream = new MemoryStream())
using (var zipStream = new DeflateStream(compressedStream, CompressionMode.Compress))
{
zipStream.Write(data, 0, data.Length);
zipStream.Close();
return compressedStream.ToArray();
}
}
示例15: Encode
public byte[] Encode(byte[] data)
{
var output = new MemoryStream();
var gzipstream = new DeflateStream(output, CompressionMode.Compress);
gzipstream.Write(data, 0, data.Length);
gzipstream.Close();
byte[] compressed = output.ToArray();
output.Close();
return compressed;
}