Skip to content

Allow new Blob() to accept Uint8Array directly - #220

Merged
khaledhosny merged 2 commits into
harfbuzz:mainfrom
lianghai:main
Jun 27, 2026
Merged

Allow new Blob() to accept Uint8Array directly#220
khaledhosny merged 2 commits into
harfbuzz:mainfrom
lianghai:main

Conversation

@lianghai

@lianghai lianghai commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Often an Uint8Array is already available. For example, Node.js Buffer is compatible with Uint8Array, and .bytes() has also been recently added to the Response API in addition to .arrayBuffer() (see also the background discussion).

Converting an Uint8Array to an ArrayBuffer can also be error-prone because of the sharing of an underlying ArrayBuffer (I just got bitten by this in the Unicode core spec’s codebase…). For example, instead of:

const arrayBuffer = readFileSync(path).buffer;

One must remember to do:

const buffer = readFileSync(path);
const arrayBuffer = buffer.buffer.slice(
  buffer.byteOffset,
  buffer.byteOffset + buffer.byteLength,
);

This PR also fixes the type error at:

var blob = new Blob(fs.readFileSync(fontPath));

lianghai added 2 commits June 27, 2026 20:14
Often an Uint8Array is already available. For example, Node.js Buffer is already compatible with Uint8Array, and .bytes() has also been recently added to Response in addition to .arrayBuffer().
@khaledhosny
khaledhosny merged commit f7c5a54 into harfbuzz:main Jun 27, 2026
3 checks passed
@khaledhosny

Copy link
Copy Markdown
Contributor

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants