PHPackages                             exeque/laravel-zipstream - 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. exeque/laravel-zipstream

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

exeque/laravel-zipstream
========================

Zip streaming for Laravel

0.0.5(2mo ago)7691MITPHPPHP ^8.4CI passing

Since Feb 25Pushed 2mo agoCompare

[ Source](https://github.com/ExeQue/laravel-zipstream)[ Packagist](https://packagist.org/packages/exeque/laravel-zipstream)[ RSS](/packages/exeque-laravel-zipstream/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

[![Laravel ZipStream](img/laravel-zipstream.jpg)](img/laravel-zipstream.jpg)

Laravel ZipStream
=================

[](#laravel-zipstream)

A fluent Laravel wrapper for [maennchen/zipstream-php](https://github.com/maennchen/zipstream-php) to easily generate and stream ZIP archives.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require exeque/laravel-zipstream
```

The service provider will automatically register itself.

Basic Usage
-----------

[](#basic-usage)

The easiest way to use the library is via the `Zip` facade. You can fluently chain methods to add files and then generate a response or save the ZIP.

```
use ExeQue\ZipStream\Facades\Zip;

return Zip::as('photos.zip')
    ->fromDisk('public', 'images/photo1.jpg')
    ->fromLocal('/path/to/local/file.pdf', 'invoice.pdf')
    ->fromRaw('notes.txt', 'Direct text content')
    ->toResponse();
```

Adding Content
--------------

[](#adding-content)

### From Laravel Disks

[](#from-laravel-disks)

Add files stored on any of your configured Laravel filesystems.

```
Zip::fromDisk('s3', 'exports/data.csv');

// With custom destination path in ZIP
Zip::fromDisk('s3', 'exports/data.csv', '2023/report.csv');
```

### From Local Path

[](#from-local-path)

Add files from the local filesystem.

```
Zip::fromLocal('/tmp/temp-file.log');

// With custom destination path in ZIP
Zip::fromLocal('/tmp/temp-file.log', 'logs/system.log');
```

### From Raw Content

[](#from-raw-content)

Add content directly from a string, resource, or stream.

```
Zip::fromRaw('hello.txt', 'Hello World');
```

### From Custom Classes (Contracts)

[](#from-custom-classes-contracts)

You can implement `StreamableToZip` or `CanStreamToZip` on your custom classes (e.g., a `Media` model or `MediaCollection`) to easily add them to the ZIP archive.

#### StreamableToZip

[](#streamabletozip)

The `StreamableToZip` contract is ideal for individual models that represent a file.

```
use ExeQue\ZipStream\Contracts\StreamableToZip;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class Media extends Model implements StreamableToZip
{
    public function stream()
    {
        // Return resource, string, StreamInterface, or a callable that returns one of these.
        return Storage::disk($this->disk)->readStream($this->path);
    }

    public function destination(): string
    {
        return "{$this->collection_name}/{$this->file_name}";
    }
}

Zip::add(Media::first());
```

#### CanStreamToZip

[](#canstreamtozip)

The `CanStreamToZip` contract is useful for classes that represent a collection of files, such as a `MediaCollection`.

```
use ExeQue\ZipStream\Contracts\CanStreamToZip;
use Illuminate\Database\Eloquent\Collection;

class MediaCollection extends Collection implements CanStreamToZip
{
    public function getStreamableToZip(): iterable
    {
        return $this->all();
    }
}

$media = Media::where('collection_name', 'avatars')->get();
$collection = new MediaCollection($media);

Zip::add($collection);
```

### Empty Directories

[](#empty-directories)

Create an empty directory within the ZIP.

```
Zip::emptyDirectory('backups');
```

Customizing Files
-----------------

[](#customizing-files)

You can pass a callback as the last argument to any of the `from*` methods to customize file-specific options.

```
use ExeQue\ZipStream\Content\LocalFile;

Zip::fromLocal('/path/file.txt', 'file.txt', function (LocalFile $file) {
    $file->comment('This is a important file')
         ->deflate()
         ->deflateLevel(9);
});
```

Extending the Builder (Macros)
------------------------------

[](#extending-the-builder-macros)

The `Zip` facade and `Builder` class use the Laravel `Macroable` trait, allowing you to add custom functionality at runtime.

```
use ExeQue\ZipStream\Facades\Zip;

Zip::macro('fromS3', function (string $path, ?string $destination = null) {
    return $this->fromDisk('s3', $path, $destination);
});

// Usage
Zip::fromS3('exports/report.pdf')->toResponse();
```

Global ZIP Options
------------------

[](#global-zip-options)

### Configuration

[](#configuration)

You can publish the config file to set global defaults:

```
php artisan vendor:publish --tag="laravel-zipstream-config"
```

Available options in `config/laravel-zipstream.php`:

- `default_compression_method`: "DEFLATE", "STORE", or null.
- `default_deflate_level`: 0-9.
- `enable_zero_header`: true or false.

### Fluent Configuration

[](#fluent-configuration)

Customize the ZIP options for a specific archive:

```
Zip::as('archive.zip')
    ->store() // No compression
    ->withZeroHeader()
    ->fromLocal($file)
    ->toResponse();
```

Output Options
--------------

[](#output-options)

### Stream to Browser (Response)

[](#stream-to-browser-response)

Returns a `Symfony\Component\HttpFoundation\StreamedResponse`.

```
return Zip::as('download.zip')
    ->fromDisk('public', 'large-file.mp4')
    ->toResponse();
```

### Save to Local Path

[](#save-to-local-path)

```
Zip::fromRaw('test.txt', 'content')
    ->saveToLocal('/path/to/save/archive.zip');
```

### Save to Laravel Disk

[](#save-to-laravel-disk)

```
Zip::fromRaw('test.txt', 'content')
    ->saveToDisk('s3', 'backups/today.zip');
```

### Get as String or Stream

[](#get-as-string-or-stream)

```
// Get as string
$content = Zip::fromRaw('a.txt', '...')->output();

// Get as PSR-7 Stream
$stream = Zip::fromRaw('a.txt', '...')->output(true);
```

Testing
-------

[](#testing)

The package includes a comprehensive test suite. You can run the tests using Pest:

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance85

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

76d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23560353?v=4)[Morten Harders](/maintainers/ExeQue)[@ExeQue](https://github.com/ExeQue)

---

Top Contributors

[![ExeQue](https://avatars.githubusercontent.com/u/23560353?v=4)](https://github.com/ExeQue "ExeQue (13 commits)")

---

Tags

laravelphpstreamzipphpzipassertzipstream

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/exeque-laravel-zipstream/health.svg)

```
[![Health](https://phpackages.com/badges/exeque-laravel-zipstream/health.svg)](https://phpackages.com/packages/exeque-laravel-zipstream)
```

###  Alternatives

[madnest/madzipper

Easier zip file handling for Laravel applications.

1382.3M6](/packages/madnest-madzipper)[jmathai/s3-bucket-stream-zip-php

PHP library to efficiently stream contents from an AWS S3 bucket or folder as a zip file

56114.4k](/packages/jmathai-s3-bucket-stream-zip-php)[barracudanetworks/archivestream-php

A library for dynamically streaming dynamic tar or zip files without the need to have the complete file stored on the server.

77192.2k1](/packages/barracudanetworks-archivestream-php)[chamilo/pclzip

A PHP library that offers compression and extraction functions for Zip formatted archives

21150.9k4](/packages/chamilo-pclzip)[wgenial/s3-objects-stream-zip-php

S3ObjectsStreamZip is a PHP library to stream objects from AWS S3 as a zip file.

2086.7k](/packages/wgenial-s3-objects-stream-zip-php)[mcnetic/zipstreamer

Stream zip files without i/o overhead

2458.7k](/packages/mcnetic-zipstreamer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
