没有不值得去解决的问题,也没有不值得去学习的技术!

On Windows 10, a ZipStream PHP ZIP File Extracts Successfully With 360 Compression but Fails With WinRAR

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.

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.

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.
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.

Extracting with 7z on Linux, although the files can be extracted, there is actually still an error message
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.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系