generated from denorg/starter
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move to base91 to decrease wasm size
- Loading branch information
Showing
2 changed files
with
5 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
|
@@ -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)); | ||
|
Oops, something went wrong.