VB6之借助zlib实现gzip解压缩

这是个简版的,可以拿来做下网页gzip的解压缩,整好我的webserver还不支持这个,有时间了就加上。

zlib.dll下载请点击我!

模块zlib.bas的代码如下:

 1 'code by lichmam from cnblogs.com
 2 'whatfor: could be used for http-gziped compress&uncompress
 3 'API declares from zlib.dll
 4 Private Declare Function compress2 Lib "zlib.dll" (dest As Any, _
 5     destLen As Any, _
 6     src As Any, _
 7     ByVal srcLen As Long, _
 8     ByVal level As Long) As Long
 9 Private Declare Function uncompress Lib "zlib.dll" (dest As Any, _
10     destLen As Any, _
11     src As Any, _
12     ByVal srcLen As Long) As Long
13     
14 Public Function Compress(ByRef bytCompressed() As Byte, _
15     ByRef bytUnCompressed() As Byte, _
16     Optional CompressionLevel = 6&) As Long
17     '0<=CompressionLevel<=9, and default value is 6.
18     'with the number of CompressionLevel increased,
19     '   the quality, speed of compression would be better and slower.
20     'however, i'd suggest that JUST TAKE THE DEFAULT VALUE OF COMPRESSION_LEVEL.
21     Dim srcLen As Long
22     Dim destLen As Long
23     
24     srcLen = UBound(bytUnCompressed) + 1
25     destLen = srcLen * (1 + 0.01) + 12
26     ReDim bytCompressed(destLen) As Byte
27     Call compress2(bytCompressed(0), destLen, bytUnCompressed(0), srcLen, CompressionLevel)
28     Compress = destLen
29 End Function
30 
31 Public Function DeCompress(ByRef bytUnCompressed() As Byte, _
32     ByRef bytCompressed() As Byte) As Long
33 
34     Dim srcLen As Long
35     Dim destLen As Long
36     
37     srcLen = UBound(bytCompressed) + 1
38     destLen = srcLen
39     ReDim bytUnCompressed(destLen) As Byte
40     Call uncompress(bytUnCompressed(0), destLen, bytCompressed(0), srcLen)
41     DeCompress = destLen
42 End Function

 

 

posted @ 2014-07-11 16:36  lichmama  阅读(2453)  评论(0编辑  收藏  举报