digitaldogsbody / mingulay

PHP Zip file parser
GNU Affero General Public License v3.0
1 stars 1 forks source link

Implement a PartialReader #14

Open digitaldogsbody opened 2 years ago

digitaldogsbody commented 2 years ago

Per discussion with Diego on Slack, it would be good to avoid copying all the data for a compressed file stream into memory before returning it to the user, and instead have a way of streaming it directly from the source zipfile.

Slack conversation:

Mike Bennett [5:31 PM] Today's shower thoughts - I am not 100% happy with using php://temp when retrieving a stream for inside the zip. We can't just attach the zlib.inflate filter to the main stream, because then the end user has to handle knowing where to seek to and how much data to read (rather than just being able to while(!feof($fp)) on the returned pointer), so the general pattern has to stay, but rather than opening the temp and doing stream_copy_to_stream directly, maybe we could implement a PartialReader that implements the interface required by fread and can be passed to the end user instead. [5:33] This would eliminate the need to use php://temp as we could just create the new class directly (instantiating it with the offset and length) and pass that to the end user from ::getStream(). [5:33] I think this is broadly similar to what you were talking about in this comment: https://github.com/digitaldogsbody/mingulay/issues/8#issuecomment-1252901778

Diego Pino [6:15 PM] I will go pragmatic here. The main question is, if you are extracting a file from the ZIP, what is the most plausible thing you will do with it? I would say, save locally/do something with it or deliver as download. [6:16] So, that said, PartialReader sounds good