Skip to content

Error in example code for Deflate-compressing an ArrayBuffer #81

@runbing

Description

@runbing

What is the issue with the Compression Standard?

There is an error in the example code in section 7.2. Deflate-compress an ArrayBuffer to a Uint8Array.

for (const chunk of cs.readable) {
  output.push(value);
  totalSize += value.byteLength;
}

When reading chunks from the CompressionStream object, it attempts to iterate the ReadableStream object synchronously, which would cause an error. The correct form is asynchronous.

Additionally, the variable value is not defined in this context and should likely be chunk.

for await (const chunk of cs.readable) {
  output.push(chunk);
  totalSize += chunk.byteLength;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions