1. Reference: Streaming a zip file to an S3 bucket based on ZipStream PHP in Laravel 6. Reference: Generating a stream resource based on fopen in PHP 7.4, which operated on the disk, adjusted to a fully memory-based implementation. Unzipping succeeds with 360 Zip, but fails with WinRAR. As shown in Figure 1.

2. Extracting with 7z on Linux, although the files can be extracted, there is actually still an error message. As shown in Figure 2.

Plaintext
ERRORS:
Unexpected end of archive
--
Path = assets_new.zip
Type = zip
ERRORS:
Unexpected end of archive
Physical Size = 781844
Archives with Errors: 1
Open Errors: 1
3. Reference: https://maennchen.dev/ZipStream-PHP/guide/FlySystem.html . Before uploading the stream, you need to execute: $zip->finish();
Before adjustment:
PHP
$name = $this->themeInstallationTask->themeInstallation->theme_id . '/assets.zip';
$stream = fopen('php://memory', 'w+');
$options = new Archive();
$options->setOutputStream($stream);
$zip = new ZipStream($name, $options);
$zip->addFile(str_replace('\\', '/', str_replace(self::$destination . '/', '', $file->getPathname())), $file->getContents());
Storage::disk(config('theme_asset.filesystem.disk'))->putStream(
$name,
$stream,
config('theme_asset.filesystem.options')
);
$zip->finish();
fclose($stream);
After adjustment:
PHP
$name = $this->themeInstallationTask->themeInstallation->theme_id . '/assets.zip';
$stream = fopen('php://memory', 'w+');
$options = new Archive();
$options->setOutputStream($stream);
$zip = new ZipStream($name, $options);
$zip->addFile(str_replace('\\', '/', str_replace(self::$destination . '/', '', $file->getPathname())), $file->getContents());
$zip->finish();
Storage::disk(config('theme_asset.filesystem.disk'))->putStream(
$name,
$stream,
config('theme_asset.filesystem.options')
);
fclose($stream);
4. Unzipping succeeds with 360 Zip, and unzipping succeeds with WinRAR.
