C# GZip 压缩 / 解压
public static byte[] GZipCompress(byte[] bytes){using (MemoryStream ms = new MemoryStream()){using (GZipStream zs = new GZipStream(ms, CompressionMode.Compress))zs.Write(bytes, 0, bytes.Length);return ms.ToArray();}}
public static byte[] GZipDecompress(byte[] bytes){using (MemoryStream ms = new MemoryStream(bytes)){using (GZipStream zs = new GZipStream(ms, CompressionMode.Decompress)){byte[] buffer = new byte[512];MemoryStream buf = new MemoryStream();for (int offset; (offset = zs.Read(buffer, 0, 512)) > 0;)buf.Write(buffer, 0, offset);return buf.ToArray();}}}
public byte[] GZipCompress(byte[] bytes){int hContext = 0; // 正文句柄int input_used = 0; // 未压缩尺寸int output_used = 0; // 压缩后尺寸InitCompression(); // 初始化压缩CreateCompression(ref hContext, GZIP_LVL); // 创建压缩正文byte[] buffer = new byte[512]; // 压缩缓冲区if (Compress(hContext, bytes, bytes.Length, buffer, 512, ref input_used, ref output_used, GZIP_LVL) != 0)Console.WriteLine("error"); // 压缩失败DestroyCompression(hContext); // 销毁正文对象return buffer;}
public byte[] GZipDecompress(byte[] bytes){int hContext = 0; // 正文句柄int input_used = 0; // 输入尺寸int output_used = 0; // 输出尺寸InitCompression(); // 初始化解压CreateCompression(ref hContext, GZIP_LVL); // 创建解压正文byte[] buffer = new byte[512]; // 解压缓冲区if (Decompress(hContext, bytes, bytes.Length, buffer, 512, ref input_used, ref output_used) != 0)Console.WriteLine("error"); // 解压失败DestroyCompression(hContext); // 销毁正文对象return buffer;}
C# GZip 压缩 / 解压相关推荐
- GZip 压缩解压 --- Pako 的压缩解压
一.GZip压缩解压 package java调用JS;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream ...
- 字符串GZIP压缩解压
c# /// <summary>/// 字符串压缩解压/// </summary>public class Zipper{public static string Compre ...
- Linux gzip压缩/解压 *.gz文件详解
gzip 是linux中常见的压缩/解压工具,最常见的使用对象是*.gz格式的文件,这里简单介绍下它最常见的用法, GZIP(1) General Commands Manual GZIP(1) NA ...
- java gzip 压缩解压工具类
因为觉得简单,本想抱着百度直接拿过来用的心态,结果发现网上的代码都转载自同一份,且埋了一个坑,你不仔细去梳理,很难发现. mark下需要注意的两点: 1. 编码/解码,压缩/解压缩是成对出现的 编码: ...
- gzip 压缩解压代码示例
#include <zlib.h> #include <iostream> #include <stdint.h> #include <string.h> ...
- python3 gzip 压缩/解压
import gzip t = gzip.compress('{"key":value""}'.encode())print(gzip.decompress(t ...
- Ubuntu使用gzip与bzip2与rar和tar压缩解压
目录 1.gzip压缩解压 2.bzip2压缩解压 3.rar压缩解压 tar归档压缩与解压包 1.gzip压缩解压 因为都是系统自带的我们不需要安装: ls 看一下目录当前的文件,创建一个 touc ...
- java 使用gzip压缩和解压 传输文件必备
java gzip 压缩解压工具类,开箱即用 gzip原理看我另外一篇介绍 压缩效果直接看图: package com.yeahmobi.datacheck.util;import java.io.* ...
- python压缩文件tar_python 实现tar文件压缩解压的实例详解
python 实现tar文件压缩解压的实例详解 python 实现tar文件压缩解压的实例详解 压缩文件: import tarfile import os def tar(fname): t = t ...
最新文章
- 「它将改变一切」,DeepMind AI解决生物学50年来重大挑战,破解蛋白质分子折叠问题...
- 凯文·凯利:下一个5000天的12个必然趋势!
- 浅谈优化SQLServer数据库服务器内存配置的策略
- CentOS7.6 MySQL8环境搭建 配置远程登录 字符集UTF8 简单密码
- JAVA基础进阶day01
- 工作42:可以不参考原型
- C#笔记(五):文件和流
- FreeSql 访问 Oracle 解决大小写问题
- hdu 2523 SORT AGAIN
- NTP组播模式配置和日志信息发送到Linux日志主机的配置
- UOS安装谷歌浏览器并设置中文
- SOME/IP 协议介绍
- 苹果id注册邮箱方法
- 彻底删除vmware
- 【组合逻辑电路】——通用译码器
- ADO.NET如何读取Excel(转自晓风残月)
- andriod 连接数据库(MySQL)
- 微信支付服务商,可视化进件特约商户
- 用友BIP对接外部旺店通企业版奇门系统
- GifCam – 更好用的 gif 动画录制/剪辑工具