Zip Chilkat2 Perl Reference Documentation
Chilkat2::Zip
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Chilkat.Zip
Add files, directories, strings, byte arrays,
Open archives from disk, memory,
Use options such as
Extract all files, matching entries, newer files, or flatten all output
into a single directory.
Work with WinZip-compatible AES encryption and legacy Zip 2.0 password
protection.
ZIP64 is used automatically when older ZIP limits are exceeded.
For an extended overview, see
Zip Class Overview.
Create, read, modify, encrypt, and extract ZIP archives.
Chilkat.Zip provides a comprehensive API for working with ZIP
archives from files, memory, BinData, embedded resources, and
Windows self-extracting EXEs. It can create new archives, open existing ZIPs,
add files or in-memory data, inspect entries, extract selectively, and write
the final archive to disk or memory.
Create ZIP archives
BinData, and
StringBuilder content.
Open ZIPs from many sources
BinData, embedded Windows
resources, or Chilkat-created self-extracting EXEs.
Control stored paths
AppendFromDir, DiscardPaths,
PathPrefix, and saveExtraPath.
Extract selectively
Encryption support
Large archive support
WriteZip,
WriteZipAndClose, WriteBd, or
WriteToMemory is called.
Object Creation
use Chilkat2;
my $zip = Chilkat2::Zip->new;
# or set properties (and RaiseError) at creation:
# my $zip = Chilkat2::Zip->new(VerboseLogging => 1, RaiseError => 1);Creates the object. The optional pairs set writable properties (and RaiseError) in order, as if set one by one; an unknown or read-only name croaks. use Chilkat2; loads every class; the Chilkat2/Zip.pm file holds only this class's documentation (perldoc Chilkat2::Zip).
Perl frees the object when its last reference goes (undef $zip, or the variable going out of scope); there is nothing to close. Objects returned by methods are independent and freed the same way. The class may be subclassed (use parent -norequire, 'Chilkat2::Zip';): an object is a blessed hash reference whose hash is free for the subclass's own fields.
When false (the default), a method that fails returns false (or undef), and the reason is in LastErrorText. When true, it dies with a Chilkat2::Error instead, as DBI does with its RaiseError. Objects returned by a method inherit the value of the object that returned them.
Errors
A Chilkat2::Error stringifies to the failed call's full LastErrorText, and has the methods text, class ('Chilkat2::Zip'), method (the method name) and object. Methods that look something up and find nothing return undef without dying (each such method says so), methods that answer a question (HasMember, IsUnlocked, ...) return a plain boolean, and property reads and writes never fail for Chilkat reasons.
Misuse always croaks, with your file and line, whatever RaiseError is: a wrong number of arguments, a reference or undef where a string or number is expected, an object of the wrong class, an out-of-range integer, a string containing a NUL character, a wide character in a byte string, or a write to a read-only property.
Strings are Perl character strings in both directions (length, regexes and :encoding layers see characters); binary data (BinData) is a byte string. Unlocking: call Chilkat2::Global->new->UnlockBundle('...') once at startup.
Properties
AbortCurrent
my $boolVal = $zip->AbortCurrent;
$zip->AbortCurrent($boolVal);
Stops the currently executing operation when set to .1
- Used to cancel long-running operations such as compression or extraction.
- Can be triggered from another thread.
- Automatically resets to
after the operation stops.0
AppendFromDir
my $strVal = $zip->AppendFromDir;
$zip->AppendFromDir($strVal);
Specifies a base directory when adding files to the ZIP.
- This portion of the path is not included in stored ZIP entry paths.
- Useful for controlling relative paths inside the archive.
For example, to add all files under c:/abc/123/myAppDir, this property could be set to c:/abc/123, and myAppDir/* would be passed to AppendFiles.
The path stored in the ZIP would begin with myAppDir/.
AutoRun
my $strVal = $zip->AutoRun;
$zip->AutoRun($strVal);
(Windows only, for creating self-extracting EXE's)
Specifies the name of an executable inside a self-extracting EXE that runs automatically after extraction.
topAutoRunParams
my $strVal = $zip->AutoRunParams;
$zip->AutoRunParams($strVal);
(Windows only, for creating self-extracting EXE's)
Command-line arguments passed to the AutoRun executable.
AutoTemp
my $boolVal = $zip->AutoTemp;
$zip->AutoTemp($boolVal);
(Windows only, for creating self-extracting EXE's)
If , the EXE being created will automatically select and create a temporary directory for unzipping.1
This property is often used together with AutoRun to create a self-extracting EXE that automatically unzips to a temporary directory and runs a setup program, such as setup.exe, without user interaction.
Note: To create a self-extracting EXE with no user interaction, set the following properties:
ExeSilentProgress =0
ExeNoInterface =1
ExeFinishNotifier =0
The default value is .0
CaseSensitive
my $boolVal = $zip->CaseSensitive;
$zip->CaseSensitive($boolVal);
Controls whether filename matching is case-sensitive.
- Affects methods such as
EntryMatchingandUnzipMatching. - Default:
0
ClearArchiveAttribute
my $boolVal = $zip->ClearArchiveAttribute;
$zip->ClearArchiveAttribute($boolVal);
(Windows only)
If , clears the Windows archive attribute after files are successfully added to the ZIP.1
The archive attribute indicates that a file has changed since the last backup.
The default value is .0
ClearReadOnlyAttr
my $boolVal = $zip->ClearReadOnlyAttr;
$zip->ClearReadOnlyAttr($boolVal);
If , removes the read-only attribute from extracted files.1
If , the read-only attribute remains unchanged.0
The default value is .0
Comment
my $strVal = $zip->Comment;
$zip->Comment($strVal);
DebugLogFilePath
my $strVal = $zip->DebugLogFilePath;
$zip->DebugLogFilePath($strVal);
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
DecryptPassword
my $strVal = $zip->DecryptPassword;
$zip->DecryptPassword($strVal);
Password used to extract encrypted ZIP archives.
- Required to unzip encrypted entries.
- Encrypted ZIP files may still be opened without a password, but their contents cannot be extracted until the correct password is provided.
The default value is the empty string.
topDiscardPaths
my $boolVal = $zip->DiscardPaths;
$zip->DiscardPaths($boolVal);
If , removes all directory path information when adding files.1
Only filenames are stored in the ZIP.
The default value is .0
Encryption
my $intVal = $zip->Encryption;
$zip->Encryption($intVal);
Specifies encryption mode:
0→ No encryption4→ WinZip-compatible AES encryption
Important: Encryption and PasswordProtect are mutually exclusive.
If PasswordProtect = , then 1Encryption should be 0.
The default value is 0.
EncryptKeyLength
my $intVal = $zip->EncryptKeyLength;
$zip->EncryptKeyLength($intVal);
Specifies the AES encryption key length.
- Valid values:
128,192, or256
The default value is 128.
EncryptPassword
my $strVal = $zip->EncryptPassword;
$zip->EncryptPassword($strVal);
ExeDefaultDir
my $strVal = $zip->ExeDefaultDir;
$zip->ExeDefaultDir($strVal);
(Windows only, for creating self-extracting EXE's)
Default extraction directory shown in the self-extracting EXE user interface.
The default value is the empty string.
topExeFinishNotifier
my $boolVal = $zip->ExeFinishNotifier;
$zip->ExeFinishNotifier($boolVal);
(Windows only, for creating self-extracting EXE's)
If , displays a completion dialog after extraction finishes.1
The default value is .0
ExeIconFile
my $strVal = $zip->ExeIconFile;
$zip->ExeIconFile($strVal);
(Windows only, for creating self-extracting EXE's)
Path to an .ico file used as the EXE icon.
This feature is only available when the application creating the EXE is 32-bit.
The default value is the empty string.
topExeNoInterface
my $boolVal = $zip->ExeNoInterface;
$zip->ExeNoInterface($boolVal);
(Windows only, for creating self-extracting EXE's)
If , runs the self-extracting EXE without displaying the main user interface.1
The default value is .0
ExeSilentProgress
my $boolVal = $zip->ExeSilentProgress;
$zip->ExeSilentProgress($boolVal);
(Windows only, for creating self-extracting EXE's)
Controls whether a progress dialog is shown during extraction.
If ExeNoInterface = , the progress bar appears within the main dialog and this property has no effect.0
The default value is .0
ExeTitle
my $strVal = $zip->ExeTitle;
$zip->ExeTitle($strVal);
(Windows only, for creating self-extracting EXE's)
Title displayed in the self-extracting EXE dialog.
The default value is the empty string.
topExeUnzipCaption
my $strVal = $zip->ExeUnzipCaption;
$zip->ExeUnzipCaption($strVal);
(Windows only, for creating self-extracting EXE's)
Caption text displayed in the self-extracting EXE dialog.
The default value is the empty string.
topExeUnzipDir
my $strVal = $zip->ExeUnzipDir;
$zip->ExeUnzipDir($strVal);
(Windows only, for creating self-extracting EXE's)
Specifies a predefined extraction directory.
- Supports environment variables such as
%TEMP%. - UNC paths are not supported.
The default value is the empty string.
topExeWaitForSetup
my $boolVal = $zip->ExeWaitForSetup;
$zip->ExeWaitForSetup($boolVal);
If , waits for the AutoRun executable to finish before exiting.1
If , the self-extracting EXE may exit before the AutoRun executable completes.0
The default value is .1
ExeXmlConfig
my $strVal = $zip->ExeXmlConfig;
$zip->ExeXmlConfig($strVal);
Allows for an XML config document to be used to specify all possible options for self-extracting EXEs. This property is a string containing the XML config document.
The XML should have this format:
MainUnzipLabel must also be set for this to take effect.</MainUnzipBtn>
MainUnzipLabel must also be set for this to take effect.</MainCloseBtn>
MainUnzipLabel must also be set for this to take effect.</MainBrowseBtn>
AutoTemp property)</AutoTemp>
SetupExe is run.)</Cleanup>
ExeFinishNotifier property)</ShowFin>
ExeNoInterface property)</ShowMain>
ExeSilentProgress property)</ShowProgress>
ExeWaitForSetup property)</WaitForSetup>
AutoRun property)</SetupExe>
ExeUnzipDir property. UNC paths, such as \\servername\path, are not supported.)</UnzipDir>
ExeDefaultDir property)</DefaultDir>
ExeIconFile property)</IconFile>
ExeTitle property.</MainTitle>
ExeUnzipCaption property.</MainCaption>
A self-extracting EXE can be run from the command line with the
-log {logFilePath} option to create a log with information for debugging.
FileCount
my $intVal = $zip->FileCount;
Number of files in the ZIP, excluding directory entries.
topFileName
my $strVal = $zip->FileName;
$zip->FileName($strVal);
HasZipFormatErrors
my $boolVal = $zip->HasZipFormatErrors;
Indicates whether minor ZIP format problems were detected when opening the ZIP archive.
topHeartbeatMs
my $intVal = $zip->HeartbeatMs;
$zip->HeartbeatMs($intVal);
Interval, in milliseconds, between abort-check callbacks.
If set to 0, abort callbacks are disabled.
The default value is 0.
IgnoreAccessDenied
my $boolVal = $zip->IgnoreAccessDenied;
$zip->IgnoreAccessDenied($boolVal);
If , files that cannot be read, written, or created due to filesystem permission errors are skipped.1
If , any access-denied error causes the ZIP operation to fail.0
The default value is .1
LastErrorHtml
my $strVal = $zip->LastErrorHtml;
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
my $strVal = $zip->LastErrorText;
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
my $strVal = $zip->LastErrorXml;
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
my $boolVal = $zip->LastMethodSuccess;
$zip->LastMethodSuccess($boolVal);
Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
MaxDate
my $strVal = $zip->MaxDate;
$zip->MaxDate($strVal);
Maximum last-modified timestamp for files processed during add or extract operations.
Files having modification timestamps later than this value are skipped.
Supports ISO 8601 date/time formats, including:
YYYY-MM-DD
Example:2024-07-31YYYY-MM-DDTHH:MM:SS±HH:MM
Example:2024-07-31T12:34:56+02:00YYYY-MM-DDTHH:MM:SSZ
Example:2024-07-31T12:34:56Z
The default value is the empty string, meaning no maximum date restriction.
MaxUncompressSize
my $intVal = $zip->MaxUncompressSize;
$zip->MaxUncompressSize($intVal);
Prevents extraction of files larger than the specified uncompressed size.
A value of 0 means no size limit.
The default value is 0.
MinDate
my $strVal = $zip->MinDate;
$zip->MinDate($strVal);
Minimum last-modified timestamp for files processed during add or extract operations.
Supports ISO 8601 date/time formats, including:
YYYY-MM-DD
Example:2024-07-31YYYY-MM-DDTHH:MM:SS±HH:MM
Example:2024-07-31T12:34:56+02:00YYYY-MM-DDTHH:MM:SSZ
Example:2024-07-31T12:34:56Z
The default value is the empty string, meaning no minimum date restriction.
NumEntries
my $intVal = $zip->NumEntries;
Total number of entries in the ZIP, including both files and directories.
OemCodePage
my $intVal = $zip->OemCodePage;
$zip->OemCodePage($intVal);
Specifies the OEM code page used for ZIP filename encoding.
Defaults to the OEM code page of the current computer.
topOverwriteExisting
my $boolVal = $zip->OverwriteExisting;
$zip->OverwriteExisting($boolVal);
PasswordProtect
my $boolVal = $zip->PasswordProtect;
$zip->PasswordProtect($boolVal);
Indicates whether the ZIP uses legacy Zip 2.0 password protection.
This property is set automatically when a ZIP archive is opened by any of the Open* methods, such as OpenZip, OpenFromMemory, OpenBd, and related methods.
Important: PasswordProtect and Encryption are mutually exclusive.
If PasswordProtect = , then 1Encryption should be 0.
The default value is .0
PathPrefix
my $strVal = $zip->PathPrefix;
$zip->PathPrefix($strVal);
Gets or sets a path prefix that is prepended to ZIP entry paths for files appended from the local filesystem.
This is useful when you want all extracted files to appear under a specific subdirectory.
This property affects only the following methods:
-
AppendFiles -
AppendFilesEx -
AddFile -
AppendOneFileOrDir
The PathPrefix value is prepended to the stored ZIP
path for each appended filesystem file.
For example, set PathPrefix to subdir/ so that files are stored in the ZIP with subdir/ prepended to their paths. When extracted, the files will be placed under the subdir directory.
This property does not affect entries added entirely from memory, such as entries added using:
-
AddString -
AddData -
AddBd -
AddSb
For in-memory entries, the ZIP entry path is determined solely by the filename/path argument passed to the method.
The default value is the empty string.
PercentDoneScale
my $intVal = $zip->PercentDoneScale;
$zip->PercentDoneScale($intVal);
Controls the granularity of PercentDone event callbacks.
This property is only applicable in programming environments that support event callbacks.
The value specifies what should be considered 100% complete for progress reporting purposes.
- A value of
100provides whole-percent progress updates. - A value of
1000provides tenth-percent granularity. - For example, with a scale of
1000, a PercentDone callback value of453represents45.3%complete.
Increasing this value allows for more frequent and finer-grained progress callbacks during long-running operations.
The value is automatically clamped to the range:
- Minimum:
10 - Maximum:
100000
The default value is 100.
PwdProtCharset
my $strVal = $zip->PwdProtCharset;
$zip->PwdProtCharset($strVal);
Specifies the character encoding used to convert the decrypt password into its binary byte representation for legacy password-protected ZIP archives that use Zip 2.0 encryption.
The default value is ansi.
Other possible values include:
cp850cp437- Any supported Windows or OEM code page listed at the link below.
This property applies only to older Zip 2.0 password protection and is not used for AES-encrypted ZIP archives.
topTempDir
my $strVal = $zip->TempDir;
$zip->TempDir($strVal);
Directory used for temporary files during ZIP operations.
When overwriting an existing ZIP file, a temporary file is used to avoid corrupting the original ZIP if an error occurs.
The default value depends on the runtime environment.
topUncommonOptions
my $strVal = $zip->UncommonOptions;
$zip->UncommonOptions($strVal);
Advanced options for uncommon scenarios.
ForceZip64→ Forces ZIP64 format even when not required.
The default value is the empty string.
topVerboseLogging
my $boolVal = $zip->VerboseLogging;
$zip->VerboseLogging($boolVal);
If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
my $strVal = $zip->Version;
Zipx
my $boolVal = $zip->Zipx;
$zip->Zipx($boolVal);
If , creates ZIPX archives using the most appropriate compression method for each file.1
The default value is .0
ZipxDefaultAlg
my $strVal = $zip->ZipxDefaultAlg;
$zip->ZipxDefaultAlg($strVal);
Default compression algorithm used when creating ZIPX archives.
- Possible values include:
deflateppmdlzmabzip2deflate64
The default value is deflate.
Methods
AddBd
# $bd is a Chilkat2::BinData
# $success is true or false
my $success = $zip->AddBd($pathInZip, $bd);
Adds the contents of a BinData object as a new entry in the ZIP archive.
pathInZipspecifies the filename and optional directory path stored within the ZIP.- The bytes contained in
bdbecome the contents of the ZIP entry. - The entry is added to the in-memory ZIP object and is not written to disk until
WriteZip,WriteZipAndClose,WriteBd, orWriteToMemoryis called.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
AddEmpty
# $pathInZip is a string
# $success is true or false
my $success = $zip->AddEmpty($isDir, $pathInZip);
Adds an empty file or directory entry to the ZIP archive.
- If
isDir =, an empty directory entry is created.1 - If
isDir =, an empty file entry is created.0 pathInZipspecifies the path stored in the ZIP archive.
This method is useful when directory structure entries must exist even if no files are present.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
AddEncoded
# $encoding is a string
# $data is a string
# $success is true or false
my $success = $zip->AddEncoded($pathInZip, $encoding, $data);
Adds encoded binary data as a ZIP entry.
encodingspecifies howdatais encoded.- Common encodings include
base64andhex. - The decoded binary bytes become the contents of the ZIP entry.
This method is useful when binary data already exists in textual encoded form.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
AddFile
# $saveExtraPath is a boolean
# $success is true or false
my $success = $zip->AddFile($localPath, $saveExtraPath);
Adds a file or directory from the local filesystem to the ZIP archive.
- If
localPathis an absolute path andsaveExtraPath =, the stored ZIP path includes the relative directory structure.1 - If
saveExtraPath =, only the filename is stored.0 - If
localPathis already relative, the relative path is stored as-is regardless ofsaveExtraPath.
This method adds a reference to the file or directory in the local filesystem. The file data is not immediately read or compressed.
The actual file contents are consumed only when a Write* method is called, such as:
WriteZipWriteZipAndCloseWriteBdWriteToMemory
This allows files and data entries to be accumulated in the in-memory ZIP object prior to writing the final ZIP archive.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
AddNoCompressExtension
$zip->AddNoCompressExtension($fileExtension);
Adds a file extension to the internal "no-compression" list.
Files having these extensions are stored without compression because they are already compressed or because compression would provide little benefit.
For example:
.zip.jpg.png.gz
The extension may be specified with or without the leading dot.
Additional extensions remain active for the lifetime of the Zip object unless removed with RemoveNoCompressExtension.
Returns the object, so calls can be chained.
topAddSb
# $sb is a Chilkat2::StringBuilder
# $charset is a string
# $success is true or false
my $success = $zip->AddSb($pathInZip, $sb, $charset);
Adds the contents of a StringBuilder object as a text entry in the ZIP archive.
- The text is converted to bytes using the specified
charset. pathInZipspecifies the filename stored in the ZIP.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
AddString
# $content is a string
# $charset is a string
# $success is true or false
my $success = $zip->AddString($pathInZip, $content, $charset);
Adds a string as a text file entry in the ZIP archive.
- The string is converted to bytes using the specified
charset. pathInZipspecifies the path stored within the ZIP archive.
This method is useful for dynamically generating text files directly in memory.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
AppendFiles
# $recurse is a boolean
# $success is true or false
my $success = $zip->AppendFiles($filePattern, $recurse);
Adds one or more files matching a wildcard pattern.
- The wildcard character
*matches zero or more characters. - If
recurse =, subdirectories are processed recursively.1 - If
recurse =, only the current directory is searched.0
For example:
AppendFiles("c:/temp/*.txt", 0)
This method only updates the in-memory ZIP object. The ZIP file itself is not written until a Write* method is called.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
AppendFilesEx
# $recurse is a boolean
# $saveExtraPath is a boolean
# $archiveOnly is a boolean
# $includeHidden is a boolean
# $includeSystem is a boolean
# $success is true or false
my $success = $zip->AppendFilesEx($filePattern, $recurse, $saveExtraPath, $archiveOnly, $includeHidden, $includeSystem);
Advanced version of AppendFiles with additional filtering and path options.
saveExtraPathcontrols whether the extra leading path information from thefilePatternis preserved in the ZIP.archiveOnlyapplies only on Windows and limits processing to files having the archive attribute set.includeHiddencontrols whether hidden files are included.includeSystemcontrols whether files with the System attribute are included.
This method adds references to files in the in-memory ZIP object. No ZIP file is written until a Write* method is called.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
AppendZip
# $success is true or false
my $success = $zip->AppendZip($zipPath);
Note: This method is currently not working and will be fixed in v11.5.0
Adds all entries from another existing ZIP archive into the current ZIP object.
The zipPath argument specifies the path of a ZIP file located in the local filesystem.
All entries from the specified ZIP archive are appended to the current in-memory ZIP object.
The ZIP archive itself is not rewritten until a Write* method is called.
This method is useful for merging the contents of multiple ZIP archives into a single ZIP.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
CloseZip
Closes the currently open ZIP archive and clears all entries from the Zip object.
This method has the same effect as calling NewZip without specifying a filename.
Returns the object, so calls can be chained.
topDeleteEntry
# $success is true or false
my $success = $zip->DeleteEntry($entry);
Removes a ZIP entry from the current ZIP object.
The ZIP file itself is not rewritten until a Write* method is called.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
EntryAt
# $entry is a Chilkat2::ZipEntry
# $success is true or false
my $success = $zip->EntryAt($index, $entry);
Retrieves the ZIP entry at the specified zero-based index.
- The first entry is at index
0. - The matching entry is returned in the supplied
ZipEntryobject.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
EntryById
# $entry is a Chilkat2::ZipEntry
# $success is true or false
my $success = $zip->EntryById($id, $entry);
Finds a ZIP entry by its unique EntryID.
The matching entry is returned in the supplied ZipEntry object.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
EntryMatching
# $entry is a Chilkat2::ZipEntry
# $success is true or false
my $success = $zip->EntryMatching($pattern, $entry);
Finds the first ZIP entry whose stored path matches a wildcard pattern.
- The wildcard character
*matches zero or more characters. - The comparison is performed against the full stored ZIP path.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
EntryOf
# $entry is a Chilkat2::ZipEntry
# $flag is true or false
my $flag = $zip->EntryOf($pathInZip, $entry);
Finds a ZIP entry whose stored path exactly matches pathInZip.
The matching entry is returned in the supplied ZipEntry object.
Never dies: false is an answer, not a failure.
ExcludeDir
$zip->ExcludeDir($dirName);
Adds a directory name to the exclusion list used by recursive append operations.
- All directories having the specified name are skipped.
- The comparison is case-insensitive.
- Call multiple times to exclude multiple directory names.
This affects methods such as AppendFiles and AppendFilesEx.
Returns the object, so calls can be chained.
ExtractExe
# $dirPath is a string
# $success is true or false
my $success = $zip->ExtractExe($exePath, $dirPath);
Extracts files from a Chilkat-created self-extracting EXE.
- Files are extracted into
dirPath. - Subdirectories are automatically created as needed.
- If the EXE is encrypted,
DecryptPasswordmust be set before extraction.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
GetDirectoryAsXML
my $str = $zip->GetDirectoryAsXML();
Returns the ZIP directory structure as an XML document.
The returned XML contains information about the entries currently contained within the ZIP archive, including files and directories.
This method is useful for inspecting ZIP contents without extracting files.
Returns the XML document as a string.
Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
GetExeConfigParam
# $str is a string or undef
my $str = $zip->GetExeConfigParam($name);
(Windows only, for creating self-extracting EXE's)
Returns the value of a configuration parameter embedded within a self-extracting EXE.
The name argument should be one of the XML tag names described in the ExeXmlConfig property documentation.
For example:
MainTitleMainCaptionSetupExe
Returns the parameter value as a string.
Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
GetMaxUncompressedSize
my $str = $zip->GetMaxUncompressedSize();
Returns the largest uncompressed file size contained within the ZIP archive.
The size is returned as a string rather than an integer because the value may exceed the range of a 32-bit integer.
This method is useful when:
- Checking for extremely large files before extraction
- Estimating required disk space
- Detecting unusually large compressed entries
Returns the size as a decimal string.
Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
IsNoCompressExtension
# $flag is true or false
my $flag = $zip->IsNoCompressExtension($fileExtension);
Checks whether a file extension is contained in the internal "no-compression" extension list.
Files having extensions in this list are stored without compression because they are typically already compressed.
The extension may be specified with or without the leading dot.
For example, both of the following are valid:
.jpgjpg
Returns if the extension exists in the list, otherwise returns 1.0
Never dies: false is an answer, not a failure.
topIsPasswordProtected
# $flag is true or false
my $flag = $zip->IsPasswordProtected($zipPath);
Checks whether a ZIP archive uses legacy Zip 2.0 password protection.
The zipPath argument specifies the path of a ZIP file in the local filesystem.
This method checks only for traditional Zip 2.0 password protection.
Returns if the ZIP archive is password protected, otherwise returns 1.0
Never dies: false is an answer, not a failure.
topNewZip
# $success is true or false
my $success = $zip->NewZip($zipPath);
Initializes a new empty ZIP archive.
- If another ZIP archive is currently open, it is closed.
- All existing in-memory ZIP entries are discarded.
- The
FileNameproperty is set tozipPath.
No ZIP file is actually created until a Write* method is called.
This method resets the Zip object to a clean empty state.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
OpenBd
Opens a ZIP archive contained entirely within a BinData object.
This method allows ZIP archives to be processed entirely in memory without requiring a filesystem file.
When a ZIP archive is opened:
PasswordProtectis automatically set if legacy Zip 2.0 encryption is detected.Encryptionis automatically set if strong encryption is detected.- A value of
4forEncryptionindicates WinZip-compatible AES encryption.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
OpenEmbedded
# $resourceName is a string
# $success is true or false
my $success = $zip->OpenEmbedded($exeFilename, $resourceName);
(Windows only)
Opens a ZIP archive embedded as a resource within a Windows executable.
exeFilenamespecifies the EXE file path.resourceNamespecifies the embedded resource name containing the ZIP data.
This method is useful when ZIP archives are packaged within Windows applications.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
OpenZip
# $success is true or false
my $success = $zip->OpenZip($zipPath);
Opens a ZIP archive from the local filesystem.
The zipPath argument specifies the path of the ZIP file to open.
Encrypted ZIP archives may be opened without providing a password, but encrypted entries cannot be extracted until the correct password is provided using DecryptPassword.
When the ZIP archive is opened:
PasswordProtectis automatically set if legacy Zip 2.0 encryption is detected.Encryptionis automatically set if strong encryption is detected.Encryption = 4indicates WinZip-compatible AES encryption.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
QuickAppend
# $success is true or false
my $success = $zip->QuickAppend($zipPath);
Efficiently appends additional entries to an existing ZIP archive.
The zipPath argument specifies the path of an existing ZIP archive in the local filesystem.
This method avoids rewriting existing entries.
- Existing ZIP entries remain unchanged.
- New entries are appended to the end of the ZIP archive.
- The ZIP central directory is updated accordingly.
This method is typically faster than rebuilding the entire ZIP archive.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
RemoveNoCompressExtension
$zip->RemoveNoCompressExtension($fileExtension);
Removes a file extension from the internal "no-compression" extension list.
After removal, files having this extension may be compressed normally.
The extension may be specified with or without the leading dot.
Returns the object, so calls can be chained.
topSetCompressionLevel
$zip->SetCompressionLevel($level);
Sets the compression level for all file and data entries currently contained within the ZIP object.
0→ No compression9→ Maximum compression
The default compression level is 6.
Important: This method should be called after files or data entries have already been added to the ZIP object.
The compression level cannot be changed for mapped entries originating from an already-open ZIP archive.
Returns the object, so calls can be chained.
topSetExclusions
Specifies a collection of wildcard exclusion patterns used when adding files to the ZIP archive.
Each pattern may use the wildcard character * to match zero or more characters.
Files matching any exclusion pattern are skipped.
Returns the object, so calls can be chained.
SetExeConfigParam
# $paramValue is a string
$zip->SetExeConfigParam($paramName, $paramValue);
(Windows only, for creating self-extracting EXE's)
Sets a configuration parameter embedded within a self-extracting EXE created by WriteExe or WriteExe2.
The paramName should be one of the XML configuration tag names described in the ExeXmlConfig property documentation.
For example:
SetExeConfigParam("MainUnzipBtn","Extract")
This changes the text displayed on the self-extractor's main unzip button.
Returns the object, so calls can be chained.
topUnzip
# $n is an integer
my $n = $zip->Unzip($dirPath);
Extracts all files and directories from the ZIP archive.
dirPathspecifies the destination directory.- Subdirectories are automatically created as needed.
Returns the number of files extracted.
Returns -1 if a failure occurs.
UnzipInto
# $n is an integer
my $n = $zip->UnzipInto($dirPath);
Extracts all files into a single directory.
All directory path information stored within the ZIP archive is ignored.
If multiple files have the same filename, later extracted files overwrite earlier ones.
Returns the number of files extracted, or -1 on failure.
UnzipMatching
# $pattern is a string
# $verbose is a boolean
# $n is an integer
my $n = $zip->UnzipMatching($dirPath, $pattern, $verbose);
Extracts only entries whose stored paths match a wildcard pattern.
- The wildcard character
*matches zero or more characters. - If no wildcard is used, an exact filename match is required.
Subdirectories are automatically created as needed.
Returns the number of files extracted, or -1 on failure.
UnzipMatchingInto
# $pattern is a string
# $verbose is a boolean
# $n is an integer
my $n = $zip->UnzipMatchingInto($dirPath, $pattern, $verbose);
Extracts matching entries into a single directory while ignoring all stored ZIP path information.
Matching behavior is identical to UnzipMatching.
If duplicate filenames occur, later extracted files overwrite earlier ones.
Returns the number of files extracted, or -1 on failure.
UnzipNewer
# $n is an integer
my $n = $zip->UnzipNewer($dirPath);
Extracts only files that:
- Do not already exist
- Or have older modification timestamps than the ZIP entry
Subdirectories are automatically created as needed.
Returns the number of files extracted, or -1 on failure.
VerifyPassword
my $flag = $zip->VerifyPassword();
Verifies that the current DecryptPassword value is correct for the currently opened ZIP archive.
This method allows password validation before attempting extraction.
Returns if the password is valid, otherwise returns 1.0
Never dies: false is an answer, not a failure.
WriteBd
# $success is true or false
my $success = $zip->WriteBd($binData);
Writes the ZIP archive to a BinData object instead of a filesystem file.
The generated ZIP archive exists entirely in memory.
The ZIP data written by this method may later be opened using OpenBd.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
WriteExe
# $success is true or false
my $success = $zip->WriteExe($exeFilename);
(Windows only, for creating self-extracting EXE's)
Creates a Windows self-extracting executable (EXE).
The generated EXE contains both the extraction logic and the ZIP archive data.
There are no limitations on:
- Total ZIP size
- Individual file size
- Number of files
The generated EXE supports the following command-line arguments:
-log logFileName-unzipDir unzipDirectoryPath-pwd password-ap autoRunParams
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
WriteZip
my $success = $zip->WriteZip();
Saves the Zip to a file and implictly re-opens it so further operations can continue. Use WriteZipAndClose to write and close the Zip. There is no limitation on the size of files that may be contained within a .zip, the total number of files in a .zip, or the total size of a .zip. If necessary, WriteZip will use the ZIP64 file format extensions when 4GB or file count limitations of the old zip file format are exceeded.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
WriteZipAndClose
my $success = $zip->WriteZipAndClose();
Saves the Zip to a file and closes it. On return, the Zip object will be in the state as if NewZip had been called. There is no limitation on the size of files that may be contained within a .zip, the total number of files in a .zip, or the total size of a .zip. If necessary, WriteZip will use the ZIP64 file format extensions when 4GB or file count limitations of the old zip file format are exceeded.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
Events
All Chilkat methods are synchronous: the call returns when the work is done. During a long-running call, Chilkat2::Zip reports progress to handlers installed with on, which takes Event => CODE pairs (closures, so a handler can use the variables around it):
$zip->on(
PercentDone => sub { my ($pctDone) = @_; print "$pctDone%\n"; return 0 }, # a true return aborts
ProgressInfo => sub { my ($name, $value) = @_; print "$name: $value\n" },
);
$zip->HeartbeatMs(250); # the AbortCheck handler is called 4 times per secondInstalls the handlers given, replacing those installed before for the same events; undef instead of a CODE reference removes one, and $zip->on() with no arguments returns the installed handlers as a list of pairs. The event names are checked: a misspelled one croaks, and nothing is installed.
The AbortCheck handler is called at the interval set by the HeartbeatMs property (0, the default, disables it); PercentDone is called when an operation's completion percentage is known; ProgressInfo delivers named progress values. A true return from the AbortCheck or PercentDone handler aborts the running method, which then fails in the usual way (false or undef, or a Chilkat2::Error under RaiseError).
Handlers run during the method call, on the thread that called it. Inside a handler, other objects may be used, but calling a method of the same object (or its on) croaks. A die in a handler aborts the running method and is re-thrown from the method call; the object remains usable. A handler that uses $zip itself makes a reference cycle: weaken the captured copy (Scalar::Util) or remove the handler when done.
AbortCheck
$zip->on(AbortCheck => sub { ... });
Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.
Example
my $deadline = time() + 30; # give up after 30 seconds
$zip->HeartbeatMs(250); # call the handler 4 times per second
$zip->on(AbortCheck => sub { return time() > $deadline });PercentDone
$zip->on(PercentDone => sub { ... });
This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).
The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.
To abort the operation, set the abort output argument to 1. This will cause the method to terminate and return a failure status or corresponding failure value.
Example
$zip->on(PercentDone => sub {
my ($pctDone) = @_; # 0 to 100
print "Percent done: $pctDone\n";
return 0; # return a true value to abort the method in progress
});ProgressInfo
$zip->on(ProgressInfo => sub { ... });
This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.
Note: Some Chilkat methods don't fire any ProgressInfo events.
Example
$zip->on(ProgressInfo => sub {
my ($name, $value) = @_;
print "$name: $value\n";
});