- How do I install league/flysystem-ziparchive in a Laravel project?
- Run `composer require league/flysystem-ziparchive` to install the package. No additional Laravel-specific setup is required beyond configuring the adapter as a custom disk in `config/filesystems.php`. The package leverages Flysystem’s existing integration with Laravel’s Storage facade.
- What Laravel versions does this package support?
- This adapter works with Laravel 8+ and requires Flysystem v3+, which is compatible with modern Laravel releases. Ensure your project uses PHP 7.4+ for ZipArchive support, as the adapter relies on PHP’s native extension.
- Can I use this for large ZIP files (e.g., >100MB)?
- ZipArchive processes files in-memory, so large ZIPs may hit PHP memory limits or slow down. For files exceeding 50MB, consider alternatives like `mikehaertl/php-archive` or chunked streaming solutions. Test memory usage with `memory_get_usage()` in your workflows.
- How do I configure a custom ZIP disk in Laravel?
- Add a new disk entry in `config/filesystems.php` under the `disks` array. Example: `'zip_archive' => ['driver' => 'ziparchive', 'path' => storage_path('app/archives')]`. Then use it via `Storage::disk('zip_archive')->put('file.zip', ...)` in your code.
- Is this adapter thread-safe for concurrent writes?
- No, ZipArchive is not thread-safe. Avoid concurrent writes to the same ZIP file. For high-traffic applications, implement locking (e.g., file locks or database semaphores) or offload ZIP generation to queue workers using Laravel Queues.
- How can I validate ZIP file integrity after creation?
- Use Flysystem’s built-in checksum methods (e.g., `Storage::disk('zip_archive')->hash('file.zip')`) or implement custom validation with `ZipArchive::status()` to check for corruption. For critical workflows, consider checksumming files before adding them to the ZIP.
- Can I combine this adapter with other Flysystem drivers (e.g., S3)?
- Yes, this adapter integrates seamlessly with other Flysystem drivers. For example, you can stream files from S3 into a ZIP using `Storage::disk('s3')->get()` and then write them to a ZIP disk. Hybrid workflows like this are fully supported.
- What are the performance implications of using ZipArchive?
- ZipArchive is CPU-intensive, especially for large files or many operations. For performance-critical applications, benchmark your workflows and consider async processing (e.g., Laravel Queues) or lighter alternatives like `ZipStream` for streaming ZIPs.
- How do I handle file path collisions in ZIP archives?
- Flysystem normalizes paths, but ZIP archives enforce strict naming. Use unique filenames (e.g., UUIDs) or implement custom logic in your `put()` calls to resolve collisions. Example: `Storage::disk('zip_archive')->put('unique_'.Str::uuid().'.zip', ...).
- Are there alternatives to league/flysystem-ziparchive for Laravel?
- Yes, alternatives include `mikehaertl/php-archive` (for streaming ZIPs) or `spatie/laravel-medialibrary` (for media packaging). However, this adapter is ideal if you need Flysystem’s abstraction for ZIPs, especially when integrating with Laravel’s Storage facade or existing Flysystem workflows.