Skip to content

Commit 8d8d9af

Browse files
committed
Add rollup
1 parent 87afc09 commit 8d8d9af

17 files changed

+6577
-120
lines changed

.gitignore

+2-36
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,27 @@
22
logs
33
*.log
44
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
8-
# Runtime data
9-
pids
10-
*.pid
11-
*.seed
12-
*.pid.lock
13-
14-
# Directory for instrumented libs generated by jscoverage/JSCover
15-
lib-cov
165

176
# Coverage directory used by tools like istanbul
187
coverage
198

20-
# nyc test coverage
21-
.nyc_output
22-
23-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24-
.grunt
25-
26-
# Bower dependency directory (https://bower.io/)
27-
bower_components
28-
29-
# node-waf configuration
30-
.lock-wscript
31-
32-
# Compiled binary addons (http://nodejs.org/api/addons.html)
33-
build/Release
34-
359
# Dependency directories
3610
node_modules/
37-
jspm_packages/
38-
39-
# Typescript v1 declaration files
40-
typings/
4111

4212
# Optional npm cache directory
4313
.npm
4414

4515
# Optional eslint cache
4616
.eslintcache
4717

48-
# Optional REPL history
49-
.node_repl_history
50-
5118
# Output of 'npm pack'
5219
*.tgz
5320

54-
# Yarn Integrity file
55-
.yarn-integrity
56-
5721
# dotenv environment variables file
5822
.env
5923

6024
dist
6125

6226
.jest-cache
27+
28+
wasm

.npmignore

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Coverage directory used by tools like istanbul
7+
coverage
8+
9+
# Dependency directories
10+
node_modules/
11+
12+
# Optional npm cache directory
13+
.npm
14+
15+
# Optional eslint cache
16+
.eslintcache
17+
18+
# Output of 'npm pack'
19+
*.tgz
20+
21+
# dotenv environment variables file
22+
.env
23+
24+
dist
25+
26+
.jest-cache
27+
28+
wasm
29+
30+
benchmark
31+
test
32+
scripts

benchmark/.gitignore

+3-37
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,25 @@
22
logs
33
*.log
44
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
8-
# Runtime data
9-
pids
10-
*.pid
11-
*.seed
12-
*.pid.lock
13-
14-
# Directory for instrumented libs generated by jscoverage/JSCover
15-
lib-cov
165

176
# Coverage directory used by tools like istanbul
187
coverage
198

20-
# nyc test coverage
21-
.nyc_output
22-
23-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24-
.grunt
25-
26-
# Bower dependency directory (https://bower.io/)
27-
bower_components
28-
29-
# node-waf configuration
30-
.lock-wscript
31-
32-
# Compiled binary addons (http://nodejs.org/api/addons.html)
33-
build/Release
34-
359
# Dependency directories
3610
node_modules/
37-
jspm_packages/
38-
39-
# Typescript v1 declaration files
40-
typings/
4111

4212
# Optional npm cache directory
4313
.npm
4414

4515
# Optional eslint cache
4616
.eslintcache
4717

48-
# Optional REPL history
49-
.node_repl_history
50-
5118
# Output of 'npm pack'
5219
*.tgz
5320

54-
# Yarn Integrity file
55-
.yarn-integrity
56-
5721
# dotenv environment variables file
5822
.env
5923

60-
dist
24+
dist
25+
26+
.jest-cache

build.sh

-12
This file was deleted.

build_all.sh

-10
This file was deleted.

lib/WASMInterface.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const fs = require('fs');
21
const MAX_HEAP = 16 * 1024;
32

43
export type ITypedArray = Uint8Array | Uint16Array | Uint32Array | ArrayBuffer;
@@ -9,13 +8,18 @@ type ThenArg<T> = T extends Promise<infer U> ? U :
98

109
export type IWASMInterface = ThenArg<ReturnType<typeof WASMInterface>>;
1110

12-
async function WASMInterface (hashName: string, hashLength: number) {
11+
async function WASMInterface (binary: any, hashLength: number) {
1312
let wasmInstance = null;
1413
let arrayOffset: number = -1;
1514
let memoryView: Uint8Array = null;
1615

16+
const getBinary = async (): Promise<Uint8Array> => {
17+
const buf = Buffer.from(binary.data, 'base64');
18+
return Promise.resolve(new Uint8Array(buf.buffer, buf.byteOffset, buf.length));
19+
}
20+
1721
const loadWASM = async () => {
18-
const binary = fs.readFileSync(`./dist/${hashName}.wasm`);
22+
let binary = await getBinary();
1923
wasmInstance = (await WebAssembly.instantiate(binary)).instance;
2024
wasmInstance.exports._start();
2125
arrayOffset = wasmInstance.exports.Hash_GetBuffer();

lib/crc32.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import WASMInterface, { ITypedArray, IWASMInterface } from './WASMInterface';
2+
import wasmJson from '../wasm/crc32.wasm.json';
23

34
let wasm: IWASMInterface = null;
45

56
export async function crc32 (data: string | Buffer | ITypedArray): Promise<string> {
67
if (!wasm) {
7-
wasm = await WASMInterface('crc32', 4);
8+
wasm = await WASMInterface(wasmJson, 4);
89
}
910

1011
return wasm.hash(data);
1112
}
1213

1314
export async function createCRC32() {
1415
if (!wasm) {
15-
wasm = await WASMInterface('crc32', 4);
16+
wasm = await WASMInterface(wasmJson, 4);
1617
wasm.init();
1718
}
1819

@@ -22,3 +23,5 @@ export async function createCRC32() {
2223
digest: wasm.digest,
2324
};
2425
};
26+
27+
export default crc32;

lib/md4.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import WASMInterface, { ITypedArray, IWASMInterface } from './WASMInterface';
2+
import wasmJson from '../wasm/md4.wasm.json';
23

34
let wasm: IWASMInterface = null;
45

56
export async function md4 (data: string | Buffer | ITypedArray): Promise<string> {
67
if (!wasm) {
7-
wasm = await WASMInterface('md4', 16);
8+
wasm = await WASMInterface(wasmJson, 16);
89
}
910

1011
return wasm.hash(data);
1112
}
1213

1314
export async function createMD4() {
1415
if (!wasm) {
15-
wasm = await WASMInterface('md4', 16);
16+
wasm = await WASMInterface(wasmJson, 16);
1617
wasm.init();
1718
}
1819

@@ -22,3 +23,5 @@ export async function createMD4() {
2223
digest: wasm.digest,
2324
};
2425
};
26+
27+
export default md4;

lib/md5.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import WASMInterface, { ITypedArray, IWASMInterface } from './WASMInterface';
2+
import wasmJson from '../wasm/md5.wasm.json';
23

34
let wasm: IWASMInterface = null;
45

56
export async function md5 (data: string | Buffer | ITypedArray): Promise<string> {
67
if (!wasm) {
7-
wasm = await WASMInterface('md5', 16);
8+
wasm = await WASMInterface(wasmJson, 16);
89
}
910

1011
return wasm.hash(data);
1112
}
1213

1314
export async function createMD5() {
1415
if (!wasm) {
15-
wasm = await WASMInterface('md5', 16);
16+
wasm = await WASMInterface(wasmJson, 16);
1617
wasm.init();
1718
}
1819

@@ -22,3 +23,5 @@ export async function createMD5() {
2223
digest: wasm.digest,
2324
};
2425
};
26+
27+
export default md5;

0 commit comments

Comments
 (0)