The Zip object represents a ZIP archive. It can inspect and read an existing archive, safely extract its contents, or create a new archive and add files, directories, bytes, and text.
Availability: The Zip object was added in ZPE 1.14.11. Archive file operations require permission level 4.
Opening an archive
Constructing a Zip object with one argument opens an existing archive for reading. Pass "write" or "create" as the second argument to create a writable archive.
$archive = new Zip("archive.zip") $builder = new Zip("build.zip", "write")
Object functions
The following functions provide archive inspection, reading, extraction, writing, modification, verification, and lifecycle management.
- _construct [1.14.11+]
Opens an existing ZIP archive for reading, or creates a writable archive when the mode is write or create.
- add_bytes [1.14.11+]
Adds binary data from a ByteStream or list of byte values as an archive entry.
- add_directory [1.14.11+]
Adds the regular files below a directory to a writable archive.
- add_file [1.14.11+]
Adds a file to a writable archive, optionally using a different entry name.
- add_text [1.14.11+]
Adds text to a writable archive using UTF-8 by default or the selected encoding.
- close [1.14.11+]
Closes the archive and releases its file resources.
- entries [1.14.11+]
Returns metadata for every entry in a readable archive.
- extract [1.14.11+]
Safely extracts all entries into a destination directory.
- extract_entry [1.14.11+]
Extracts one archive entry to a destination file.
- has [1.14.11+]
Checks whether an entry exists in the archive.
- info [1.14.11+]
Returns metadata for one archive entry, or undefined when the entry is not present.
- is_open [1.14.11+]
Returns whether the archive is currently open.
- is_read_only [1.14.11+]
Returns whether the archive was opened in read mode.
- read [1.14.11+]
Reads an archive entry and returns its bytes as a ByteStream object.
- read_text [1.14.11+]
Reads an archive entry as text using UTF-8 by default or the specified character encoding.
- remove [1.14.11+]
Removes an entry by safely rebuilding the archive.
- rename [1.14.11+]
Renames an entry by safely rebuilding the archive.
- verify [1.14.11+]
Reads every archive entry to verify that its contents can be decompressed and checked.

There are no comments on this page.
Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days. Your email address is stored so that replies can be sent to your email address.
Comments powered by BalfComment