The new vbAccelerator Site - more VB and .NET Code and Controls
Source Code
3 Code Libraries &nbsp
&nbsp

Compressing and Expanding with the Freeware zLib.DLL

Compress anything in memory with this industry-strength API



NOTE: this code has been superceded by the version at the new site.




Compress-Z-It Demonstration Project

Download Code
VB5 code Download the VB5 CompressZ-It project (18kb)
VB6 code Download the VB6 CompressZ-It project (18kb)
VB6 code Download the zLib DLL (13kb)

&nbsp Before you Begin &nbsp
&nbsp This project requires zlib.dll to be placed in your Windows\System directory. zlib.dll is the freeware zLib compression DLL Make sure you have read the licensing conditions and requirements from the zLib site before using this DLL. &nbsp

&nbsp

Overview
This project from Benjamin Dowse (bendowse@dingoblue.net.au) provides a reusable DLL which allows you to compress and decompress byte arrays and strings. You can compress data in memory, or using file IO in Visual Basic you can also compress files.

ZLib is an excellent compression technique and has been re-used in many other places where a free source and patent-free method of compression is needed. One of the notable recent applications is as part of the PNG (Portable Network Graphics) file format specification. So you're in good company if you choose to use it yourself!

How to use it
First, you need to ensure zlib.dll is unzipped into your Windows\System folder. zlib.dll is a straight Win32 DLL written in C by the ZLib authors, and does not need to be registered.

Then fire up the project group in the download. The demonstration code includes the CompressZItLib DLL and a sample application, which demos compression and decompression of in-memory data and files.

The methods of the DLL are straightforward: to compress and decompress string data, use the CompressString and DecompressString functions. To compress and decompress binary data, use the CompressData and DecompressData functions and pass in the data as a byte array. Note that when you decompress data, you need to know how large the data was before it was compressed, so if you are storing in a file you will probably want to save the size as the first thing in the file. The helper properties OriginalSize and CompressedSize allow you to query information about the data, but note that when decompressing original size is a parameter, and when compressing compressed size is only valid once the data has been compressed.




TopBack to top
Source Code - What We're About!Back to Library Source Code
Source Code - What We're About!Back to Source Code

&nbsp

AboutContributeSend FeedbackPrivacy

Copyright 2000, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 1 January 2000