ZLIB for Visual Basic


Download ZLIB for Visual Basic (26kB 24-8-97)

ZLIB

    ZLIB is a general purpose compression library developed for open use on the Web. It is the compression technique used in the new .PNG file format, and owes its heritage to PKZIP.
    ZLIB is available pre-compiled for most computers, including Win32. This allows C and C++ coders access to good compression very easily.
    More ZLIB information is available at http://www.gzip.org/index.html. and http://www.alumni.caltech.edu/~madler/ and http://www.cdrom.com/pub/infozip/zlib/
 

    ZLIB has been ported to an .OCX by Mark Nelson. If you don't want the overhead of an .ocx, you can use this zlibvb.bas file (module) to give you access to the basic routines. In order to use it, you're going to need one of the ZLIB.DLL files from the ZLIB page; I've included one of them in the .zip file. Here is the API.
 
Name Returns Params Desc
compress zlib error code
dest pointer to empty buffer for compressed data
dest_len pre-compression size of the dest buffer
src pointer to the buffer containing the raw data
src_len size of the source data
 
compresses raw data 

on return, dest_len  contains the size of the data in  the dest buffer 

make sure you allow enough room in the destination buffer; the recommended size is (source_len)*1001/1000+12 

don't forget to truncate the dest buffer down to the size returned to you in dest_len

uncompress zlib error code
dest pointer to empty buffer for uncompressed data
dest_len pointer to the pre-uncompression size of the dest buffer
src pointer to the buffer containing the compressed data
src_len size of the source data
 
uncompresses the data back to its original form 

on return, dest_len  contains the size of the data in the dest buffer 

you'll have to know how big the reconstruction buffer is going to need to be before you make this call

gzopen zlib file handle
path file name
mode either "rb" or "wb"
 
open the named file for compression read or write 

if you read from a non-zlib-compressed file, the reads will just pass the data right through

gzread number of uncompressed bytes actually read 

0 for eof 

-1 on error

file the handle from the gzopen call
buf pointer to a buffer
len size of buf
 
gzwrite the number of uncompressed bytes actually written 

0 on error

file the handle from the gzopen call
buf pointer to a buffer
len size of buf
 
gzflush zlib error number
file the handle from the gzopen call
mode flush mode
 
use a flush mode of 4 if you want to flush at the end of the file; gzclose() does the same thing 

use a flush mode of 3 to force a flush and "segment" a file; segments can be decompressed individually/independently

gclose zlib error number
file the handle from the gzopen call
 
addler32 running adler32 number
adler the running adler number
buf pointer to a buffer
len size of buf
 
calculates a running Adler32 checksum 

call with buf set to 0 to start the checksum

crc32 running crc32
crc the running adler number
buf pointer to a buffer
len size of buf
 
calculates a running crc32 checksum 

includes one's complement code 

call with buf set to 0 to start the checksum

 
The .zip file includes a .BAS file which you can include in your VB project. This will give you access to the above API. There are three versions of the API included in the .BAS file:

  1. If you want to work with strings, you can use Basic strings as your buffers
  2. If you wish, you can use Basic byte arrays as your buffers
  3. If you have a problem with the generic names "compress" and "uncompress" and "crc32", you can expose a different naming system, like ZlibCompress, ZlibUncompress and ZlibCrc32

The .zip file contains Basic test code, which serves as an illustration.



Back to my home page

Contact me by email or email