1,486
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
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
Private Const OFFSET As Long = &H8
''----------------------------------------------
''解压缩gzip
''----------------------------------------------
Public Sub UnCompressByte(ByteArray() As Byte)
Dim bufferSize As Long
Dim buffer() As Byte
Dim lReturn As Long
Dim outUsed As Long
Dim inUsed As Long
'创建解压缩后的缓存
CopyMemory bufferSize, ByteArray(0), OFFSET
bufferSize = bufferSize + (bufferSize * 0.01) + 12
ReDim buffer(bufferSize) As Byte
'创建解压缩进程
Dim contextHandle As Long: InitDecompression
CreateDecompression contextHandle, 1 '创建
'解压缩数据
lReturn = Decompress(ByVal contextHandle, ByteArray(0), UBound(ByteArray) + 1, buffer(0), bufferSize, inUsed, outUsed)
DestroyDecompression contextHandle
'删除重复的数据
ReDim Preserve ByteArray(0 To outUsed - 1)
CopyMemory ByteArray(0), buffer(0), outUsed
End Sub