node icon indicating copy to clipboard operation
node copied to clipboard

Implement `bytes()` method on Blob for reading bytes into a Uint8Array

Open bakkot opened this issue 1 year ago • 12 comments

See https://github.com/w3c/FileAPI/pull/198. This is like the existing arrayBuffer() method, but gives you a Uint8Array instead.

Tests at https://github.com/web-platform-tests/wpt/pull/46232

See also https://github.com/nodejs/undici/issues/3256 for the issue for doing the same for Request/Response.

There's also a PR adding the same method to PushMessageData, but I don't think it's relevant to node. Mentioning it here anyway just in case I'm wrong.

bakkot avatar May 13 '24 21:05 bakkot

@nodejs/web-standards (Summary) this appears to be a future standard, but none of the "big 3" have taken a stance on it yet, but W3C seems to be content with it.

avivkeller avatar May 13 '24 21:05 avivkeller

@RedYetiDev blob is a web standard, this method is added to the spec, we should definitely implement it (as experimental and remove experimental status when it lands).

benjamingr avatar May 13 '24 22:05 benjamingr

I won't implement it into fetch until it becomes standardized. I don't think node should land it either until then.

KhafraDev avatar May 13 '24 22:05 KhafraDev

@RedYetiDev blob is a web standard, this method is added to the spec, we should definitely implement it (as experimental and remove experimental status when it lands).

I don't think it is standard yet (bytes() atleast), I agree with @KhafraDev's stance. (But, I am not a CODEOWNER)

avivkeller avatar May 13 '24 22:05 avivkeller

Implementing before the spec lands is almost always a good idea since it's literally our last realistic chance to request changes or provide feedback when we see an API is problematic.

benjamingr avatar May 14 '24 16:05 benjamingr

That's a good point, but either way, I'm not involved in that process, undici handles this, right?

avivkeller avatar May 14 '24 16:05 avivkeller

Node handles this for Blob and undici handles it for request/response

benjamingr avatar May 14 '24 16:05 benjamingr

Thanks for the info. I'm marking this as feature-request, as it is a feature-request.

avivkeller avatar May 14 '24 16:05 avivkeller

If implemented, this would be experimental, hence the label

avivkeller avatar May 14 '24 16:05 avivkeller

almost always a good idea

There won't be anything problematic with it 😄.

KhafraDev avatar May 14 '24 16:05 KhafraDev

it did land in the spec already and I've opened a PR to add it to fetch

KhafraDev avatar May 14 '24 18:05 KhafraDev

The Request/Response one landed but Blob - this issue - is technically a different spec, and that PR is still open. (It's slightly more annoying because that spec lives in W3C, unlike fetch, and I haven't gone through the process of joining the relevant W3C working group.)

bakkot avatar May 14 '24 18:05 bakkot

The Blob PR is now merged.

bakkot avatar May 29 '24 19:05 bakkot

Just an update on the Big 3

Landed in WebKit: https://github.com/WebKit/WebKit/pull/28657 No comment from Chromium (yet) Confirmed by Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=1896509

avivkeller avatar May 29 '24 22:05 avivkeller