Using zip files with Blitz Basic
How to use zip files within Blitz Basic applications. Open and create archives and compress your data.
Zip files are one of the most common compression formats around, and are a great way of storing files. Using the userlib functionality of BlitzPlus and Blitz3D, it’s now possible to access and manipulate zip files from within your Blitz applications. This can be useful for packing your media, as well as compressing network data.
This article will show you the following:
- What files you need to use zip files in Blitz, and how to install them.
- How to open an archive file and find out what files it contains.
- How to extract a file from an archive.
- How to create a new zip file and add files to it.
- How to compress and uncompress Blitz banks.
What will you need?
Blitz.ZipApi — A free library that you can include in your Blitz project. It comes with everything you need to use zip functionality within Blitz.
Installing the files
Once you’ve downloaded the library, you’ll need to copy “zlibwapi.dll” and “zlibwapi.decls” to the appropriate “userlibs” folder so that you can use the userlib functions in your application. This will be something similar to “c:\program files\blitzplus\userlibs\”. The userlib file is fully documented and has XML comments for use with Protean IDE.
You’re now able to use simple zip functions, but if you’d like to get easier access to some of the more common functions, you should include the following into your project:
- Blitz_File_ZipApi.bb — Helper functions for using zip files in Blitz.
- Blitz_File_FileName.bb — A few functions for manipulating file names. Use them to get a directory name, file name and extensions from a string.
- Blitz_Basic_Bank.bb — PeekString and PokeString functions.
All of these files are included in the Blitz.ZipApi distribution, along with full documentation in HTML format.
How it works
The zip library works in a similar fashion to the standard Blitz file functions. Before a file can be read from it should be opened with ZipApi_Open, and once finished with it should be closed with ZipApi_Close. Files to be written to should be opened with ZipApi_CreateZip and closed with ZipApi_CloseZip.
Fully documented examples are included with the library, and are also available online.

No CommentsComments Feed