Skip to content

Writer cannot cope with ArrayBuffer #43433

Description

@zhmushan

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

Activity

  1. added
    streamIssues and PRs related to Node.js streams.
    on Jun 17, 2022
  2. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    on Nov 4, 2022
  3. debadree25 commented on Dec 21, 2022

    @debadree25
    Contributor

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

  4. MarybethGasman commented on Feb 1, 2023

    @MarybethGasman

    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.

  5. MrJithil commented on Oct 9, 2023

    @MrJithil
    Member

    So, this can be closed?

  6. panva commented on Nov 9, 2023

    @panva
    Member

    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.

  7. added
    web-standardsIssues and PRs related to web-platform APIs and standards compliance.
    on Nov 9, 2023
  8. suuuuuuminnnnnn commented on Feb 21, 2026

    @suuuuuuminnnnnn
    Contributor

    I'd like to work on this issue if no one is currently working on it.

    I can investigate the BufferSource handling in CompressionStream / DecompressionStream and put together a PR with a regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.streamIssues and PRs related to Node.js streams.web streamsIssues and PRs related to the Web Streams API.web-standardsIssues and PRs related to web-platform APIs and standards compliance.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions