ワンクリックで
laravel-zipstream
Generate and stream ZIP archives in Laravel using a fluent, memory-efficient API.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Generate and stream ZIP archives in Laravel using a fluent, memory-efficient API.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | laravel-zipstream |
| description | Generate and stream ZIP archives in Laravel using a fluent, memory-efficient API. |
Use this skill when a Laravel application needs to create ZIP files from various sources (disks, local paths, or raw content) and either stream them to the browser, save them to a disk, or obtain them as a string/stream. It wraps the maennchen/zipstream-php library to provide a Laravel-friendly interface.
ExeQue\ZipStream\Facades\Zip) for interacting with the library.toResponse() or saveToDisk() to handle large archives without exhausting memory.store() for already compressed formats (images, videos) and deflate() for text-based content to optimize performance.Zip facade.To create a simple ZIP and stream it to the browser:
use ExeQue\ZipStream\Facades\Zip;
return Zip::as('archive_name.zip')
->fromDisk('public', 'path/to/file.jpg')
->toResponse();
The library supports multiple source types:
// From a Laravel Disk
Zip::fromDisk('s3', 'source/path.pdf', 'internal/name.pdf');
// From a Local File Path
Zip::fromLocal('/absolute/path/to/file.log', 'logs/app.log');
// From Raw String/Stream Content
Zip::fromRaw('notes.txt', 'This is the content of the file.');
// From Custom Classes (Contracts)
// Individual models implementing StreamableToZip
Zip::add($mediaModel);
// Collections implementing CanStreamToZip
Zip::add($mediaCollection);
// Create an Empty Directory
Zip::emptyDirectory('empty_folder');
Implement contracts on your models or collections to integrate them directly:
Ideal for objects representing a single file (e.g., a Media model).
use ExeQue\ZipStream\Contracts\StreamableToZip;
class Media extends Model implements StreamableToZip {
public function stream() { return Storage::disk($this->disk)->readStream($this->path); }
public function destination(): string { return "media/{$this->name}"; }
}
Ideal for objects representing multiple files (e.g., a custom collection).
use ExeQue\ZipStream\Contracts\CanStreamToZip;
class MediaCollection extends Collection implements CanStreamToZip {
public function getStreamableToZip(): iterable { return $this->all(); }
}
The Zip facade and Builder are Macroable:
Zip::macro('fromS3', function (string $path, ?string $destination = null) {
return $this->fromDisk('s3', $path, $destination);
});
// Usage
Zip::fromS3('report.pdf')->toResponse();
Use a callback to customize individual files:
use ExeQue\ZipStream\Content\LocalFile;
Zip::fromLocal('file.txt', 'file.txt', function (LocalFile $file) {
$file->comment('Important file')
->deflate()
->deflateLevel(9);
});
Set options that apply to the entire ZIP:
Zip::as('optimized.zip')
->store() // Use 'STORE' method for all files by default
->withZeroHeader()
->fromDisk('public', 'video.mp4')
->toResponse();
Choose the appropriate output method:
// 1. Stream as Laravel Response
return Zip::toResponse();
// 2. Save to Local Path
Zip::saveToLocal('/path/to/archive.zip');
// 3. Save to Laravel Disk
Zip::saveToDisk('s3', 'backups/archive.zip');
// 4. Get as String
$content = Zip::output();
// 5. Get as PSR-7 Stream
$stream = Zip::output(true);