dablach/zip-stream-reader

Stream reader for extracting zip archives on the fly.

dev-main 2025-02-19 13:25 UTC

This package is auto-updated.

Last update: 2025-05-19 14:44:56 UTC


README

Read ZIP files from stream in a memory efficient way without first downloading the whole file.

Note

ZIP files can contain entries with no size set in the local file header. These entries can only be read after parsing the central directory which is at the end of the file, making it impossible to read such a file in a streaming fashion. When ZipStreamReader encounters such an entry in an unseekable stream, it wil load the remaining contents into php://temp and read the rest from there.

Usage

$reader = ZipStreamReader::open("https://...");

foreach ($reader as $entry) {
  echo "Name: " . $entry->getName() . "\n";
  echo "Modified: " . $entry->getMtime()->format('r') . "\n";

  $handle = $entry->getStream();
  // $handle is a resource you can use to read the file content (e.g. fread, fgetcsv ..)
}