.net压缩功能实现方法
更新时间:2014年02月19日 16:34:35 作者:
这篇文章主要介绍了.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();
}
}
}
}
您可能感兴趣的文章:
相关文章
前台JS(jquery ajax)调用后台方法实现无刷新级联菜单示例
前台用AJAX直接调用后台方法,老有人发帖提问,没事做个示例详细介绍一下,感兴趣的朋友可以参考下2013-01-01
Visual Studio 2017通过SSH调试Linux上.NET Core
这篇文章主要为大家详细介绍了Visual Studio 2017通过SSH调试Linux 上.NET Core的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-03-03
Asp.NetCore1.1版本去掉project.json后如何打包生成跨平台包
这篇文章主要为大家详细介绍了Asp.NetCore1.1版本去掉project.json后如何打包生成跨平台包 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-06-06
Asp.net Core MVC中怎么把二级域名绑定到特定的控制器上
这篇文章主要介绍了Asp.net Core MVC中怎么把二级域名绑定到特定的控制器上,需要的朋友可以参考下2017-06-06
asp.net的web页面(aspx)数据量过多时提交失败对策
asp.net的web页面,数据量过多时提交失败的情况想必有很多朋友都有遇到过吧,下面与大家分享下详细的解决方法2013-05-05


最新评论