Use base122 encoding for WASM buffer (#127)

This commit is contained in:
Jaco Greeff
2020-10-27 09:04:37 +01:00
committed by GitHub
parent 08b72cc782
commit 35b2bb2d13
4 changed files with 171 additions and 12 deletions
+2 -2
View File
@@ -28,8 +28,8 @@ echo "*** Optimising WASM output"
../../binaryen/bin/wasm-opt $WSM -Os -o $OPT
# convert wasm to base64 structure
echo "*** Packing WASM into base64"
node ../../scripts/pack-wasm-base64.js
echo "*** Packing WASM into baseX"
node ../../scripts/pack-wasm-base.js
# build asmjs version from the input (optimised) WASM
echo "*** Building asm.js version"
+22
View File
@@ -0,0 +1,22 @@
// Copyright 2019-2020 @polkadot/wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const buffer = fs.readFileSync('./build/wasm_opt.wasm');
// base 64
// fs.writeFileSync('./build/wasm_wasm.js', `
// module.exports = Buffer.from('${buffer.toString('base64')}', 'base64');
// `);
// base 122
const { encode } = require('../packages/wasm-crypto/src/js/base122');
fs.writeFileSync('./build/wasm_wasm.js', `// Generated as part of the build, do not edit
const { decode } = require('./base122');
module.exports = Buffer.from(decode("${Buffer.from(encode(buffer)).toString('utf-8')}"));
`, { encoding: 'utf-8' });
-10
View File
@@ -1,10 +0,0 @@
// Copyright 2019-2020 @polkadot/wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const buffer = fs.readFileSync('./build/wasm_opt.wasm');
fs.writeFileSync('./build/wasm_wasm.js', `
module.exports = Buffer.from('${buffer.toString('base64')}', 'base64');
`);