From c8ac6180418a5151e4808e629dab2805f3b1c6a9 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Sun, 17 Dec 2023 15:58:59 +0200 Subject: [PATCH] fix: remove utf-8 encoding from contents --- src/utils/serveFromHar.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/serveFromHar.ts b/src/utils/serveFromHar.ts index b8146b2..ac85318 100644 --- a/src/utils/serveFromHar.ts +++ b/src/utils/serveFromHar.ts @@ -62,16 +62,17 @@ function findEntry( return bestEntry?.entry ?? null; } -async function parseContent(content: Content & { _file?: string }, dirName: string = ".") { +async function parseContent( + content: Omit & { text: Buffer | string }, + dirName: string = ".", +) { if (!content) return undefined; if (content._file && !content.text) { const contentFilePath = path.join(dirName, content._file); - content.text = await promises.readFile(contentFilePath, { - encoding: "utf8", - }); + content.text = await promises.readFile(contentFilePath); } if (!content.text) return undefined; - if (content.encoding === "base64") { + if (content.encoding === "base64" && typeof content.text === "string") { return Buffer.from(content.text, "base64"); } else { return content.text;