Skip to content

Commit

Permalink
Decrease JS output size by encoding WASM as base64
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewLM committed Dec 7, 2023
1 parent 294f4c9 commit be03388
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions coinlib/bin/build_wasm.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'docker_util.dart';
import 'util.dart';
Expand Down Expand Up @@ -83,10 +84,10 @@ RUN ${WASI_SDK_PATH}/bin/wasm-ld \

void binaryFileToDart(String inPath, String outPath, String name) {
final bytes = File(inPath).readAsBytesSync();
final hexList = bytes.map((b) => "0x${b.toRadixString(16)}").join(",");
final b64 = base64Encode(bytes);
final output = """\
import 'dart:typed_data';
final $name = Uint8List.fromList([$hexList]);""";
import 'dart:convert';
final $name = base64Decode("$b64");""";
File(outPath).writeAsStringSync(output, flush: true);
}

Expand Down
4 changes: 2 additions & 2 deletions coinlib/lib/src/secp256k1/secp256k1.wasm.g.dart

Large diffs are not rendered by default.

0 comments on commit be03388

Please sign in to comment.