贴出GZip.dll里面API声明,欢迎大虾们一起看看,顺便散分

yinweihong 2008-05-05 10:17:55
翻箱倒柜,在这里找到
http://www.google.com/codesearch?hl=en&q=show:IQaFsxIyO24:OxRSJga7rN0:kHBOK1EXgjc&sa=N&ct=rd&cs_p=http://lolsws.tripod.com&cs_f=/0321113594_ch06lev1sec1.html-002&start=1

c#和vb.net的声明我就不贴了,调试后发现在c#和vb.net中都能正常压缩解压缩长度<N的字符串,更长的都被截断了~ 要看代码的请跟贴,呵呵

VB里面我这样声明的
Public Declare Function InitDecompression Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" () As Long
Public Declare Function InitCompression Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" () As Long

Public Declare Function CreateDecompression Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" (ByRef context As Long, ByVal flags As Long) As Long
Public Declare Function CreateCompression Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" (ByRef context As Long, ByVal flags As Long) As Long

Public Declare Function ResetDecompression Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" (ByVal context As Long) As Long
Public Declare Function ResetCompression Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" (ByVal context As Long) As Long

Public Declare Function DestroyDecompression Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" (ByRef context As Long) As Long
Public Declare Function DestroyCompression Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" (ByRef context As Long) As Long

Public Declare Function Decompress Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" (ByVal context As Long, ByVal inBytes As Long, ByVal input_size As Long, ByVal outBytes As Long, ByVal output_size As Long, ByVal input_used As Long, ByVal output_used As Long) As Long
Public Declare Function Compress Lib "c:\\windows\\system32\\inetsrv\\gzip.dll" (ByVal context As Long, ByVal inBytes As Long, ByVal input_size As Long, ByVal outBytes As Long, ByVal output_size As Long, ByRef input_used As Long, ByRef output_used As Long, ByVal compressionLevel As Long) As Long
到现在还没调试出来过,一个字符都没有,呵呵

大虾们一起讨论讨论,尤其是Compress 和Decompress 这两函数

欢迎接分~~~!!!!




...全文
2032 69 打赏 收藏 转发到动态 举报
写回复
用AI写文章
69 条回复
切换为时间正序
请发表友善的回复…
发表回复
ColorfulHouse 2011-08-20
  • 打赏
  • 举报
回复
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


这个解压没问题,压缩死活整不出来
spotty2008 2011-01-18
  • 打赏
  • 举报
回复
正在研究中
glowing_yu 2009-11-01
  • 打赏
  • 举报
回复
学习
glowing_yu 2009-11-01
  • 打赏
  • 举报
回复
学习
kxscr1 2009-09-22
  • 打赏
  • 举报
回复
?????
可西哥 2008-10-01
  • 打赏
  • 举报
回复
书林很能挖贴啊,跟上!
eslbs 2008-10-01
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20080518/15/810e9a05-c61e-4cca-a2f0-2a1b12f11176.html?seed=1954492383#top
yinweihong 发表于:2008-05-23 23:52:3654楼 得分:0
好了,ZLIB的来了,贴代码,星期天晚上回来揭贴,理论上只要你memory足够大,可以压缩解压缩4GB的字符串
本地测试,18.8 MB (19,815,840 字节)大小的字符串,得到压缩后字节流大小94.5 KB (96,784 字节)
压缩和计算CRC时间
incrc = 0x88BD9A06
0.6003s
解压缩和计算解压缩后的CRC的时间,用的是未知原字节流大小,先计算推测解压缩需要的缓存区大小,然后再解压缩
如果已知原字节流长度再解压缩的话,更快
outcrc = 0x88BD9A06
0.4434s

压缩后和还原后的CRC32 一致,说明得到的字节流正确

模块:
Option Explicit
Private Declare Function compressAPI Lib "ZLibWAPI.dll" Alias "compress" (ByRef dest As Any, ByRef destLen As Long, ByRef Source As Any, ByVal sourceLen As Long) As Long
Private Declare Function compressBound Lib "ZLibWAPI.dll" (ByVal sourceLen As Long) As Long
Private Declare Function uncompressAPI Lib "ZLibWAPI.dll" Alias "uncompress" (ByRef dest As Any, ByRef destLen As Long, ByRef Source As Any, ByVal sourceLen As Long) As Long
Private Declare Function adler32 Lib "ZLibWAPI.dll" (ByVal adler As Long, ByRef buf As Any, ByVal length As Long) As Long
Private Declare Function crc32 Lib "ZLibWAPI.dll" (ByVal crc As Long, ByRef buf As Any, ByVal length As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)
Public Const Z_OK As Long = &H0
Public Const Z_ERROR As Long = -&H1
Public Const Z_BUF_ERROR As Long = -&H5
Private Sub Main()
Form1.Show
End Sub
Public Function compress(ByRef inBytes() As Byte, ByVal BufferSize As Long, ByRef incrc As Long, ByRef outBytes() As Byte) As Long
If BufferSize > 0 Then
incrc = crc32(crc32(0, ByVal 0&, 0), inBytes(0), BufferSize)

Dim outLength As Long
outLength = compressBound(BufferSize)

ReDim outBytes(0 To outLength - 1) As Byte

Dim ret As Long
ret = compressAPI(outBytes(0), outLength, inBytes(0), BufferSize)
Erase inBytes
If ret = Z_OK Then
ReDim Preserve outBytes(0 To outLength - 1)
compress = ret
Else
compress = Z_ERROR
End If
End If
End Function
Public Function uncompress(ByRef inBytes() As Byte, ByVal BufferSize As Long, ByRef outcrc As Long, ByRef outBytes() As Byte) As Long
ReDim outBytes(0 To (BufferSize - 1)) As Byte
Dim ret As Long
ret = uncompressAPI(outBytes(0), BufferSize, inBytes(0), UBound(inBytes) + 1)
Erase inBytes
If (ret = Z_OK) Then
ReDim Preserve outBytes(0 To (BufferSize - 1))
outcrc = crc32(crc32(0, ByVal 0&, 0), outBytes(0), BufferSize)
uncompress = Z_OK
Else
uncompress = Z_ERROR
End If
End Function
Public Function uncompressEx(ByRef inBytes() As Byte, ByRef outcrc As Long, ByRef outBytes() As Byte, ByVal multiple As Integer) As Long
Dim inLength As Long
inLength = UBound(inBytes) + 1
Dim gzSize As Long
gzSize = multiple * inLength
Dim outBuffer As Long
Dim ret As Long
Do
outBuffer = gzSize
ReDim outBytes(0 To (outBuffer - 1)) As Byte
ret = uncompressAPI(outBytes(0), outBuffer, inBytes(0), inLength)
gzSize = gzSize + inLength
Loop While ret = Z_BUF_ERROR
Erase inBytes
If (ret = Z_OK) Then
ReDim Preserve outBytes(0 To (outBuffer - 1))
outcrc = crc32(crc32(0, ByVal 0&, 0), outBytes(0), outBuffer)
uncompressEx = Z_OK
Else
uncompressEx = Z_ERROR
End If
End Function
Public Function fileToBuffer(ByVal inFile As String, ByRef outBuffer() As Byte) As Long
' make sure file exists
If (Not fileExist(inFile)) Then Exit Function
Dim FNum As Integer
FNum = FreeFile()

Open inFile For Binary Access Read Lock Write As #FNum
ReDim refBuffer(0 To (LOF(FNum) - 1)) As Byte ' allocate buffer
Get #FNum, , refBuffer() ' read file data into buffer
Close #FNum

' return array
outBuffer = refBuffer
fileToBuffer = UBound(refBuffer) + 1
End Function
Public Function flushToFile(ByVal inFile As String, ByRef outBuffer() As Byte) As Long
If (fileExist(inFile)) Then Kill inFile
Open inFile For Output As #1: Close #1 'create empty file

Dim FNum As Integer
FNum = FreeFile() ' get a free file handle
Open inFile For Binary Access Write As #FNum
Put #FNum, , outBuffer() 'flush buffer to local file
Close #FNum
End Function
Private Sub ArrayCopy(ByRef arrSrc() As Byte, ByVal srcPos As Long, ByRef arrDest() As Byte, ByVal destPos As Long, ByVal length As Long)
'make sure srcPos >= LBound(arrSrc) and srcPos + length < UBound(arrSrc) +1
'make sure destPos >= LBound(arrDest) and destPos + length < UBound(arrDest) +1
CopyMemory arrDest(destPos), arrSrc(srcPos), length
End Sub
Private Function WriteBuffer(buffer() As Byte, ByVal srcPos As Long, ByVal length As Long) As Byte()
ReDim retBuffer(length - 1) As Byte
CopyMemory retBuffer(0), buffer(srcPos), length
WriteBuffer = retBuffer
End Function
Private Function fileExist(ByRef inFile As String) As Boolean
On Error Resume Next
fileExist = CBool(FileLen(inFile) + 1)
End Function
时间类
Option Explicit

Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long

Private m_Frequency As Currency
Private m_Start As Currency
Private m_Now As Currency
Private m_Available As Boolean

Private Sub Class_Initialize()
m_Available = (QueryPerformanceFrequency(m_Frequency) <> 0)
If Not m_Available Then
Debug.Print "Performance Counter not available"
End If
End Sub
Friend Function Elapsed() As Double
QueryPerformanceCounter m_Now
If m_Available Then
Elapsed = 1000 * (m_Now - m_Start) / m_Frequency
End If
End Function
Friend Sub Reset()
QueryPerformanceCounter m_Start
End Sub
窗体
Option Explicit

Private Sub Command1_Click()
Dim inFile As String
inFile = App.Path & "\inBytes.in"
Dim tmpFile As String
tmpFile = App.Path & "\Bytes.tmp"
Dim outFile As String
outFile = App.Path & "\outBytes.out"

Dim origSize As Long, inBytes() As Byte
Dim ct1 As New clsTiming
ct1.Reset
origSize = fileToBuffer(inFile, inBytes())

Dim incrc As Long, outBytes() As Byte
If Z_OK = compress(inBytes, origSize, incrc, outBytes) Then
flushToFile tmpFile, outBytes
Debug.Print "incrc = 0x" & Hex(incrc)
End If
Erase inBytes
Debug.Print Format$(ct1.Elapsed / 1000, "0.0000") & "s"

Dim Ct2 As New clsTiming
Ct2.Reset
Dim outcrc As Long, origBytes() As Byte
'已知原字节流大小解压缩
' If Z_OK = uncompress(outBytes, origSize, outcrc, origBytes) Then
' Debug.Print "outcrc = 0x" & Hex(outcrc)
' End If
'未知原字节流大小解压缩
If Z_OK = uncompressEx(outBytes, outcrc, origBytes, 1024) Then
Debug.Print "outcrc = 0x" & Hex(outcrc)
End If
Erase outBytes
flushToFile outFile, origBytes
Erase origBytes
Debug.Print Format$(Ct2.Elapsed / 1000, "0.0000") & "s"
End Sub

yinweihong 发表于:2008-05-23 23:54:0255楼 得分:0
转贴的话麻烦注明一下,谢谢
ZLibWAPI.dll 这个文件就是winImage那里下的

好帖子做个标记
不知道楼主解决问题没有,虽然结贴了……
yuanweiyw 2008-07-16
  • 打赏
  • 举报
回复
gzip.dll 的版本号为:6.0.2600.2180 存在上函数(InitCompression、 CreateCompression 、 Compress 、DestroyCompression、InitDecompression、CreateDecompression、Decompress、DestroyDecompression )下载地址:http://www.dllxia.cn/soft/7/2007/dll_922.html。
yuanweiyw 2008-07-15
  • 打赏
  • 举报
回复
我的,gzip.dll 的版本号为:6.0.3790.3959 只包括压缩数据所用的函数(InitCompression、 CreateCompression 、 Compress 、DestroyCompression) ;解压缩函数不存在(InitDecompression、CreateDecompression、Decompress、DestroyDecompression )声名后找不到入口点。请问哪个朋友解决了这个问题,或有其它GZIP.DLL版的,发给我一份。我在这先谢谢了,我的QQ:69798459 我的EMAIL:YUANWEIYW@SOHU.COM
现在还是人类 2008-05-25
  • 打赏
  • 举报
回复
接分
m60a1 2008-05-25
  • 打赏
  • 举报
回复
学习一下,,
yinweihong 2008-05-23
  • 打赏
  • 举报
回复
ZLIB的代码贴错了地方,贴到这里去了...

http://topic.csdn.net/u/20080518/15/810e9a05-c61e-4cca-a2f0-2a1b12f11176.html?seed=1954492383
yinweihong 2008-05-15
  • 打赏
  • 举报
回复
用zlib.dll实现了最大65535个字符的压缩解压缩代码,好象低版本的zlib.dll的限制? 再多试试~~


希望还是了解IIS GZIP的朋友帮帮忙,指点一下
舉杯邀明月 2008-05-09
  • 打赏
  • 举报
回复
Mark.........
舉杯邀明月 2008-05-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 Tiger_Zhao 的回复:]
首先,VB字符串中字符“\”不是转义符,所以声明路径中不需要用双斜杠“\\”。
[/Quote]

Ding............
CathySun118 2008-05-09
  • 打赏
  • 举报
回复
谢谢
xingyerj 2008-05-09
  • 打赏
  • 举报
回复
Option Explicit
Public WithEvents owinhttp As WinHttp.WinHttpRequest
Public Function StartWork() As Boolean
Dim FileNo As Integer
With owinhttp
.SetRequestHeader "accept-encoding", "gzip,deflate"
Call .Open("GET", "http://www.sina.com.cn/", True) .Option(WinHttpRequestOption_UserAgentString) = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"

.SetRequestHeader "accept", "*/*"
.SetRequestHeader "accept-language", "en-us"
.SetRequestHeader "accept-encoding", "gzip,deflate"
.SetRequestHeader "connection", "Keep-Alive"
.SetRequestHeader "cache-control", "no-cache"
.SetTimeouts 90000, 15000, 80000, 90000
owinhttp.Send

Do While Not .WaitForResponse(1)
DoEvents
Loop
Dim strContent As String

.ResponseText StartWork = True
End Function
eslbs 2008-05-09
  • 打赏
  • 举报
回复
gz
yinweihong 2008-05-09
  • 打赏
  • 举报
回复
还有buffer多大,呵呵~~
yinweihong 2008-05-09
  • 打赏
  • 举报
回复
这个东西我也知道~

我就是想试试gzip,呵呵,,,,你说的测试,是多大的数据? level是几的?
加载更多回复(49)

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧