VB6解压GZIP和C#解压GZIP
2021-09-07 15:12
标签:got long 报错 declare stream boolean 0kb lin .dll VB进行GZIP解压的,DLL是系统的,如果没有点击这里下载 1 Option Explicit 2 ‘GZIP API 3 ‘-------------------------------------------------- 4 Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) 5 Private Declare Function InitDecompression Lib "gzip.dll" () As Long 6 Private Declare Function CreateDecompression Lib "gzip.dll" (ByRef context As Long, ByVal Flags As Long) As Long 7 Private Declare Function DestroyDecompression Lib "gzip.dll" (ByRef context As Long) As Long 8 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 9 ‘============================================================= 10 ‘2012-10-5 11 ‘gzip解压,返回值表示是否成功,如果成功,解压结果通过址参回传 12 ‘============================================================= 13 Public Function UnGzip(ByRef arrBit() As Byte) As Boolean 14 On Error GoTo errline 15 Dim SourceSize As Long 16 Dim buffer() As Byte 17 Dim lReturn As Long 18 Dim outUsed As Long 19 Dim inUsed As Long 20 Dim chandle As Long 21 If arrBit(0) &H1F Or arrBit(1) &H8B Or arrBit(2) &H8 Then 22 Exit Function ‘不是GZIP数据的字节流 23 End If 24 ‘获取原始长度 25 ‘GZIP格式的最后4个字节表示的是原始长度 26 ‘与最后4个字节相邻的4字节是CRC32位校验,用于比对是否和原数据匹配 27 lReturn = UBound(arrBit) - 3 28 CopyMemory SourceSize, arrBit(lReturn), 4 29 ‘重点在这里,网上有些代码计算解压存放空间用了一些奇怪的公式 30 ‘如:L = 压缩大小 * (1 + 0.01) + 12 31 ‘不知道怎么得到的,用这种方式偶尔会报错... 32 ‘这里的判断是因为:(维基)一个压缩数据集包含一系列的block(块),只要未压缩数据大小不超过65535字节,块的大小是任意的。 33 ‘GZIP基本头是10字节 34 If SourceSize > 65535 Or SourceSize