From ca664cb1a0324798585aaf2c2daaf0b959c648cb Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 23 Jan 2023 13:52:42 +0100 Subject: [PATCH] use buffer first, add changelog --- changelogs/unreleased/1264-dark64 | 1 + zokrates_js/patch.js | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 changelogs/unreleased/1264-dark64 diff --git a/changelogs/unreleased/1264-dark64 b/changelogs/unreleased/1264-dark64 new file mode 100644 index 00000000..c9d64e90 --- /dev/null +++ b/changelogs/unreleased/1264-dark64 @@ -0,0 +1 @@ +Optimize `zokrates-js` library size \ No newline at end of file diff --git a/zokrates_js/patch.js b/zokrates_js/patch.js index 4e33e752..4f4c19aa 100644 --- a/zokrates_js/patch.js +++ b/zokrates_js/patch.js @@ -18,17 +18,17 @@ import pako from "pako"; let bytes; - if (typeof atob === 'function') { + if (typeof Buffer === "function") { + bytes = Buffer.from(encoded, "base64"); + } else if (typeof atob === "function") { const binary = atob(encoded); bytes = new Uint8Array(binary.length); - + for (let i = 0; i < binary.length; i++) { bytes[i] = binary.charCodeAt(i); - } - } else if (typeof Buffer === 'function') { - bytes = Buffer.from(encoded, 'base64'); + } } else { - throw new Error('Unsupported platform'); + throw new Error("Unsupported platform"); } const imports = getImports();