You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Blob constructor error message when passing a string is misleading #38856
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 a USVString (which doesn't seem to be a sequence in that specification), or a DOMString (which is defined as a sequence<unsigned short> and unsigned short is not a BlobPart), but either way new 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
@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 on Blob supporting 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 😄
Activity
Ethan-Arrowood commentedon May 30, 2021
Oh looks like this is intentionally not supported
node/lib/internal/blob.js
Line 106 in 7919ced
Ethan-Arrowood commentedon May 30, 2021
Can we add a reason why to the docs?
bl-ue commentedon May 30, 2021
#36811
aduh95 commentedon May 30, 2021
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:
TypeError: Failed to construct 'Blob': The provided value cannot be converted to a sequence.TypeError: Blob constructor: Argument 1 can't be converted to a sequence.TypeError: Value is not a sequencejasnell commentedon May 31, 2021
This works just fine, however:
new Blob(['hello'])jasnell commentedon May 31, 2021
@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.Ethan-Arrowood commentedon May 31, 2021
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 😄
[-]Support string as source for Blob[/-][+]Blob constructor error message when passing a string is misleading[/+]buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string
buffer: improve Blob constructor error message when passing a string