From 91224e5274d035c0a8d879c87ccf390c3c765897 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 19 Sep 2023 13:45:56 +0200 Subject: [PATCH] :zap: Add minor optimizations to data-uri->blob helper --- frontend/src/app/util/webapi.cljs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/util/webapi.cljs b/frontend/src/app/util/webapi.cljs index 21675a01b..9be8d1737 100644 --- a/frontend/src/app/util/webapi.cljs +++ b/frontend/src/app/util/webapi.cljs @@ -74,14 +74,16 @@ (defn data-uri->blob [data-uri] - (let [[mtype b64-data] (str/split data-uri ";base64,") + (let [[mtype b64-data] (str/split data-uri ";base64," 2) mtype (subs mtype (inc (str/index-of mtype ":"))) decoded (.atob js/window b64-data) size (.-length ^js decoded) content (js/Uint8Array. size)] - (doseq [i (range 0 size)] - (aset content i (.charCodeAt ^js decoded i))) + (loop [i 0] + (when (< i size) + (aset content i (.charCodeAt ^js decoded i)) + (recur (inc i)))) (create-blob content mtype)))