-
Notifications
You must be signed in to change notification settings - Fork 11
Allow MultipartStreamBuilder subclass to manipulate data #49
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
Conversation
this sounds really cool and makes me wonder if it would make sense to add that functionality into this repository, if you are motivated to contribute it. looking at how we put things into data in hm, and it seems that the |
I am currently writing a multipart stream implementation from ground up to fulfill my own needs. My approach is quite different than yours so I don't think it is suitable as a PR. Instead of building the entire stream content string, I opt to dynamically seek and read the underlying resources on StreamInterface::read. This approach, although heavier in code (thus probably slower), would be more memory efficient for large file uploads / downloads. I am still in the middle of my process. I can share more with you later. |
This approach makes sense to me. If you're OK, I can write a PR of it. |
would be great if you can refactor it to have a clean, protected addData method. that would allow you to do the thing you want, right? and i see, this different approach to a stream builder sounds interesting but can not replace the one here. in that case i think it is best to keep it separate. if you open source it, we'd be happy to link to it from the readme here, with the explanation that the php-http implementation does not support range requests, and people who need that should look at your implementation. |
* Added a public method addData for manipulating the private $data array properly.
bd7c05e
to
e451466
Compare
Rewritten into a public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have addResource call the addData method? though there is some handling on the thing we created with getStream to determine the "filename" from the uri. would it make sense to have that filename header determined that way in addData
as well, if it is not set?
If the 'filename' key is not used at all elsewhere, can I omit it in MultipartStreamBuilder::data? Seem to me it's only used in MultipartStreamBuilder::prepareHeaders. |
* Rewrite with new addData method. * Remove internal 'filename' key from MultipartStreamBuilder::data.
i agree, i can't see it being used anywhere once it goes into data. i guess its a leftover after a previous refactoring. and with data being private, we can be sure there is no BC break if we drop it from the $data. |
Please see if 7323e85 (rewrite addResource with addData) is OK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, this looks good to me - i have one question to double-check i understood correctly.
and please keep the blank line before the return
. i think if you rebase on master, the styleci run would work again and complain about them too ;-)
* add a line before final returns. * use addData to immediately return $this.
Updated. Please see if 0db0d5c works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, looks good to me!
can you please change the branch-alias in composer.json to 1.x-dev (it is currently 1.1-dev but what you do should go into 1.2. with the 1.x-dev notation we avoid having to update it on each minor version upgrade). and please add a note in the CHANGELOG.md describing the new feature.
Updated. Please check. |
i added a changelog entry in 9addfcf thanks a lot! can you rebase your other MR on master to get the latest changes in? |
Leaving more flexibilities for subclassing.
What's in this PR?
Allow subclass of MultipartStreamBuilder to manipulate $data property.
Why?
I am recently working on Range Request support
for my application. For a range request with multiple specified ranges, I need to return a "multipart/byteranges" response.
The signature of MultipartStreamBuilder::addResource forces me to add a field name ($name), which is totally non-sense for
my use case.
I tried to extend the MultipartStreamBuilder with my own class and have an extra method that can properly add
the streams without the unnecessary extra handling, but since the visibility of MultipartStreamBuilder::data is "private",
I cannot do that.
Example Usage
Checklist
To Do