From 73cec8f08af618f05a219de20c6e8df2a42b3f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E6=B5=B7=20Liang=20Hai?= Date: Sat, 27 Jun 2026 20:14:17 +0200 Subject: [PATCH 1/2] Allow `new Blob()` to accept Uint8Array directly 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(). --- src/blob.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/blob.ts b/src/blob.ts index 3224896..787c09a 100644 --- a/src/blob.ts +++ b/src/blob.ts @@ -10,12 +10,13 @@ export class Blob { /** * @param data Binary font data. */ - constructor(data: ArrayBuffer) { - const blobPtr = exports.malloc(data.byteLength); - Module.HEAPU8.set(new Uint8Array(data), blobPtr); + constructor(data: Uint8Array | ArrayBuffer) { + const array = data instanceof Uint8Array ? data : new Uint8Array(data) + const blobPtr = exports.malloc(array.byteLength); + Module.HEAPU8.set(array, blobPtr); this.ptr = exports.hb_blob_create( blobPtr, - data.byteLength, + array.byteLength, 2 /* HB_MEMORY_MODE_WRITABLE */, blobPtr, freeFuncPtr, From 6fe7712b8be84dbfb33b4b49981e6c80a97f631f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E6=B5=B7=20Liang=20Hai?= Date: Sat, 27 Jun 2026 20:34:43 +0200 Subject: [PATCH 2/2] npx prettier --write . --- src/blob.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blob.ts b/src/blob.ts index 787c09a..58e56ed 100644 --- a/src/blob.ts +++ b/src/blob.ts @@ -11,7 +11,7 @@ export class Blob { * @param data Binary font data. */ constructor(data: Uint8Array | ArrayBuffer) { - const array = data instanceof Uint8Array ? data : new Uint8Array(data) + const array = data instanceof Uint8Array ? data : new Uint8Array(data); const blobPtr = exports.malloc(array.byteLength); Module.HEAPU8.set(array, blobPtr); this.ptr = exports.hb_blob_create(