您现在的位置是:网站首页> 编程资料编程资料
.net压缩功能实现方法_实用技巧_
2023-05-25
326人已围观
简介 .net压缩功能实现方法_实用技巧_
复制代码 代码如下:
public static class Compressor {
public static byte[] Compress(byte[] data)
{
using (MemoryStream output = new MemoryStream())
{
using (GZipStream gzip = new GZipStream(output, CompressionMode.Compress, true))
{
gzip.Write(data, 0, data.Length);
gzip.Close();
return output.ToArray();
}
}
}
public static byte[] Decompress(byte[] data)
{
using (MemoryStream input = new MemoryStream())
{
input.Write(data, 0, data.Length);
input.Position = 0;
using (GZipStream gzip = new GZipStream(input, CompressionMode.Decompress, true))
{
using (MemoryStream output = new MemoryStream())
{
byte[] buff = new byte[64];
int read = -1;
read = gzip.Read(buff, 0, buff.Length);
while (read > 0)
{
output.Write(buff, 0, read);
read = gzip.Read(buff, 0, buff.Length);
}
gzip.Close();
return output.ToArray();
}
}
}
}
您可能感兴趣的文章:
相关内容
- asp.net导出Excel乱码的原因及解决方法_实用技巧_
- asp.net读取excel中的数据并绑定在gridview_实用技巧_
- asp.net listbox实现单选全选取消_实用技巧_
- asp.net C#检查URL是否有效的方法_实用技巧_
- ASP.NET页面按钮单击事件失效的解决方法_实用技巧_
- GridView生成的HTML代码示例对比_实用技巧_
- .net4.0中tuple元组的使用方法_实用技巧_
- asp.net各种cookie代码和解析实例_实用技巧_
- asp.net上传execl文件后,在页面上加载显示(示例代码)_实用技巧_
- asp.net(C#)生成Code39条形码实例 条码枪可以扫描出_实用技巧_
