Comments (6)
Sure thing. You just need to create the S3File model yourself, so you can set the filesize.
// Instead of this...
$zip->add('s3://bucket/key', 'zipfilename.txt');
// ... do this:
$zip->add(
S3File::make('s3://bucket/key', 'zipfilename.txt')->setFilesize(12345)
);
from laravel-zipstream.
Hi jszobody,
Thanks for the quick response. Now it works great, download starts instantly.
It would be great to add this information to the README.md
But that doesn't solve the problem for HttpFile model - $this->getHeaders()
laravel-zipstream/src/Models/HttpFile.php
Lines 50 to 54 in 1960242
I think it's a good idea to add
if ($this->filesize) { return parent::canPredictZipDataSize(); }
here
from laravel-zipstream.
Hi jszobody,
I will try to convey my point of view again in other words.
The model File
has a canPredictZipDataSize()
method. And only in the HttpFile
model it is also present.
The HttpFile
model sets the header variable to make one HTTP request to the file rather than two via the calculateFilesize()
and canPredictZipDataSize()
methods to get the file size - HEADER_CONTENT_LENGTH
We know the size of each file and in order not to do extra work, we transfer it using ->setFilesize(12345)
.
Method calculateFilesize()
is no longer called, but canPredictZipDataSize()
also continues to run because the $headers
variable is empty. What we wanted to get rid of continues to bother us.
It is necessary that the $this->getHeaders()
are not called if the file size was set in advance here https://github.com/stechstudio/laravel-zipstream/blob/master/src/Models/HttpFile.php#L52
What do you think about this ?
from laravel-zipstream.
Yeah, makes sense. It should skip headers if filesize is present. Do you want to submit a PR for this?
Also, I'm curious what kind of HTTP file sources you're using, with known filesizes up front. That's interesting.
from laravel-zipstream.
Yeah, I'll do the PR later.
Initially, for a very long time, I use mod_zip
(https://github.com/evanmiller/mod_zip) for nginx
, and he wants to know the size and hash in advance.
I just decided to see what PHP has achieved while working with zip during this time.
from laravel-zipstream.
On a quick inspection, I ran into a problem.
This line returns the size https://github.com/stechstudio/laravel-zipstream/blob/master/src/Models/HttpFile.php#L26
But there may be no header Content-Length
in the response and this will lead to an error.
We can process this and answer in the false - if (!array_key_exists(self::HEADER_CONTENT_LENGTH, $headers)) { return false; }
But after that we have to return union types
- int|false
which have been supported since php 8.0. And we have the minimum version php: ^7.1
Using zero to check is not correct too as it is the correct file size.
Then it turns out that the correct way is set to check the file size is if (is_numeric($this->filesize))
What do you think?
from laravel-zipstream.
Related Issues (20)
- saveTo method has permission denied error on manjaro without webserver HOT 1
- Grant public-read access HOT 1
- Update maennchen/zipstream-php package HOT 2
- Space & Specials Character are being replaced by "%" sign HOT 1
- Compatibility with PHP 8.2 HOT 2
- Always downloading as a html file with incorrect name HOT 4
- Unable to install package. HOT 9
- maennchen/ZipStream-PHP v3 HOT 17
- The name of the file being downloaded is “download” without extension HOT 7
- ZipStream v3 Beta HOT 9
- Unexpected end of Archive HOT 1
- S3File memory leak on calculateFilesize HOT 11
- ErrorException: fopen(): s3:// wrapper is disabled HOT 1
- Filename sanitization HOT 2
- Laravel 10 Support HOT 1
- The package gets http file headers anyway even when filesize prediction is disabled
- Feature request: Check if file exists and/or append $var to filename HOT 3
- Unable to use Zip HOT 1
- Merge zip - source from s3 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-zipstream.