GZIP的压缩与解压缩代码:

public static class CompressionHelper
{
/// <summary>
/// Compress the byte[]
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static byte[] Compress(byte[] input)
{
byte[] output;
using (MemoryStream ms = new MemoryStream())
{
using (GZipStream gs = new GZipStream(ms, CompressionMode.Compress))
{
gs.Write(input, , input.Length);
gs.Close();
output = ms.ToArray();
}
ms.Close();
}
return output;
} /// <summary>
/// Decompress the byte[]
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static byte[] Decompress(byte[] input)
{
List<byte> output = new List<byte>();
using (MemoryStream ms = new MemoryStream(input))
{
using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress))
{
int readByte = gs.ReadByte();
while (readByte != -)
{
output.Add((byte)readByte);
readByte = gs.ReadByte();
}
gs.Close();
}
ms.Close();
}
return output.ToArray();
}
}

出处:http://blog.csdn.net/joyhen/article/details/45366969

GZip压缩与解压缩的更多相关文章

  1. GZIP压缩、解压缩工具类

    GZIP压缩.解压缩工具类: public class GZIPUtiles { public static String compress(String str) throws IOExceptio ...

  2. GZip 压缩及解压缩

    /// <summary> /// GZipHelper /// </summary> public class GZipHelper { /// <summary> ...

  3. 对数据进行GZIP压缩或解压缩

    /** * 对data进行GZIP解压缩 * @param data * @return * @throws Exception */ public static String unCompress( ...

  4. java GZIP压缩与解压缩

    1.GZIP压缩 public static byte[] compress(String str, String encoding) { if (str == null || str.length( ...

  5. 压缩与解压缩 gzip bzip2 tar 命令

    gzip压缩与解压缩 命令  gzip -v   解压缩 gzip-d 操作如下. 压缩 .可以看到源文件有5171大小,压缩后,变成了1998大小. 解压缩 .解压缩之后可以看到,原来的man_db ...

  6. gzip [选项] 压缩(解压缩)

    减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间.gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用. 语法:gzip ...

  7. Linux命令(十八) 压缩或解压缩文件和目录 gzip gunzip

    目录 1.命令简介 2.常用参数介绍 3.实例 4.直达底部 命令简介 和 zip 命令类似,gzip 用于文件的压缩,gzip压缩后的文件扩展名为 ".gz",gzip默认压缩后 ...

  8. c#实现gzip压缩解压缩算法:byte[]字节数组,文件,字符串,数据流的压缩解压缩

    转载:https://blog.csdn.net/luanpeng825485697/article/details/78165788 我测试了下压缩byte[],是可以的 using System; ...

  9. Python3 压缩与解压缩(zlib / gzip / bz2 / lzma / zipfile / tarfile)

    本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog.csdn.net/Rozol/article/details/72672703 以下代码以Python3.6.1为例 L ...

随机推荐

  1. React-Native 常用组件学习资料链接

    以下链接是自己开发RN工程时参考的一些不错的资料,给喜欢学习的朋友分享以下. React-Native组件用法详解之ListViewhttp://www.jianshu.com/p/1293bb8ac ...

  2. caffe python lmdb读写

    caffe中可以采取lmdb健值数据库的方式向网络中输入数据. 所以操作lmdb就围绕"键-值"的方式访问数据库就好了. Write 我们可以采用cv2来读入自己的图像数据,采用d ...

  3. UVA 1640 The Counting Problem(按位dp)

    题意:给你整数a.b,问你[a,b]间每个数字分解成单个数字后,0.1.2.3.4.5.6.7.8.9,分别有多少个 题解:首先找到[0,b]与[0,a-1]进行区间减法,接着就只是求[0,x] 对于 ...

  4. Oracle闪回机制

    最近学习oracle的时候,无意中看到oracle的闪回技术flashback,原来oracle在delete数据或者drop的时候,不是直接删除,而是跟windows一样,先把数据放入到回收站中. ...

  5. php源码之appveyor

    打开appveyor目录 是4个bat文件 1. .bat是什么? bat文件是dos下的批处理文件.批处理文件是无格式的文本文件,它包含一条或多条命令. 它的文件扩展名为.bat或.cmd 在命令提 ...

  6. centOS7.4 thinkPHP nginx 支持pathinfo和rewrite

    server { listen 80; server_name www.demo.com mayifanx.com; root /data/www/demo; index index.php inde ...

  7. LeetCode第[49]题(Java):Group Anagrams

    题目:同字符分组 难度:Medium 题目内容: Given an array of strings, group anagrams together. 翻译:给定一组字符串数组,按相同字符组成的字符 ...

  8. 第一章 Burp Suite 安装和环境配置

    Burp Suite是一个集成化的渗透测试工具,它集合了多种渗透测试组件,使我们自动化地或手工地能更好的完成对web应用的渗透测试和攻击.在渗透测试中,我们使用Burp Suite将使得测试工作变得更 ...

  9. 【Demo】HTML5获取地理位置

    HTML5获取地理位置简单实例 实例1--获取地理位置的经纬度: <!DOCTYPE html> <html> <head>  <meta charset=& ...

  10. 三十六 Python分布式爬虫打造搜索引擎Scrapy精讲—利用开源的scrapy-redis编写分布式爬虫代码

    scrapy-redis是一个可以scrapy结合redis搭建分布式爬虫的开源模块 scrapy-redis的依赖 Python 2.7, 3.4 or 3.5,Python支持版本 Redis & ...