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
With New cZipArchive
.AddFile App.Path & "\your_file"
.CompressArchive App.Path & "\test.zip"
End WithCompress All Files and Subfolders
With New cZipArchive
.AddFromFolder "C:\Path\To\*.*", Recursive:=True
.CompressArchive App.Path & "\archive.zip"
End WithExtract All Files from an Archive
With New cZipArchive
.OpenArchive App.Path & "\test.zip"
.Extract "C:\Path\To\extract_folder"
End WithThe 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.
With New cZipArchive
.OpenArchive App.Path & "\test.zip"
.Extract "C:\Path\To\extract_folder\new_filename", Filter:="your_file"
End WithGet Uncompressed Size of an Archive Entry
Via the FileInfo property, using the entry filename as the first parameter and zipIdxSize:
With New cZipArchive
.OpenArchive App.Path & "\test.zip"
Debug.Print .FileInfo("report.pdf", zipIdxSize)
End WithList Files in a ZIP Archive
Via the FileInfo property, using a numeric index as the first parameter:
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 WithAvailable values for the second parameter of FileInfo:
| Value | Name |
|---|---|
0 | zipIdxFileName |
1 | zipIdxAttributes |
2 | zipIdxCrc32 |
3 | zipIdxSize |
4 | zipIdxCompressedSize |
5 | zipIdxComment |
6 | zipIdxLastModified |
7 | zipIdxMethod |
8 | zipIdxOffset |
9 | zipIdxFlags |
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.
With New cZipArchive
.OpenArchive App.Path & "\test.zip"
.Extract App.Path & "\test", Password:="123456"
End WithUse the Password parameter on the AddFile method, along with the EncrStrength parameter to set the encryption mode used when creating an archive.
| EncrStrength | Mode |
|---|---|
0 | ZipCrypto (default) |
1 | AES-128 |
2 | AES-192 |
3 | AES-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.
Dim baZip() As Byte
With New cZipArchive
.AddFile ReadBinaryFile("sample.pdf"), "report.pdf"
.CompressArchive baZip
End With
WriteBinaryFile "test.zip", baZipThe Extract method also supports a byte array as the target.
Dim baOutput() As Byte
With New cZipArchive
.OpenArchive ReadBinaryFile("test.zip")
.Extract baOutput, Filter:=0 '--- only the first file in the archive
End WithTODO (Not Yet Supported)
- Deflate64 (de)compressor
- VBA7 (x64) support