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

Question: How to add a stream resource? #79

Closed
jacksleight opened this issue Sep 1, 2022 · 4 comments
Closed

Question: How to add a stream resource? #79

jacksleight opened this issue Sep 1, 2022 · 4 comments

Comments

@jacksleight
Copy link

jacksleight commented Sep 1, 2022

Thanks for this awesome library!

Just a quick question: How do you add a stream resource directly?

When I try $zip->add($stream, $basename) I get:

STS\ZipStream\Models\File::make(): Argument #1 ($source) must be of type string, resource given

With the underlying php-zipstream you use addFileFromStream(), but I can't figure out how to do it with laravel-zipstream. I think the readme suggests this is possible so I'm probably just missing something! 😄

For context I'm trying to add streams from Flysystem's readStream() method: https://flysystem.thephpleague.com/docs/usage/filesystem-api/ . The files could come from any of the sources Flysystem supports so I can't use paths, and I dont want to read the files first to keep memory usage down.

@jszobody
Copy link
Member

jszobody commented Sep 2, 2022

Are you able to get the size of this particular stream? Curious if you are able to fstat($stream) and get details, including the size parameter. That's going to be important for how this package works.

If you can get size, I don't see why it can't work with the package. It would likely need a new file model that expects a stream. Would be a nice addition to the package, I'm just not sure if all Flysystem sources would provide stream size.

@jacksleight
Copy link
Author

jacksleight commented Sep 2, 2022

Ah good point. I did try implementing a new model, and got it working with local streams, but some of them are going to be remote so it won't be possible to get their size with fstat.

I guess that means this package wouldn't really be suitable for this use case and I should use php-zipstream instead?

@jszobody
Copy link
Member

jszobody commented Sep 2, 2022

I think so. I wrote this zipstream wrapper package to be pretty opinionated. I wanted size calculations up front so that I could send a Content-Length header to the browser and give the user progress and ETA during the download. These weren't supported in the php-zipstream package itself.

So yeah, if you're not looking to do things this way, might be easiest to use the lower-level package directly.

@jacksleight
Copy link
Author

Sure makes sense. Thanks for you help! 😊

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

2 participants