Skip to content

Commit 35ad553

Browse files
committed
u8aToB64 js overflow fix
1 parent 040eb49 commit 35ad553

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

ghcjs/delivery-calculator/delivery-calculator.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: delivery-calculator
3-
version: 0.1.0.9
3+
version: 0.1.0.11
44
synopsis: Delivery Calculator
55
category: Web
66
build-type: Simple

ghcjs/delivery-calculator/trapeze.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
platforms:
22
android:
33
appName: Delivery Calculator
4-
versionCode: 9
5-
versionName: 0.1.0.9
4+
versionCode: 11
5+
versionName: 0.1.0.11
66
packageName: com.functora.delivery_calculator
77
manifest:
88
- file: AndroidManifest.xml

ghcjs/miso-functora/js/main.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export async function selectBarcode() {
156156
export async function saveFile(name, mime, ab) {
157157
const u8a = new Uint8Array(ab);
158158
if (Capacitor.isNativePlatform()) {
159-
const b64 = btoa(String.fromCharCode.apply(null, u8a));
159+
const b64 = await u8aToB64(u8a);
160160
const { uri } = await Filesystem.writeFile({
161161
path: name,
162162
data: b64,
@@ -170,6 +170,18 @@ export async function saveFile(name, mime, ab) {
170170
}
171171
}
172172

173+
async function u8aToB64(u8a) {
174+
const b64 = await new Promise((resolve, reject) => {
175+
const fr = new FileReader();
176+
fr.onload = () => {
177+
resolve(fr.result);
178+
};
179+
fr.onerror = reject;
180+
fr.readAsDataURL(new Blob([u8a]));
181+
});
182+
return b64.slice(b64.indexOf(",") + 1);
183+
}
184+
173185
export async function shareFiles(files) {
174186
if (Capacitor.isNativePlatform()) {
175187
const { value } = await Share.share({ files: files });

ghcjs/miso-functora/js/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)