Skip to content

cZipArchive

A pure VB6 single-class library for ZIP archive management.

Open source: https://github.com/wqweto/ZipArchive Author: wqweto@gmail.com License: MIT

Usage

Just add cZipArchive.cls to your project, then use it like this:

Simple Compression

vb
With New cZipArchive
    .AddFile App.Path & "\your_file"
    .CompressArchive App.Path & "\test.zip"
End With

Compress All Files and Subfolders

vb
With New cZipArchive
    .AddFromFolder "C:\Path\To\*.*", Recursive:=True
    .CompressArchive App.Path & "\archive.zip"
End With

Extract All Files from an Archive

vb
With New cZipArchive
    .OpenArchive App.Path & "\test.zip"
    .Extract "C:\Path\To\extract_folder"
End With

The Extract method can filter by file mask (e.g. Filter:="*.doc"), file index (e.g. Filter:=15), or a Boolean array (setting indexes to extract to True).

Extract a Single File to a Specified Filename

OutputTarget can include the target new_filename, used to rename when extracting a specific file from the archive.

vb
With New cZipArchive
    .OpenArchive App.Path & "\test.zip"
    .Extract "C:\Path\To\extract_folder\new_filename", Filter:="your_file"
End With

Get Uncompressed Size of an Archive Entry

Via the FileInfo property, using the entry filename as the first parameter and zipIdxSize:

vb
With New cZipArchive
    .OpenArchive App.Path & "\test.zip"
    Debug.Print .FileInfo("report.pdf", zipIdxSize)
End With

List Files in a ZIP Archive

Via the FileInfo property, using a numeric index as the first parameter:

vb
Dim lIdx As Long
With New cZipArchive
    .OpenArchive App.Path & "\test.zip"
    For lIdx = 0 To .FileCount - 1
        Debug.Print "FileName=" & .FileInfo(lIdx, zipIdxFileName) & ", Size=" & .FileInfo(lIdx, zipIdxSize)
    Next
End With

Available values for the second parameter of FileInfo:

ValueName
0zipIdxFileName
1zipIdxAttributes
2zipIdxCrc32
3zipIdxSize
4zipIdxCompressedSize
5zipIdxComment
6zipIdxLastModified
7zipIdxMethod
8zipIdxOffset
9zipIdxFlags

Encryption Support

Make sure to set the conditional compilation argument ZIP_CRYPTO = 1 in the "Make" tab of your project properties to compile encryption support from source. By default, encryption support is not compiled to reduce the final executable size.

vb
With New cZipArchive
    .OpenArchive App.Path & "\test.zip"
    .Extract App.Path & "\test", Password:="123456"
End With

Use the Password parameter on the AddFile method, along with the EncrStrength parameter to set the encryption mode used when creating an archive.

EncrStrengthMode
0ZipCrypto (default)
1AES-128
2AES-192
3AES-256 (recommended)

Note: The default ZipCrypto encryption is weak, but it is the only option compatible with Windows Explorer's built-in zip folder support.

Memory Operations

The example utility function ReadBinaryFile in /test/basic/Form1.frm returns a byte array of file contents.

vb
Dim baZip() As Byte
With New cZipArchive
    .AddFile ReadBinaryFile("sample.pdf"), "report.pdf"
    .CompressArchive baZip
End With
WriteBinaryFile "test.zip", baZip

The Extract method also supports a byte array as the target.

vb
Dim baOutput() As Byte
With New cZipArchive
    .OpenArchive ReadBinaryFile("test.zip")
    .Extract baOutput, Filter:=0    '--- only the first file in the archive
End With

TODO (Not Yet Supported)

  • Deflate64 (de)compressor
  • VBA7 (x64) support

VB6 and LOGO copyright of Microsoft Corporation