From b3cbd80deee3648a943da5a0e7b8f4f570d1211a Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Wed, 20 Mar 2024 13:12:49 +0800 Subject: [PATCH] example fix import buffer --- src/esploader.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/esploader.ts b/src/esploader.ts index e20c6c5..5130bec 100644 --- a/src/esploader.ts +++ b/src/esploader.ts @@ -1134,10 +1134,11 @@ export class ESPLoader { return resp; } - decodeBase64(romText: string) { + async decodeBase64(romText: string) { if (typeof window !== "undefined" && typeof window.atob === "function") { return window.atob(romText); } else { + const { Buffer } = await import("buffer"); return Buffer.from(romText, "base64").toString("binary"); } } @@ -1148,13 +1149,13 @@ export class ESPLoader { */ async runStub(): Promise { this.info("Uploading stub..."); - let decoded = this.decodeBase64(this.chip.ROM_TEXT); + let decoded = await this.decodeBase64(this.chip.ROM_TEXT); let chardata = decoded.split("").map(function (x) { return x.charCodeAt(0); }); const text = new Uint8Array(chardata); - decoded = this.decodeBase64(this.chip.ROM_DATA); + decoded = await this.decodeBase64(this.chip.ROM_DATA); chardata = decoded.split("").map(function (x) { return x.charCodeAt(0); });