整理代码块
代码块整理后存储,供后期使用
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
public class GzipHelper
{
/// <summary>
/// GZIP解压缩
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
protected byte[] Decompress(byte[] data)
{
try
{
var ms = new MemoryStream(data);
var zip = new GZipStream(ms, CompressionMode.Decompress, true);
var msreader = new MemoryStream();
var buffer = new byte[0x1000];
while (true)
{
var reader = zip.Read(buffer, 0, buffer.Length);
if (reader <= 0)
{
break;
}
msreader.Write(buffer, 0, reader);
}
zip.Close();
ms.Close();
msreader.Position = 0;
buffer = msreader.ToArray();
msreader.Close();
return buffer;
}
catch (Exception)
{
throw;
}
}
protected string Decompress(Stream stream)
{
try
{
var zip = new GZipStream(stream, CompressionMode.Decompress, true);
var msreader = new MemoryStream();
var buffer = new byte[0x1000];
while (true)
{
var reader = zip.Read(buffer, 0, buffer.Length);
if (reader <= 0)
{
break;
}
msreader.Write(buffer, 0, reader);
}
zip.Close();
stream.Close();
msreader.Position = 0;
buffer = msreader.ToArray();
msreader.Close();
return Encoding.GetEncoding("UTF-8").GetString(buffer);
}
catch (Exception)
{
throw;
}
}
}
标签:Helper,buffer,代码,System,var,using,GZIP,new,byte
From: https://www.cnblogs.com/Katakana/p/17615641.html