From 59db019696503ff178e4d07bbe7d8e04c947ff97 Mon Sep 17 00:00:00 2001 From: idanran <96647698+idanran@users.noreply.github.com> Date: Thu, 4 Apr 2024 00:39:41 +0800 Subject: [PATCH] fix(file): data is not an arraybuffer (#5) --- packages/file/src/adapter/node.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/file/src/adapter/node.ts b/packages/file/src/adapter/node.ts index ecf856c..ad54868 100644 --- a/packages/file/src/adapter/node.ts +++ b/packages/file/src/adapter/node.ts @@ -10,6 +10,8 @@ export async function loadFile(url: string): Promise { if (url.startsWith('file://')) { const data = await readFile(fileURLToPath(url)) const result = await fromBuffer(data) - return { mime: result?.mime, filename: basename(url), data } + // https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer#answer-31394257 + const buffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength) + return { mime: result?.mime, filename: basename(url), data: buffer } } }