nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107k stars 29.29k forks source link

`Writer` cannot cope with `ArrayBuffer` #43433

Open zhmushan opened 2 years ago

zhmushan commented 2 years ago

Version

v19.0.0-pre

Platform

Darwin

Subsystem

web/streams

What steps will reproduce the bug?

Try the following code both on chrome & nodejs:

const str = "H4sIAAAAAAAAE0vLzwcAIWVzjAMAAAA=";
const buf = Uint8Array.from(atob(str), c => c.charCodeAt(0));
const ds = new DecompressionStream("gzip");
const writer = ds.writable.getWriter();
writer.write(buf.buffer);
writer.close();
await new Response(ds.readable).arrayBuffer();

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

node:internal/errors:477
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of ArrayBuffer
    at new NodeError (node:internal/errors:388:5)
    at _write (node:internal/streams/writable:315:13)
    at Writable.write (node:internal/streams/writable:337:10)
    at Object.write (node:internal/webstreams/adapters:166:63)
    at ensureIsPromise (node:internal/webstreams/util:172:19)
    at writableStreamDefaultControllerProcessWrite (node:internal/webstreams/writablestream:1091:5)
    at writableStreamDefaultControllerAdvanceQueueIfNeeded (node:internal/webstreams/writablestream:1206:5)
    at node:internal/webstreams/writablestream:1278:7 {
  code: 'ERR_INVALID_ARG_TYPE'
}

Additional information

No response

debadree25 commented 1 year ago

For this issue is the function write supposed to work on Buffer | Uint8Array | ArrayBuffer? cc @ronag @VoltrexKeyva

MarybethGasman commented 1 year ago

According to the documentation, the function write is not supposed to work on \<ArrayBuffer> in node.(It works in chrome.)

writer.write(buf);

Using \<Uint8Array> is fine.

MrJithil commented 12 months ago

So, this can be closed?

panva commented 11 months ago

For this issue is the function write supposed to work on Buffer | Uint8Array | ArrayBuffer?

So, this can be closed?

No, CompressionStream and DecompressionStream are supposed to handle BufferSource, that means, as per how this is done WebCryptoAPI - <ArrayBuffer> | <TypedArray> | <DataView> | <Buffer> should all be valid chunks.

The WPTs for this will soon be enabled #50631.