Commit d91eb0b 1 parent e1b6e03 commit d91eb0b Copy full SHA for d91eb0b
File tree 1 file changed +16
-4
lines changed
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 1
1
const fs = require ( "fs" ) ;
2
2
3
- // TODO: Add the base64 decode function automagically
3
+ const decodeFunc = `
4
+ function _base64ToArrayBuffer(base64) {
5
+ var binary_string = window.atob(base64);
6
+ var len = binary_string.length;
7
+ var bytes = new Uint8Array(len);
8
+ for (var i = 0; i < len; i++) {
9
+ bytes[i] = binary_string.charCodeAt(i);
10
+ }
11
+ return bytes.buffer;
12
+ }` ;
4
13
5
14
module . exports = function base64wasm ( ) {
6
15
return {
7
16
name : 'base64-wasm-bundler' , // this name will show up in warnings and errors
8
17
async transform ( code , id ) {
9
- if ( id . endsWith ( ".wasm" ) ) {
18
+ if ( id . endsWith ( ".wasm" ) ) {
10
19
const base64 = fs . readFileSync ( id ) . toString ( "base64" ) ;
11
20
return {
12
- code : `export default "${ base64 } "` ,
21
+ code : `export default () => {
22
+ ${ decodeFunc }
23
+ return _base64ToArrayBuffer("${ base64 } ");
24
+ }` ,
13
25
map : { mappings : "" } ,
14
26
} ;
15
27
}
16
28
return null ;
17
- } ,
29
+ }
18
30
} ;
19
31
}
You can’t perform that action at this time.
0 commit comments