@lynx-js/tasm 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog.md +8 -0
- package/build/darwin/Release/lepus.node +0 -0
- package/build/linux/Release/lepus.node +0 -0
- package/index.js +25 -8
- package/lepus.d.ts +85 -0
- package/lepus.js +3969 -4838
- package/package.json +3 -2
package/ChangeLog.md
CHANGED
|
Binary file
|
|
Binary file
|
package/index.js
CHANGED
|
@@ -44,8 +44,7 @@ async function encode_wasm(options) {
|
|
|
44
44
|
return res;
|
|
45
45
|
}
|
|
46
46
|
function encode_napi(options) {
|
|
47
|
-
const
|
|
48
|
-
const lepus = require(bindingPath);
|
|
47
|
+
const lepus = require(`./build/${process.platform}/Release/lepus.node`);
|
|
49
48
|
const res = lepus.encode(JSON.stringify({...options}));
|
|
50
49
|
if (res.status !== 0) {
|
|
51
50
|
throw new Error(`encode error: ${res.error_msg}`);
|
|
@@ -69,15 +68,13 @@ function getEncodeMode(os) {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
function encrypt(plain) {
|
|
72
|
-
const
|
|
73
|
-
const lepus = require(bindingPath);
|
|
71
|
+
const lepus = require(`./build/${process.platform}/Release/lepus.node`);
|
|
74
72
|
const res = lepus.encrypt(plain);
|
|
75
73
|
return res
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
function decrypt(cipher) {
|
|
79
|
-
const
|
|
80
|
-
const lepus = require(bindingPath);
|
|
77
|
+
const lepus = require(`./build/${process.platform}/Release/lepus.node`);
|
|
81
78
|
const res = lepus.decrypt(cipher);
|
|
82
79
|
return res
|
|
83
80
|
}
|
|
@@ -96,8 +93,7 @@ function decrypt_wasm(plain) {
|
|
|
96
93
|
|
|
97
94
|
function decode_napi(templateJS) {
|
|
98
95
|
const templateArray = Uint8Array.from(templateJS);
|
|
99
|
-
const
|
|
100
|
-
const lepus = require(bindingPath);
|
|
96
|
+
const lepus = require(`./build/${process.platform}/Release/lepus.node`);
|
|
101
97
|
const res = lepus.decode(templateArray);
|
|
102
98
|
if (res.status !== 0) {
|
|
103
99
|
throw new Error(`decode error: ${res.error_msg}`);
|
|
@@ -126,6 +122,27 @@ function decode_wasm(buffer) {
|
|
|
126
122
|
return JSON.parse(res.result);
|
|
127
123
|
}
|
|
128
124
|
|
|
125
|
+
function decode_wasm(buffer) {
|
|
126
|
+
const Module = loadModule();
|
|
127
|
+
// console.log(templateJs);
|
|
128
|
+
// const uint8array = new Uint8Array(templateJs.size());
|
|
129
|
+
// const res = m._decode(uint8array);
|
|
130
|
+
const byteArray = new Uint8Array(buffer);
|
|
131
|
+
const byteArrayLength = byteArray.length;
|
|
132
|
+
// Allocate memory in the Emscripten heap
|
|
133
|
+
const byteArrayPtr = Module._malloc(byteArrayLength);
|
|
134
|
+
// Copy the data to the Emscripten heap
|
|
135
|
+
Module.HEAPU8.set(byteArray, byteArrayPtr);
|
|
136
|
+
// Call the C++ function
|
|
137
|
+
const res = Module._decode(byteArrayPtr, byteArrayLength);
|
|
138
|
+
// Free the allocated memory
|
|
139
|
+
Module._free(byteArrayPtr);
|
|
140
|
+
if (res.status !== 0) {
|
|
141
|
+
throw new Error(`decode error: ${res.result}`);
|
|
142
|
+
}
|
|
143
|
+
return res;
|
|
144
|
+
}
|
|
145
|
+
|
|
129
146
|
let encode = encode_napi;
|
|
130
147
|
module.exports = {
|
|
131
148
|
supportNapi,
|
package/lepus.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
|
|
2
|
+
declare namespace RuntimeExports {
|
|
3
|
+
/**
|
|
4
|
+
* @param {string=} returnType
|
|
5
|
+
* @param {Array=} argTypes
|
|
6
|
+
* @param {Object=} opts
|
|
7
|
+
*/
|
|
8
|
+
function cwrap(ident: any, returnType?: string, argTypes?: any[], opts?: any): any;
|
|
9
|
+
/**
|
|
10
|
+
* @param {string|null=} returnType
|
|
11
|
+
* @param {Array=} argTypes
|
|
12
|
+
* @param {Array=} args
|
|
13
|
+
* @param {Object=} opts
|
|
14
|
+
*/
|
|
15
|
+
function ccall(ident: any, returnType?: string, argTypes?: any[], args?: any[], opts?: any): any;
|
|
16
|
+
function allocateUTF8(...args: any[]): any;
|
|
17
|
+
/**
|
|
18
|
+
* Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
|
|
19
|
+
* emscripten HEAP, returns a copy of that string as a Javascript String object.
|
|
20
|
+
*
|
|
21
|
+
* @param {number} ptr
|
|
22
|
+
* @param {number=} maxBytesToRead - An optional length that specifies the
|
|
23
|
+
* maximum number of bytes to read. You can omit this parameter to scan the
|
|
24
|
+
* string until the first 0 byte. If maxBytesToRead is passed, and the string
|
|
25
|
+
* at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
|
|
26
|
+
* string will cut short at that byte index.
|
|
27
|
+
* @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
|
|
28
|
+
* @return {string}
|
|
29
|
+
*/
|
|
30
|
+
function UTF8ToString(ptr: number, maxBytesToRead?: number, ignoreNul?: boolean): string;
|
|
31
|
+
}
|
|
32
|
+
interface WasmModule {
|
|
33
|
+
_quickjsCheck(_0: number): void;
|
|
34
|
+
_createBufferPool(): number;
|
|
35
|
+
_dropBufferPool(_0: number): void;
|
|
36
|
+
_readBufferPool_data(_0: number, _1: number): number;
|
|
37
|
+
_readBufferPool_len(_0: number, _1: number): number;
|
|
38
|
+
_reencode_template_debug(_0: number, _1: number, _2: number, _3: number): number;
|
|
39
|
+
_lepusCheck(_0: number, _1: number, _2: number): number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string;
|
|
43
|
+
export interface ClassHandle {
|
|
44
|
+
isAliasOf(other: ClassHandle): boolean;
|
|
45
|
+
delete(): void;
|
|
46
|
+
deleteLater(): this;
|
|
47
|
+
isDeleted(): boolean;
|
|
48
|
+
// @ts-ignore - If targeting lower than ESNext, this symbol might not exist.
|
|
49
|
+
[Symbol.dispose](): void;
|
|
50
|
+
clone(): this;
|
|
51
|
+
}
|
|
52
|
+
export interface VectorUInt8 extends ClassHandle {
|
|
53
|
+
push_back(_0: number): void;
|
|
54
|
+
resize(_0: number, _1: number): void;
|
|
55
|
+
size(): number;
|
|
56
|
+
get(_0: number): number | undefined;
|
|
57
|
+
set(_0: number, _1: number): boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type EncodeResult = {
|
|
61
|
+
status: number,
|
|
62
|
+
error_msg: EmbindString,
|
|
63
|
+
buffer: VectorUInt8,
|
|
64
|
+
lepus_code: EmbindString,
|
|
65
|
+
lepus_debug: EmbindString,
|
|
66
|
+
section_size: EmbindString
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type DecodeResult = {
|
|
70
|
+
status: number,
|
|
71
|
+
result: EmbindString
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
interface EmbindModule {
|
|
75
|
+
VectorUInt8: {
|
|
76
|
+
new(): VectorUInt8;
|
|
77
|
+
};
|
|
78
|
+
_encode(_0: EmbindString): EncodeResult;
|
|
79
|
+
_quickjsCheck(_0: EmbindString): string;
|
|
80
|
+
_encode_ssr(_0: number, _1: number, _2: EmbindString): EncodeResult;
|
|
81
|
+
_decode(_0: number, _1: number): DecodeResult;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;
|
|
85
|
+
export default function MainModuleFactory (options?: unknown): MainModule;
|