GZip压缩与解压缩
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压缩与解压缩的更多相关文章
- GZIP压缩、解压缩工具类
GZIP压缩.解压缩工具类: public class GZIPUtiles { public static String compress(String str) throws IOExceptio ...
- GZip 压缩及解压缩
/// <summary> /// GZipHelper /// </summary> public class GZipHelper { /// <summary> ...
- 对数据进行GZIP压缩或解压缩
/** * 对data进行GZIP解压缩 * @param data * @return * @throws Exception */ public static String unCompress( ...
- java GZIP压缩与解压缩
1.GZIP压缩 public static byte[] compress(String str, String encoding) { if (str == null || str.length( ...
- 压缩与解压缩 gzip bzip2 tar 命令
gzip压缩与解压缩 命令 gzip -v 解压缩 gzip-d 操作如下. 压缩 .可以看到源文件有5171大小,压缩后,变成了1998大小. 解压缩 .解压缩之后可以看到,原来的man_db ...
- gzip [选项] 压缩(解压缩)
减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间.gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用. 语法:gzip ...
- Linux命令(十八) 压缩或解压缩文件和目录 gzip gunzip
目录 1.命令简介 2.常用参数介绍 3.实例 4.直达底部 命令简介 和 zip 命令类似,gzip 用于文件的压缩,gzip压缩后的文件扩展名为 ".gz",gzip默认压缩后 ...
- c#实现gzip压缩解压缩算法:byte[]字节数组,文件,字符串,数据流的压缩解压缩
转载:https://blog.csdn.net/luanpeng825485697/article/details/78165788 我测试了下压缩byte[],是可以的 using System; ...
- Python3 压缩与解压缩(zlib / gzip / bz2 / lzma / zipfile / tarfile)
本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog.csdn.net/Rozol/article/details/72672703 以下代码以Python3.6.1为例 L ...
随机推荐
- 对MySQL数据类型的认识
简述 良好的逻辑设计和物理设计是高性能系统的基石,比如反范式设计可以加快某些类型的查询同时也会影响另外一些类型的查询效率,所以我们必须重视Mysql对于数据库的设计(本文主要讲述表字段类型对于数据库性 ...
- Spring Boot 设置启动时banner
Spring Boot项目再启动的时候默认会在控制台输出一个字符banner图案,如下图: 我们可以通过下面的方法关闭启动时显示字符banner图案: 关闭banner方法一: public stat ...
- C# word 类库基本属性介绍
using System;using System.Collections.Generic;using System.Text;using Microsoft.Office.Interop.Word; ...
- 使用js写的确认提交表单确认框
js脚本 <script language="Javascript"> function validator() { if(confirm("确认要执行此操作 ...
- scjp考试准备 - 10 - 类型转换
题目为如下代码的执行结果: class Building{} public class Barn extends Building{ public static void main(String[] ...
- thrift安装及常见问题
一.安装thrift (macOS / Linux) 1. 下载thrift0.10.0源码 https://github.com/apache/thrift/releases/tag/0.10.0 ...
- SQLite 插入大量数据慢的解决方法
sqlite 插入数据很慢的原因:sqlite在没有显式使用事务的时候会为每条insert都使用事务操作,而sqlite数据库是以文件的形式存在磁盘中,就相当于每次访问时都要打开一次文件,如果对数据进 ...
- Ubuntu16.04 Kdevelop汉化及配置
关闭Kdevelop sudo apt-get install kdevelop-l10n 再打开. 字体选择 Sans Serif :style:Normal:这样更舒服且不影响中文的排版,如何改成 ...
- jsp:xpath - xml
.1 关于“/ ”和“// ”的使用“/”是表示当前文档的节点,类似 DOS 目录分割符,“//”则表示当前文档所有的节点.类似查看整个目录.(1)/authors/author:表示选择根目录下.父 ...
- appium自动化测试(一)
一. appium的引入 二. adb adb(Android Debug Brige)是用来连接安卓手机和PC端的调试桥梁,通过adb服务,在PC端命令行界面对手机或者模拟器进行全面的操作 安装: ...