GZip压缩与解压缩

news/2024/7/7 22:02:33

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, 0, 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 != -1){output.Add((byte)readByte);readByte = gs.ReadByte();}gs.Close();}ms.Close();}return output.ToArray();}}

 

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


http://lihuaxi.xjx100.cn/news/251426.html

相关文章

linux shell显示下载进度,shell脚本测试下载速度

在linux下用shell来测试下载速度&#xff0c;很实用的shell代码。代码&#xff1a;复制代码 代码示例:#!/bin/bash#date:20140210# edit: www.jquerycn.cn#used for test server download speedr_host"188.18.28.19"r_dir"/home/test0208/tmp"r_file"…

TSQL语句中的Like用法

SQL Server&#xff1a;SQL Like 的特殊用法 %&#xff1a;匹配零个及多个任意字符&#xff1b; _&#xff1a;与任意单字符匹配&#xff1b; []&#xff1a;匹配一个范围&#xff1b; [^]&#xff1a;排除一个范围 SymbolMeaninglike 5[%]5%like [_]n_nlike [a-cdf]a, b, c, d…

【组队学习】【32期】scikit-learn教程

scikit-learn教程 航路开辟者&#xff1a;江季领航员&#xff1a;李牧轩航海士&#xff1a;武帅、陈宇 基本信息 开源内容&#xff1a;&#xff1a;https://github.com/datawhalechina/machine-learning-toy-code/tree/main/ml-with-sklearn内容属性&#xff1a;公测课程内容…

LAMP兄弟连PHP课程学习笔记 第二天 PHP中使用变量

2019独角兽企业重金招聘Python工程师标准>>> 一、变量的介绍 变量&#xff1a;是指临时储存值的容器&#xff0c;这个值可以是数字或者文本或者其他组合。可以在程序使用的过程中更改。 二、变量的声明 1、如果用到的数据需要多次被调用时就声明为变量&#xff0c;P…

HSV 通道分离

// 转换成hsv cv::Mat img_h, img_s, img_v, imghsv;std::vector<cv::Mat> hsv_vec;cv::cvtColor(srcImage, imghsv, CV_BGR2HSV);cv::imshow("hsv", imghsv);cv::waitKey(0);// 分割hsv通道cv::split(imghsv, hsv_vec);img_h hsv_vec[0];img_s hsv_vec[1];i…

在c语言中逗号的作用,关于c语言中的逗号运算符???

等下。。答错了。。还需要理解一下神马是逗号表达式。。我前面说的和uuyyhhjj与delta_charlie的意思一样&#xff0c;但其实我们都搞错了。你可以自己把我们的例子都运行一下&#xff0c;看看是不是这样。下面我感觉应该是我正确的理解。逗号表达式是所有运算符中优先级最低的&…

[IoC容器Unity]第四回:使用范例

1.引言  前面几个章节介绍了Unity的基本使用&#xff0c;主要分为程序和配置文件两种方法的使用&#xff0c;可以参考一下链接&#xff0c; [IoC容器Unity]第一回&#xff1a;Unity预览[IoC容器Unity]第二回&#xff1a;Lifetime Managers生命周期[IoC容器Unity]第三回&#x…