Skip to content

Commit

Permalink
use atob lite instead (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianignacio5 authored Mar 20, 2024
1 parent 4c3f91e commit 22e115b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"url": "https://github.com/espressif/esptool-js/issues"
},
"dependencies": {
"atob-lite": "^2.0.0",
"pako": "^2.1.0",
"tslib": "^2.4.1"
},
Expand All @@ -38,6 +39,7 @@
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.1.0",
"@types/atob-lite": "^2.0.2",
"@types/pako": "^2.0.0",
"@types/w3c-web-serial": "^1.0.3",
"@typescript-eslint/eslint-plugin": "^5.43.0",
Expand Down
14 changes: 3 additions & 11 deletions src/esploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Data, deflate, Inflate } from "pako";
import { Transport, SerialOptions } from "./webserial.js";
import { ROM } from "./targets/rom.js";
import { customReset, usbJTAGSerialReset } from "./reset.js";
import atob from "atob-lite";

/* global SerialPort */

Expand Down Expand Up @@ -1134,28 +1135,19 @@ export class ESPLoader {
return resp;
}

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");
}
}

/**
* Upload the flasher ROM bootloader (flasher stub) to the chip.
* @returns {ROM} The Chip ROM
*/
async runStub(): Promise<ROM> {
this.info("Uploading stub...");
let decoded = await this.decodeBase64(this.chip.ROM_TEXT);
let decoded = atob(this.chip.ROM_TEXT);
let chardata = decoded.split("").map(function (x) {
return x.charCodeAt(0);
});
const text = new Uint8Array(chardata);

decoded = await this.decodeBase64(this.chip.ROM_DATA);
decoded = atob(this.chip.ROM_DATA);
chardata = decoded.split("").map(function (x) {
return x.charCodeAt(0);
});
Expand Down

0 comments on commit 22e115b

Please sign in to comment.