zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Spring Boot 配置加载顺序详解
    JVM总结篇
    nginx负载均衡的策略
    布隆过滤器的方式解决缓存穿透问题
    Spring Cloud Eureka自我保护机制(服务无法剔除)
    缓存穿透,缓存击穿,缓存雪崩解决方案分析
    高并发秒杀系统总结
    Linux环境进程间通信(一)
    HDU 1695 GCD(容斥定理)
    数据结构精要------冒泡与直接排序算法
  • 原文地址:https://www.cnblogs.com/lichmama/p/3838067.html
Copyright © 2011-2022 走看看