VB6之借助zlib实现gzip解压缩

本文介绍了一个简单的HTTP GZIP压缩与解压方法,并提供了使用zlib.dll进行压缩和解压缩的VB代码示例。该方法适用于不支持网页GZIP压缩的Web服务器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是个简版的,可以拿来做下网页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

 

 

转载于:https://www.cnblogs.com/lichmama/p/3838067.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值