-
Notifications
You must be signed in to change notification settings - Fork 44
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
Streams are hot, FileReader.readAs____ is not #40
Comments
This would be a great addition. When I asked people for how they would use streaming uploads in the browser, many of them had to do with getting a file from I'd suggest |
Just thought about something. If we have Otherwise you end up doing the same thing as |
Blob.toStream() (the concept, not the name) was brought up at TPAC F2F and everyone in the room who had an opinion seemed to be a fan. Also implies we should do FormData.toStream() (again, the idea not the name) for symmetry with other BodyInit types. Open question raised in the discussion: do we need to compute the total size synchronously to be able to report progress and populate Content-Length headers? Is that doable, i.e. is the encoded size + separators knowable given data length? Is this compatible with current architectures (i.e. Chrome's browser/renderer process split)? @annevk - did I miss anything? |
That sounds about right. I think for I guess the other question is whether there is some ToStream operation that takes an arbitrary object and invokes As for |
Regarding size, I think that is a somewhat orthogonal issue that can be solved separately. We could add .stream() ASAP, and later add .size if possible, or figure out some out-of-band way of passing through the size specific to whatever progression framework we come up with, or... For now, no Content-Length would get set. I don't quite remember what purpose the to-stream-able protocol would serve. I guess maybe some internal protocol that produces a { readableStream, optionalLength } structure could be used to remove the switch statements in Fetch, but that's just spec-factoring. @inexorabletash, I can prioritize working on this next week if you think the spec is ready to accept a PR. We're still figuring out how to interface streams with other specs nicely, so I think having me do the initial work for this spec would be nice. So, a few concrete questions:
|
I think the main benefit of a protocol (similar to |
I can't make spec editor or implementer commitments at the moment so no On Tuesday, September 27, 2016, Jimmy Karl Roland Wärting <
|
Now when i have tried converting mostly anything to a readable byte stream on a couple of things such as fetch, blob, formData, JSZip, TextEncoder/Decoder, Buffers, iterators, blinks sandboxed filesystem API, and even strings I'm starting to thing that @annevk got a good point about symbol |
So I've been sort or arguing against things like this in the past, primarily because it doesn't seem like adding more methods etc really helps much for the API when you can already achieve pretty much anything by calling So what to do about this. If I squint hard enough it sort of seems to make sense if a The alternative would of course be to not inherit from the So what do people think? Shoe-horn in |
Returning a new object each time from a getter is an anti-pattern. We want Given that, duplication coupled with partial modification (perhaps There might be ways to share a bunch of underlying infrastructure though and even some of the IDL if we split the mixin. I'd be open to such a refactoring of Fetch to enable this functionality on (I guess the one question I have is whether it makes sense to have blobs that once read can be collected. But I guess that would bring back |
I agree with @annevk that we should not try to reuse IDL and interface definitions where they don't fit perfectly. Embrace the spirit of JavaScript, and just make the names line up; that's what matters in the end. It's possible you could reuse some of the processing model, but probably not easily, so I'd suggest starting with new from-scratch definitions for all the methods and considering a refactoring afterward. I think .arrayBuffer(), .text(), and .stream() is the right place to start. You could do json(), but I'm skeptical it would be used as often. |
Sounds good to me. Totally agree that having getters return new objects all the time is really ugly, and reusing IDL just doesn't make much sense in this case. I guess one benefit for having as much of the same methods as Body, even if they seem silly/not used as much for blobs (i.e. |
* Add simpler reading methods to Blob interface. This fixes #40
Large Blob/Files becomes an issue if you don't slice it into chunks...
Streams brings other cool feature like pipe-ing, back pressure & transforming
Currently I'm using Response (part of Fetch) to transform a blob to a stream that i can "read into" step by step
This works okey. but it feels hacky.
Could we get new method to get a stream from File & Blob's please?
The text was updated successfully, but these errors were encountered: