@napi-rs/tar-wasm32-wasi 0.1.1
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/README.md +3 -0
- package/package.json +37 -0
- package/tar.wasi-browser.js +71 -0
- package/tar.wasi.cjs +102 -0
- package/tar.wasm32-wasi.wasm +0 -0
- package/wasi-worker-browser.mjs +32 -0
- package/wasi-worker.mjs +63 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@napi-rs/tar-wasm32-wasi",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"cpu": [
|
|
5
|
+
"wasm32"
|
|
6
|
+
],
|
|
7
|
+
"main": "tar.wasi.cjs",
|
|
8
|
+
"files": [
|
|
9
|
+
"tar.wasm32-wasi.wasm",
|
|
10
|
+
"tar.wasi.cjs",
|
|
11
|
+
"tar.wasi-browser.js",
|
|
12
|
+
"wasi-worker.mjs",
|
|
13
|
+
"wasi-worker-browser.mjs"
|
|
14
|
+
],
|
|
15
|
+
"description": "Node.js tar binding https://docs.rs/tar/latest/tar/",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"napi-rs",
|
|
18
|
+
"NAPI",
|
|
19
|
+
"N-API",
|
|
20
|
+
"Rust",
|
|
21
|
+
"node-addon",
|
|
22
|
+
"node-addon-api"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=14.0.0"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"registry": "https://registry.npmjs.org/",
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"repository": "git@github.com:napi-rs/tar.git",
|
|
33
|
+
"browser": "tar.wasi-browser.js",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@napi-rs/wasm-runtime": "^0.2.3"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
|
|
3
|
+
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
|
+
WASI as __WASI,
|
|
5
|
+
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
|
6
|
+
} from '@napi-rs/wasm-runtime'
|
|
7
|
+
|
|
8
|
+
import __wasmUrl from './tar.wasm32-wasi.wasm?url'
|
|
9
|
+
|
|
10
|
+
const __wasi = new __WASI({
|
|
11
|
+
version: 'preview1',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const __emnapiContext = __emnapiGetDefaultContext()
|
|
15
|
+
|
|
16
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
17
|
+
initial: 4000,
|
|
18
|
+
maximum: 65536,
|
|
19
|
+
shared: true,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
instance: __napiInstance,
|
|
26
|
+
module: __wasiModule,
|
|
27
|
+
napiModule: __napiModule,
|
|
28
|
+
} = __emnapiInstantiateNapiModuleSync(__wasmFile, {
|
|
29
|
+
context: __emnapiContext,
|
|
30
|
+
asyncWorkPoolSize: 4,
|
|
31
|
+
wasi: __wasi,
|
|
32
|
+
onCreateWorker() {
|
|
33
|
+
const worker = new Worker(new URL('@napi-rs/tar-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url), {
|
|
34
|
+
type: 'module',
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return worker
|
|
38
|
+
},
|
|
39
|
+
overwriteImports(importObject) {
|
|
40
|
+
importObject.env = {
|
|
41
|
+
...importObject.env,
|
|
42
|
+
...importObject.napi,
|
|
43
|
+
...importObject.emnapi,
|
|
44
|
+
memory: __sharedMemory,
|
|
45
|
+
}
|
|
46
|
+
return importObject
|
|
47
|
+
},
|
|
48
|
+
beforeInit({ instance }) {
|
|
49
|
+
__napi_rs_initialize_modules(instance)
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
function __napi_rs_initialize_modules(__napiInstance) {
|
|
54
|
+
__napiInstance.exports['__napi_register__Entries_struct_0']?.()
|
|
55
|
+
__napiInstance.exports['__napi_register__Entries_impl_1']?.()
|
|
56
|
+
__napiInstance.exports['__napi_register__Entry_struct_2']?.()
|
|
57
|
+
__napiInstance.exports['__napi_register__Entry_impl_5']?.()
|
|
58
|
+
__napiInstance.exports['__napi_register__EntryType_6']?.()
|
|
59
|
+
__napiInstance.exports['__napi_register__Header_struct_7']?.()
|
|
60
|
+
__napiInstance.exports['__napi_register__Header_impl_37']?.()
|
|
61
|
+
__napiInstance.exports['__napi_register__ReadonlyHeader_struct_38']?.()
|
|
62
|
+
__napiInstance.exports['__napi_register__ReadonlyHeader_impl_54']?.()
|
|
63
|
+
__napiInstance.exports['__napi_register__Archive_struct_55']?.()
|
|
64
|
+
__napiInstance.exports['__napi_register__Archive_impl_66']?.()
|
|
65
|
+
}
|
|
66
|
+
export const Archive = __napiModule.exports.Archive
|
|
67
|
+
export const Entries = __napiModule.exports.Entries
|
|
68
|
+
export const Entry = __napiModule.exports.Entry
|
|
69
|
+
export const Header = __napiModule.exports.Header
|
|
70
|
+
export const ReadonlyHeader = __napiModule.exports.ReadonlyHeader
|
|
71
|
+
export const EntryType = __napiModule.exports.EntryType
|
package/tar.wasi.cjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const __nodeFs = require('node:fs')
|
|
7
|
+
const __nodePath = require('node:path')
|
|
8
|
+
const { WASI: __nodeWASI } = require('node:wasi')
|
|
9
|
+
const { Worker } = require('node:worker_threads')
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
13
|
+
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
|
+
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
15
|
+
} = require('@napi-rs/wasm-runtime')
|
|
16
|
+
|
|
17
|
+
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
18
|
+
|
|
19
|
+
const __wasi = new __nodeWASI({
|
|
20
|
+
version: 'preview1',
|
|
21
|
+
env: process.env,
|
|
22
|
+
preopens: {
|
|
23
|
+
[__rootDir]: __rootDir,
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const __emnapiContext = __emnapiGetDefaultContext()
|
|
28
|
+
|
|
29
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
30
|
+
initial: 4000,
|
|
31
|
+
maximum: 65536,
|
|
32
|
+
shared: true,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
let __wasmFilePath = __nodePath.join(__dirname, 'tar.wasm32-wasi.wasm')
|
|
36
|
+
const __wasmDebugFilePath = __nodePath.join(__dirname, 'tar.wasm32-wasi.debug.wasm')
|
|
37
|
+
|
|
38
|
+
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
39
|
+
__wasmFilePath = __wasmDebugFilePath
|
|
40
|
+
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
41
|
+
try {
|
|
42
|
+
__wasmFilePath = __nodePath.resolve('@napi-rs/tar-wasm32-wasi')
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error('Cannot find tar.wasm32-wasi.wasm file, and @napi-rs/tar-wasm32-wasi package is not installed.')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
49
|
+
context: __emnapiContext,
|
|
50
|
+
asyncWorkPoolSize: (function() {
|
|
51
|
+
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
52
|
+
// NaN > 0 is false
|
|
53
|
+
if (threadsSizeFromEnv > 0) {
|
|
54
|
+
return threadsSizeFromEnv
|
|
55
|
+
} else {
|
|
56
|
+
return 4
|
|
57
|
+
}
|
|
58
|
+
})(),
|
|
59
|
+
wasi: __wasi,
|
|
60
|
+
onCreateWorker() {
|
|
61
|
+
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
62
|
+
env: process.env,
|
|
63
|
+
execArgv: ['--experimental-wasi-unstable-preview1'],
|
|
64
|
+
})
|
|
65
|
+
worker.onmessage = ({ data }) => {
|
|
66
|
+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
67
|
+
}
|
|
68
|
+
return worker
|
|
69
|
+
},
|
|
70
|
+
overwriteImports(importObject) {
|
|
71
|
+
importObject.env = {
|
|
72
|
+
...importObject.env,
|
|
73
|
+
...importObject.napi,
|
|
74
|
+
...importObject.emnapi,
|
|
75
|
+
memory: __sharedMemory,
|
|
76
|
+
}
|
|
77
|
+
return importObject
|
|
78
|
+
},
|
|
79
|
+
beforeInit({ instance }) {
|
|
80
|
+
__napi_rs_initialize_modules(instance)
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
function __napi_rs_initialize_modules(__napiInstance) {
|
|
85
|
+
__napiInstance.exports['__napi_register__Entries_struct_0']?.()
|
|
86
|
+
__napiInstance.exports['__napi_register__Entries_impl_1']?.()
|
|
87
|
+
__napiInstance.exports['__napi_register__Entry_struct_2']?.()
|
|
88
|
+
__napiInstance.exports['__napi_register__Entry_impl_5']?.()
|
|
89
|
+
__napiInstance.exports['__napi_register__EntryType_6']?.()
|
|
90
|
+
__napiInstance.exports['__napi_register__Header_struct_7']?.()
|
|
91
|
+
__napiInstance.exports['__napi_register__Header_impl_37']?.()
|
|
92
|
+
__napiInstance.exports['__napi_register__ReadonlyHeader_struct_38']?.()
|
|
93
|
+
__napiInstance.exports['__napi_register__ReadonlyHeader_impl_54']?.()
|
|
94
|
+
__napiInstance.exports['__napi_register__Archive_struct_55']?.()
|
|
95
|
+
__napiInstance.exports['__napi_register__Archive_impl_66']?.()
|
|
96
|
+
}
|
|
97
|
+
module.exports.Archive = __napiModule.exports.Archive
|
|
98
|
+
module.exports.Entries = __napiModule.exports.Entries
|
|
99
|
+
module.exports.Entry = __napiModule.exports.Entry
|
|
100
|
+
module.exports.Header = __napiModule.exports.Header
|
|
101
|
+
module.exports.ReadonlyHeader = __napiModule.exports.ReadonlyHeader
|
|
102
|
+
module.exports.EntryType = __napiModule.exports.EntryType
|
|
Binary file
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
|
|
2
|
+
|
|
3
|
+
const handler = new MessageHandler({
|
|
4
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
5
|
+
const wasi = new WASI({
|
|
6
|
+
print: function () {
|
|
7
|
+
// eslint-disable-next-line no-console
|
|
8
|
+
console.log.apply(console, arguments)
|
|
9
|
+
},
|
|
10
|
+
printErr: function() {
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
console.error.apply(console, arguments)
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
16
|
+
childThread: true,
|
|
17
|
+
wasi,
|
|
18
|
+
overwriteImports(importObject) {
|
|
19
|
+
importObject.env = {
|
|
20
|
+
...importObject.env,
|
|
21
|
+
...importObject.napi,
|
|
22
|
+
...importObject.emnapi,
|
|
23
|
+
memory: wasmMemory,
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
globalThis.onmessage = function (e) {
|
|
31
|
+
handler.handle(e)
|
|
32
|
+
}
|
package/wasi-worker.mjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { parse } from "node:path";
|
|
4
|
+
import { WASI } from "node:wasi";
|
|
5
|
+
import { parentPort, Worker } from "node:worker_threads";
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
|
|
10
|
+
|
|
11
|
+
if (parentPort) {
|
|
12
|
+
parentPort.on("message", (data) => {
|
|
13
|
+
globalThis.onmessage({ data });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Object.assign(globalThis, {
|
|
18
|
+
self: globalThis,
|
|
19
|
+
require,
|
|
20
|
+
Worker,
|
|
21
|
+
importScripts: function (f) {
|
|
22
|
+
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
|
|
23
|
+
},
|
|
24
|
+
postMessage: function (msg) {
|
|
25
|
+
if (parentPort) {
|
|
26
|
+
parentPort.postMessage(msg);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const emnapiContext = getDefaultContext();
|
|
32
|
+
|
|
33
|
+
const __rootDir = parse(process.cwd()).root;
|
|
34
|
+
|
|
35
|
+
const handler = new MessageHandler({
|
|
36
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
37
|
+
const wasi = new WASI({
|
|
38
|
+
version: 'preview1',
|
|
39
|
+
env: process.env,
|
|
40
|
+
preopens: {
|
|
41
|
+
[__rootDir]: __rootDir,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
46
|
+
childThread: true,
|
|
47
|
+
wasi,
|
|
48
|
+
context: emnapiContext,
|
|
49
|
+
overwriteImports(importObject) {
|
|
50
|
+
importObject.env = {
|
|
51
|
+
...importObject.env,
|
|
52
|
+
...importObject.napi,
|
|
53
|
+
...importObject.emnapi,
|
|
54
|
+
memory: wasmMemory
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
globalThis.onmessage = function (e) {
|
|
62
|
+
handler.handle(e);
|
|
63
|
+
};
|