Skip to content

Commit

Permalink
feat: move to base91 to decrease wasm size
Browse files Browse the repository at this point in the history
  • Loading branch information
oplik0 authored Jun 13, 2022
1 parent dbdbbdb commit 5fecf11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/_wasm/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// adopted from https://deno.land/[email protected]/hash/_wasm/build.ts
import { encode as base64Encode } from "https://deno.land/[email protected]/encoding/base64.ts";
import { encode as base91Encode } from "https://deno.land/x/base91/base91.ts";

// 1. build wasm
async function buildWasm(path: string): Promise<void> {
Expand All @@ -25,16 +25,16 @@ async function buildWasm(path: string): Promise<void> {
// 2. encode wasm
async function encodeWasm(wasmPath: string): Promise<string> {
const wasm = await Deno.readFile(`${wasmPath}/scrypt_wasm_bg.wasm`);
return base64Encode(wasm);
return base91Encode(wasm);
}

// 3. generate script
async function generate(wasm: string, output: string): Promise<void> {
const initScript = await Deno.readTextFile(`${output}/scrypt_wasm.js`);
const denoHashScript = "/* eslint-disable */\n"
+ "//deno-fmt-ignore-file\n"
+ `import * as base64 from "https://deno.land/[email protected]/encoding/base64.ts";`
+ `export const source = base64.decode("${wasm}");`
+ `import { decode } from "https://deno.land/x/base91/base91.ts";`
+ `export const source = decode("${wasm.replaceAll('"', '\\"')}");`
+ initScript;

await Deno.writeFile("wasm.js", new TextEncoder().encode(denoHashScript));
Expand Down
Loading

0 comments on commit 5fecf11

Please sign in to comment.