VB进行GZIP解压的,DLL是系统的,如果没有 [点击下载]

 Option Explicit
'GZIP API
'--------------------------------------------------
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function InitDecompression Lib "gzip.dll" () As Long
Private Declare Function CreateDecompression Lib "gzip.dll" (ByRef context As Long, ByVal Flags As Long) As Long
Private Declare Function DestroyDecompression Lib "gzip.dll" (ByRef context As Long) As Long
Private Declare Function Decompress Lib "gzip.dll" (ByVal context As Long, inBytes As Any, ByVal input_size As Long, outBytes As Any, ByVal output_size As Long, ByRef input_used As Long, ByRef output_used As Long) As Long
'=============================================================
'2012-10-5
'gzip解压,返回值表示是否成功,如果成功,解压结果通过址参回传
'=============================================================
Public Function UnGzip(ByRef arrBit() As Byte) As Boolean
On Error GoTo errline
Dim SourceSize As Long
Dim buffer() As Byte
Dim lReturn As Long
Dim outUsed As Long
Dim inUsed As Long
Dim chandle As Long
If arrBit() <> &H1F Or arrBit() <> &H8B Or arrBit() <> &H8 Then
Exit Function '不是GZIP数据的字节流
End If
'获取原始长度
'GZIP格式的最后4个字节表示的是原始长度
'与最后4个字节相邻的4字节是CRC32位校验,用于比对是否和原数据匹配
lReturn = UBound(arrBit) -
CopyMemory SourceSize, arrBit(lReturn),
'重点在这里,网上有些代码计算解压存放空间用了一些奇怪的公式
'如:L = 压缩大小 * (1 + 0.01) + 12
'不知道怎么得到的,用这种方式偶尔会报错...
'这里的判断是因为:(维基)一个压缩数据集包含一系列的block(块),只要未压缩数据大小不超过65535字节,块的大小是任意的。
'GZIP基本头是10字节
If SourceSize > Or SourceSize < Then
'测试用,申请100KB空间尝试一下
'SourceSize = 102400
Exit Function
Else
SourceSize = SourceSize +
End If
ReDim buffer(SourceSize) As Byte
'创建解压缩进程
InitDecompression
CreateDecompression chandle, '创建
'解压缩数据
Decompress ByVal chandle, arrBit(), UBound(arrBit) + , buffer(), SourceSize + , inUsed, outUsed
If outUsed <> Then
DestroyDecompression chandle
ReDim arrBit(outUsed - )
CopyMemory arrBit(), buffer(), outUsed
UnGzip = True
End If
Exit Function
errline:
End Function

C#进行GZIP压缩和解压,参考[MSDN]

 public static byte[] GZipCompress(byte[] buffer)
{
using (MemoryStream ms = new MemoryStream())
{
GZipStream Compress = new GZipStream(ms, CompressionMode.Compress);
Compress.Write(buffer, , buffer.Length);
Compress.Close();
return ms.ToArray();
}
}
public static byte[] GZipDecompress(byte[] buffer)
{
using (MemoryStream tempMs = new MemoryStream())
{
using (MemoryStream ms = new MemoryStream(buffer))
{
GZipStream Decompress = new GZipStream(ms, CompressionMode.Decompress);
Decompress.CopyTo(tempMs);
Decompress.Close();
return tempMs.ToArray();
}
}
}

VB6进行GZIP解压&C#进行GZIP压缩和解压的更多相关文章

  1. C#实现通过Gzip来对数据进行压缩和解压

    C#实现通过Gzip来对数据进行压缩和解压 internal static byte[] Compress(byte[] data) { using (var compressedStream = n ...

  2. 使用pako.js实现gzip的压缩和解压

    poko.js可至Github下载:https://github.com/nodeca/pako 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...

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

    public class GzipUtils { /** * 对字符串进行gzip压缩 * @param data * @return * @throws IOException */ public ...

  4. linux学习之路第七天(压缩和解压类指令详解)

    压缩和解压类 1.gzip/gunzip 指令 gzip 指令用于压缩文件, gunzip用于解压的 基本语法 gzip 文件 (功能描述:压缩文件,指令将文件压缩成*.gz文件) gunzip 文件 ...

  5. linux常用命令:4文件压缩和解压命令

    文件压缩和解压命令 压缩命令:gzip.tar[-czf].zip.bzip2 解压缩命令:gunzip.tar[-xzf].unzip.bunzip2 1. 命令名称:gzip 命令英文原意:GNU ...

  6. .net文件压缩和解压及中文文件夹名称乱码问题

    /**************************注释区域内为引用http://www.cnblogs.com/zhaozhan/archive/2012/05/28/2520701.html的博 ...

  7. Linux下的压缩和解压

    1. gzip, bzip2 能否直接压缩目录呢?不可以 2. 请快速写出,使用gzip和bzip2压缩和解压一个文件的命令.压缩:gzip 1.txt bzip2 1.txt解压:gzip -d 1 ...

  8. Linux下tar bz gz等压缩包的压缩和解压

    Linux下用户经常需要备份计算机系统中的数据,为了节省存储空间,常常将备份文件进行压缩,本文是对压缩和解压命令的大致总结 .tar.gz  解压:tar zxvf FileName.tar.gz  ...

  9. Linux下tar bz gz等压缩包的压缩和解压【转】

    Linux下用户经常需要备份计算机系统中的数据,为了节省存储空间,常常将备份文件进行压缩,本文是对压缩和解压命令的大致总结 .tar.gz  解压:tar zxvf FileName.tar.gz  ...

随机推荐

  1. Linux的快捷键一

  2. windows安装解压版mysql

    记录下用批处理安装mysql5.7.18的过程与踩到的坑 先在安装目录新建文件my.ini [mysql] default-character-set=utf8 basedir=TODO datadi ...

  3. Win2012 R2安装 sqlserver2017 Express

    1.在官网下载 安装一直跟着点下一步就好了 到登录验证那步,给sa设置一个密码 2.下载管理工具 SQL Server Management Studio 17 https://docs.micros ...

  4. ubuntu 下开机启动项修复(进不去windows系统)

    1.终端输入: sudo gedit /etc/default/grub 2.更改: GRUB_DEFAULT=0    改为  GRUB_DEFAULT=4 GRUB_TIMEOUT=10  改为 ...

  5. 20175333曹雅坤 实验二 Java面向对象程序设计

    实验二 Java面向对象程序设计 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计 ...

  6. mysql插入大数据

    /*部门表*/ CREATE TABLE dept( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, /*id*/ deptno MEDIUMINT UNSIG ...

  7. window mysql8.0 zip版本安装

    第一步下载安装包 官方下载地址:https://dev.mysql.com/downloads/mysql/ 解压到D盘目录中D://db 第二步配置环境变量 编辑path内容 添加mysql地址 第 ...

  8. No grammar constraints (DTD or XML Schema) referenced in the document.

    问题描述 web.xml 使用 Servlet4.0 版本,No grammar constraints (DTD or XML Schema) referenced in the document. ...

  9. centOS设置开机自启

    原文:https://blog.csdn.net/txz317/article/details/49683439 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHat其他系统下 ...

  10. django ajax 及批量插入数据 分页器

    ``` Ajax 前端朝后端发送请求都有哪些方式 a标签href GET请求 浏览器输入url GET请求 form表单 GET/POST请求 Ajax GET/POST请求 前端朝后端发送数据的编码 ...