Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ZipFile::saveAsStream with non-seekable stream #67

Open
connorhu opened this issue Nov 19, 2020 · 0 comments
Open

use ZipFile::saveAsStream with non-seekable stream #67

connorhu opened this issue Nov 19, 2020 · 0 comments

Comments

@connorhu
Copy link

Description
With symfony this would a pretty easy way to stream large zip files on the fly:

        $finder = new Finder();
        $finder
            ->files()
            ->in('path');

        $zipFile = new ZipFile();
        $zipFile->addFromFinder($finder, $options = [
            ZipOptions::COMPRESSION_METHOD => ZipCompressionMethod::DEFLATED,
        ]);
        
        $response = new StreamedResponse(function() use ($zipFile) {
            $outputStream = fopen('php://output', 'wb');
            $zipFile->saveAsStream($outputStream);
        });
        
        $response->headers->set('Content-Type', 'application/zip');
        $disposition = HeaderUtils::makeDisposition(
            HeaderUtils::DISPOSITION_ATTACHMENT,
            'file.zip'
        );
        $response->headers->set('Content-Disposition', $disposition);

        return $response;

But the problem is the saveAsStream() only works with seekable streams. (btw you should check stream_get_meta_data of $handle in saveAsStream method)

Is there any workaround to save large zip into a non-seekable stream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant