Skip to content

1.0.0

Choose a tag to compare

@ExeQue ExeQue released this 22 Sep 07:40
· 14 commits to main since this release
1f15f2a

Everything streams. An archive of any size is built while it is written, at constant memory, whether it goes to
a browser, a Laravel disk or a local path.

Upgrading from 0.x? Start with the upgrade guide. Every breaking change is there with before and after.

The fix this release started as

saveToDisk() built the whole archive into php://temp before writing a byte, so peak local disk - or memory,
when the temp directory was not writable - equalled the archive size. A 129 MB archive exhausted a default
128 MB memory_limit.

ZipStream pushes while Flysystem and the AWS SDK pull. The archive is now produced inside a Fiber that the
reader drives, so only one chunk is ever held. A failed write leaves nothing behind: the S3 multipart upload is
aborted, the key removed only if this call created it, and the original exception rethrown.

What else is new

  • Events are objects. A handler declares what it listens for by type-hinting its first parameter, and every
    event carries a frozen Context with the archive id, the entry being streamed and how far along it is.
  • Progress reports itself, throttled by bytes or by an interval, and renders as "10 of 125 files" or
    "5.00 KB of 64.00 MB" in thirty European languages.
  • abort() stops an archive from a handler; abort(discard: true) throws it away, upload and all.
  • fromDiskDirectory() and fromLocalDirectory() add a whole prefix from one listing, sizes included.
  • Zip::fake() records what an archive would have contained, so composition is testable without storage.
  • The response owns PHP's output layer - zlib, buffers, encoding, time limit - so a large download streams
    rather than stalls.
  • ArchiveBuilder declares the public surface, with tests that fail on anything public it does not cover.

Breaking changes

  • output(bool) split into toString() and toStream(); the stream is read-once and not seekable
  • EventType gone; $event->id is $event->context->id, and the event interfaces moved to Events\Contracts
  • zeroHeader(?bool) replaced by withZeroHeader(), withoutZeroHeader() and inheritZeroHeader()
  • Content-Type is application/zip, and a plain filename is no longer quoted
  • saveToDisk() takes $options, and DiskFile::make() takes a FilesystemAdapter
  • A failed write cleans up after itself, which includes deleting a path this call created
  • Three new config keys: progress_every, size_precision, manage_output

Documentation

exeque.github.io/laravel-zipstream - including driver pages for
S3 as both source and destination.