PHPackages                             wp-php-toolkit/zip - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. wp-php-toolkit/zip

ActiveLibrary[File &amp; Storage](/categories/file-storage)

wp-php-toolkit/zip
==================

Zip component for WordPress.

v0.8.1(1mo ago)02671GPL-2.0-or-laterPHPPHP &gt;=7.2

Since May 29Pushed 1mo agoCompare

[ Source](https://github.com/wp-php-toolkit/zip)[ Packagist](https://packagist.org/packages/wp-php-toolkit/zip)[ Docs](https://wordpress.github.io/php-toolkit/reference/zip.html)[ RSS](/packages/wp-php-toolkit-zip/feed)WikiDiscussions trunk Synced today

READMEChangelogDependencies (12)Versions (49)Used By (1)

   slug zip   title Zip   install wp-php-toolkit/zip   see\_also    ../learn/02-streaming-archives.html | Tutorial — Streaming archives | Walk through ZIP and EPUB writers from the toolkit's worked example.

 filesystem | Filesystem | Treat an archive like a swappable filesystem backend.

 bytestream | ByteStream | Feed readers and writers without whole-file buffers.

 httpclient | HttpClient | Stream downloaded archives into validation or extraction workflows.

    Read and write ZIP archives without `libzip` or `ZipArchive`. Stored entries are pure PHP; Deflate entries use PHP's `zlib` functions. Entries stream one at a time, while ZIP metadata such as the central directory is still held in memory.

Why this exists
---------------

[](#why-this-exists)

Common PHP ZIP workflows rely on the `ZipArchive` extension or shelling out to `zip`. Those are awkward in hosts without libzip, WebAssembly builds, and code paths that need to stream archive data through toolkit byte streams.

The Zip component reads and writes Stored and Deflate archives without `ZipArchive`. The decoder is pull-based for entry bodies, but `ZipFilesystem` indexes the central directory in memory and currently rejects archives whose central directory exceeds 2 MB. The encoder accepts any `ByteWriteStream` as a sink and writes one entry at a time.

Read a file out of a ZIP
------------------------

[](#read-a-file-out-of-a-zip)

`ZipFilesystem` implements this toolkit's `Filesystem` interface, so once you wrap the byte reader you can call `get_contents()`, `ls()`, and `is_dir()` just like the other read backends.

**Try this:** after *Run*, add a second `append_file()` call before `$enc->close()` for a `notes.md` entry, then call `print_r( $zip->ls( '/' ) )` at the end. The directory listing reflects the new entry without re-reading the file.

```

XML;

foreach ( array(
	'META-INF/container.xml' => $container,
	'EPUB/package.opf'       =>
