Repository navigation
Blob constructor error message when passing a string is misleading #38856
Description
Activity
Oh looks like this is intentionally not supported
Line 106 in 7919ced
typeof sources === 'string') { Can we add a reason why to the docs?
Here's my interpretation of why a string is not accepted: The specs dictates that the param must be a
sequence<BlobPart>. It's not clear to me if the string is interpreted as aUSVString(which doesn't seem to be a sequence in that specification), or aDOMString(which is defined as asequence<unsigned short>andunsigned shortis not aBlobPart), but either waynew Blob('string')is meant to fail.Now I agree the error message is misleading, for reference here's the error messages thrown by some browsers:
- Chromium:
TypeError: Failed to construct 'Blob': The provided value cannot be converted to a sequence. - Firefox:
TypeError: Blob constructor: Argument 1 can't be converted to a sequence. - Safari:
TypeError: Value is not a sequence
Reacted by bl-ue, Ethan Arrowood and Anna Henningsen- Chromium:
- addedbufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.errorsIssues and PRs related to JavaScript errors originating in Node.js core.Issues and PRs related to JavaScript errors originating in Node.js core.
on May 30, 2021 This works just fine, however:
new Blob(['hello'])Reacted by Ethan Arrowood@Ethan-Arrowood ... just as a heads up since you're using
Blob... sometime in the next two months as time allows, I will be working onBlobsupporting async data sources. It won't impact the API usage at all, but figured it's worthwhile to give a heads up.Yes I saw that, very excited for it. I'm using this in undici-fetch and it'll be a nice perf boost if blob can support the async iterator sources directly 😄
- changed the title
[-]Support string as source for Blob[/-][+]Blob constructor error message when passing a string is misleading[/+]on Jun 1, 2021 - added a commit that references this issue
on Apr 4, 2022 - added a commit that references this issue
on Apr 25, 2022 - added a commit that references this issue
on May 31, 2022 - added a commit that references this issue
on Jun 27, 2022 - added a commit that references this issue
on Jul 11, 2022 - added a commit that references this issue
on Jul 31, 2022 - added a commit that references this issue
on Oct 10, 2022
Is your feature request related to a problem? Please describe.
Working with the new Blob api. Cannot instantiate using a string though I don't see why not.
Describe the solution you'd like
Maybe I'm misunderstanding, but I think strings to implement [Symbol.iterator]; does that not make it an instance of Iterable?
Describe alternatives you've considered
Plenty of work arounds - think this would make for a good addition.
Happy to contribute this feature too