@bytecodealliance/preview2-shim 0.0.20 → 0.14.0
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 +4 -14
- package/lib/browser/cli.js +77 -12
- package/lib/browser/clocks.js +15 -27
- package/lib/browser/filesystem.js +147 -205
- package/lib/browser/index.js +1 -3
- package/lib/{common → browser}/io.js +8 -4
- package/lib/common/assert.js +7 -0
- package/lib/io/calls.js +64 -0
- package/lib/io/worker-http.js +95 -0
- package/lib/io/worker-io.js +322 -0
- package/lib/io/worker-thread.js +569 -0
- package/lib/nodejs/cli.js +45 -58
- package/lib/nodejs/clocks.js +13 -27
- package/lib/nodejs/filesystem.js +540 -427
- package/lib/nodejs/http.js +441 -175
- package/lib/nodejs/index.js +4 -1
- package/lib/nodejs/io.js +1 -0
- package/lib/nodejs/sockets/socket-common.js +116 -0
- package/lib/nodejs/sockets/socketopts-bindings.js +94 -0
- package/lib/nodejs/sockets/tcp-socket-impl.js +794 -0
- package/lib/nodejs/sockets/udp-socket-impl.js +628 -0
- package/lib/nodejs/sockets/wasi-sockets.js +320 -0
- package/lib/nodejs/sockets.js +11 -200
- package/lib/synckit/index.js +4 -2
- package/package.json +1 -5
- package/types/interfaces/wasi-cli-terminal-input.d.ts +4 -0
- package/types/interfaces/wasi-cli-terminal-output.d.ts +4 -0
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +19 -6
- package/types/interfaces/wasi-filesystem-types.d.ts +1 -178
- package/types/interfaces/wasi-http-outgoing-handler.d.ts +2 -2
- package/types/interfaces/wasi-http-types.d.ts +412 -82
- package/types/interfaces/wasi-io-error.d.ts +16 -0
- package/types/interfaces/wasi-io-poll.d.ts +19 -8
- package/types/interfaces/wasi-io-streams.d.ts +26 -46
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +9 -21
- package/types/interfaces/wasi-sockets-network.d.ts +4 -0
- package/types/interfaces/wasi-sockets-tcp.d.ts +75 -18
- package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +1 -1
- package/types/interfaces/wasi-sockets-udp.d.ts +282 -193
- package/types/wasi-cli-command.d.ts +28 -28
- package/types/wasi-http-proxy.d.ts +12 -12
- package/lib/common/make-request.js +0 -30
- package/types/interfaces/wasi-clocks-timezone.d.ts +0 -56
package/README.md
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Preview2 Shim
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
WASI Preview2 implementations for Node.js & browsers.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Browser support is considered experimental, and not currently suitable for production applications.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
| Interface | Node.js | Browser |
|
|
10
|
-
| --------------- | ----------------------------:|-----------------------------:|
|
|
11
|
-
| Clocks | Pending timezone, poll | Pending timezone, poll |
|
|
12
|
-
| Filesystem | Basic read support | _N/A_ |
|
|
13
|
-
| HTTP | Experimental support | :x: |
|
|
14
|
-
| IO | Experimental support | Experimental support |
|
|
15
|
-
| Random | :heavy_check_mark: | :heavy_check_mark: |
|
|
16
|
-
| Sockets | :x: | _N/A_ |
|
|
17
|
-
| CLI | :heavy_check_mark: | :heavy_check_mark: |
|
|
7
|
+
Node.js support is currently being stabilized, which can be tracked in https://github.com/bytecodealliance/jco/milestone/1.
|
|
18
8
|
|
|
19
9
|
# License
|
|
20
10
|
|
package/lib/browser/cli.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { _setCwd as fsSetCwd } from './filesystem.js';
|
|
2
|
+
import { streams } from './io.js';
|
|
3
|
+
const { InputStream, OutputStream } = streams;
|
|
4
|
+
|
|
5
|
+
const symbolDispose = Symbol.dispose ?? Symbol.for('dispose');
|
|
2
6
|
|
|
3
7
|
let _env = [], _args = [], _cwd = null;
|
|
4
8
|
export function _setEnv (envObj) {
|
|
@@ -38,50 +42,111 @@ export const exit = {
|
|
|
38
42
|
}
|
|
39
43
|
};
|
|
40
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @param {import('../common/io.js').InputStreamHandler} handler
|
|
47
|
+
*/
|
|
48
|
+
export function _setStdin (handler) {
|
|
49
|
+
stdinStream.handler = handler;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @param {import('../common/io.js').OutputStreamHandler} handler
|
|
53
|
+
*/
|
|
54
|
+
export function _setStderr (handler) {
|
|
55
|
+
stderrStream.handler = handler;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @param {import('../common/io.js').OutputStreamHandler} handler
|
|
59
|
+
*/
|
|
60
|
+
export function _setStdout (handler) {
|
|
61
|
+
stdoutStream.handler = handler;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const stdinStream = new InputStream({
|
|
65
|
+
blockingRead (_len) {
|
|
66
|
+
// TODO
|
|
67
|
+
},
|
|
68
|
+
subscribe () {
|
|
69
|
+
// TODO
|
|
70
|
+
},
|
|
71
|
+
[symbolDispose] () {
|
|
72
|
+
// TODO
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
let textDecoder = new TextDecoder();
|
|
76
|
+
const stdoutStream = new OutputStream({
|
|
77
|
+
write (contents) {
|
|
78
|
+
console.log(textDecoder.decode(contents));
|
|
79
|
+
},
|
|
80
|
+
blockingFlush () {
|
|
81
|
+
},
|
|
82
|
+
[symbolDispose] () {
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const stderrStream = new OutputStream({
|
|
86
|
+
write (contents) {
|
|
87
|
+
console.error(textDecoder.decode(contents));
|
|
88
|
+
},
|
|
89
|
+
blockingFlush () {
|
|
90
|
+
|
|
91
|
+
},
|
|
92
|
+
[symbolDispose] () {
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
41
97
|
export const stdin = {
|
|
98
|
+
InputStream,
|
|
42
99
|
getStdin () {
|
|
43
|
-
return
|
|
100
|
+
return stdinStream;
|
|
44
101
|
}
|
|
45
102
|
};
|
|
46
103
|
|
|
47
104
|
export const stdout = {
|
|
105
|
+
OutputStream,
|
|
48
106
|
getStdout () {
|
|
49
|
-
return
|
|
107
|
+
return stdoutStream;
|
|
50
108
|
}
|
|
51
109
|
};
|
|
52
110
|
|
|
53
111
|
export const stderr = {
|
|
112
|
+
OutputStream,
|
|
54
113
|
getStderr () {
|
|
55
|
-
return
|
|
114
|
+
return stderrStream;
|
|
56
115
|
}
|
|
57
116
|
};
|
|
58
117
|
|
|
59
|
-
|
|
60
|
-
|
|
118
|
+
class TerminalInput {}
|
|
119
|
+
class TerminalOutput {}
|
|
61
120
|
|
|
62
|
-
|
|
121
|
+
const terminalStdoutInstance = new TerminalOutput();
|
|
122
|
+
const terminalStderrInstance = new TerminalOutput();
|
|
123
|
+
const terminalStdinInstance = new TerminalInput();
|
|
124
|
+
|
|
125
|
+
export const terminalInput = {
|
|
126
|
+
TerminalInput
|
|
63
127
|
};
|
|
64
128
|
|
|
65
129
|
export const terminalOutput = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
130
|
+
TerminalOutput
|
|
69
131
|
};
|
|
70
132
|
|
|
71
133
|
export const terminalStderr = {
|
|
134
|
+
TerminalOutput,
|
|
72
135
|
getTerminalStderr () {
|
|
73
|
-
return
|
|
136
|
+
return terminalStderrInstance;
|
|
74
137
|
}
|
|
75
138
|
};
|
|
76
139
|
|
|
77
140
|
export const terminalStdin = {
|
|
141
|
+
TerminalInput,
|
|
78
142
|
getTerminalStdin () {
|
|
79
|
-
return
|
|
143
|
+
return terminalStdinInstance;
|
|
80
144
|
}
|
|
81
145
|
};
|
|
82
146
|
|
|
83
147
|
export const terminalStdout = {
|
|
148
|
+
TerminalOutput,
|
|
84
149
|
getTerminalStdout () {
|
|
85
|
-
return
|
|
150
|
+
return terminalStdoutInstance;
|
|
86
151
|
}
|
|
87
152
|
};
|
package/lib/browser/clocks.js
CHANGED
|
@@ -1,34 +1,23 @@
|
|
|
1
|
-
function _hrtimeBigint () {
|
|
2
|
-
// performance.now() is in milliseconds, but we want nanoseconds
|
|
3
|
-
return BigInt(Math.floor(performance.now() * 1e6));
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
let _hrStart = _hrtimeBigint();
|
|
7
|
-
|
|
8
1
|
export const monotonicClock = {
|
|
9
2
|
resolution() {
|
|
10
|
-
|
|
3
|
+
// usually we dont get sub-millisecond accuracy in the browser
|
|
4
|
+
// Note: is there a better way to determine this?
|
|
5
|
+
return 1e6;
|
|
11
6
|
},
|
|
12
7
|
now () {
|
|
13
|
-
|
|
8
|
+
// performance.now() is in milliseconds, but we want nanoseconds
|
|
9
|
+
return BigInt(Math.floor(performance.now() * 1e6));
|
|
14
10
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
display (timezone, when) {
|
|
22
|
-
console.log(`[timezone] DISPLAY ${timezone} ${when}`);
|
|
11
|
+
subscribeInstant (instant) {
|
|
12
|
+
instant = BigInt(instant);
|
|
13
|
+
const now = this.now();
|
|
14
|
+
if (instant <= now)
|
|
15
|
+
return this.subscribeDuration(0);
|
|
16
|
+
return this.subscribeDuration(instant - now);
|
|
23
17
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.log(`[
|
|
27
|
-
return 0;
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
dropTimezone (timezone) {
|
|
31
|
-
console.log(`[timezone] DROP ${timezone}`);
|
|
18
|
+
subscribeDuration (_duration) {
|
|
19
|
+
_duration = BigInt(_duration);
|
|
20
|
+
console.log(`[monotonic-clock] subscribe`);
|
|
32
21
|
}
|
|
33
22
|
};
|
|
34
23
|
|
|
@@ -39,8 +28,7 @@ export const wallClock = {
|
|
|
39
28
|
const nanoseconds = (now % 1e3) * 1e6;
|
|
40
29
|
return { seconds, nanoseconds };
|
|
41
30
|
},
|
|
42
|
-
|
|
43
31
|
resolution() {
|
|
44
|
-
|
|
32
|
+
return { seconds: 0n, nanoseconds: 1e6 };
|
|
45
33
|
}
|
|
46
34
|
};
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { streams } from './io.js';
|
|
2
2
|
import { environment } from './cli.js';
|
|
3
3
|
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
let _preopens = [[3, '/']], _rootPreopen = _preopens[0];
|
|
7
|
-
|
|
8
|
-
export function _setPreopens (preopens) {
|
|
9
|
-
_preopens = preopens;
|
|
10
|
-
descriptorCnt = 3 + _preopens.length;
|
|
11
|
-
_rootPreopen = _preopens.find(preopen => preopen[1] === '/');
|
|
12
|
-
}
|
|
4
|
+
const { InputStream, OutputStream } = streams;
|
|
13
5
|
|
|
14
6
|
let _cwd = null;
|
|
15
7
|
|
|
@@ -19,11 +11,7 @@ export function _setCwd (cwd) {
|
|
|
19
11
|
|
|
20
12
|
export function _setFileData (fileData) {
|
|
21
13
|
_fileData = fileData;
|
|
22
|
-
|
|
23
|
-
const fd = descriptorCnt++;
|
|
24
|
-
descriptorTable[fd] = { entry: fileData[key] };
|
|
25
|
-
return [fd, key];
|
|
26
|
-
}));
|
|
14
|
+
_rootPreopen[0] = new Descriptor(fileData);
|
|
27
15
|
const cwd = environment.initialCwd();
|
|
28
16
|
_setCwd(cwd || '/');
|
|
29
17
|
}
|
|
@@ -32,34 +20,20 @@ export function _getFileData () {
|
|
|
32
20
|
return JSON.stringify(_fileData);
|
|
33
21
|
}
|
|
34
22
|
|
|
35
|
-
let _fileData = {};
|
|
36
|
-
|
|
37
|
-
let descriptorCnt = 4;
|
|
38
|
-
const descriptorTable = {
|
|
39
|
-
0: { stream: 0 },
|
|
40
|
-
1: { stream: 1 },
|
|
41
|
-
2: { stream: 2 },
|
|
42
|
-
3: { entry: { dir: {} } },
|
|
43
|
-
};
|
|
23
|
+
let _fileData = { dir: {} };
|
|
44
24
|
|
|
45
25
|
const timeZero = {
|
|
46
26
|
seconds: BigInt(0),
|
|
47
27
|
nanoseconds: 0
|
|
48
28
|
};
|
|
49
29
|
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
if (!descriptor) throw 'bad-descriptor';
|
|
53
|
-
return descriptor;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function getChildEntry (fd, subpath, openFlags) {
|
|
57
|
-
if (subpath === '.' && _rootPreopen && _rootPreopen[0] === fd) {
|
|
30
|
+
function getChildEntry (parentEntry, subpath, openFlags) {
|
|
31
|
+
if (subpath === '.' && _rootPreopen && descriptorGetEntry(_rootPreopen[0]) === parentEntry) {
|
|
58
32
|
subpath = _cwd;
|
|
59
|
-
if (subpath.startsWith('/'))
|
|
33
|
+
if (subpath.startsWith('/') && subpath !== '/')
|
|
60
34
|
subpath = subpath.slice(1);
|
|
61
35
|
}
|
|
62
|
-
let entry =
|
|
36
|
+
let entry = parentEntry;
|
|
63
37
|
let segmentIdx;
|
|
64
38
|
do {
|
|
65
39
|
if (!entry || !entry.dir) throw 'not-directory';
|
|
@@ -76,13 +50,6 @@ function getChildEntry (fd, subpath, openFlags) {
|
|
|
76
50
|
return entry;
|
|
77
51
|
}
|
|
78
52
|
|
|
79
|
-
function createChildDescriptor (fd, subpath, openFlags) {
|
|
80
|
-
const entry = getChildEntry(fd, subpath, openFlags);
|
|
81
|
-
const childFd = descriptorCnt++;
|
|
82
|
-
descriptorTable[childFd] = { entry };
|
|
83
|
-
return childFd;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
53
|
function getSource (fileEntry) {
|
|
87
54
|
if (typeof fileEntry.source === 'string') {
|
|
88
55
|
fileEntry.source = new TextEncoder().encode(fileEntry.source);
|
|
@@ -90,12 +57,12 @@ function getSource (fileEntry) {
|
|
|
90
57
|
return fileEntry.source;
|
|
91
58
|
}
|
|
92
59
|
|
|
93
|
-
class
|
|
60
|
+
class DirectoryEntryStream {
|
|
94
61
|
constructor (entries) {
|
|
95
62
|
this.idx = 0;
|
|
96
63
|
this.entries = entries;
|
|
97
64
|
}
|
|
98
|
-
|
|
65
|
+
readDirectoryEntry () {
|
|
99
66
|
if (this.idx === this.entries.length)
|
|
100
67
|
return null;
|
|
101
68
|
const [name, entry] = this.entries[this.idx];
|
|
@@ -107,117 +74,116 @@ class DirStream {
|
|
|
107
74
|
}
|
|
108
75
|
}
|
|
109
76
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
77
|
+
class Descriptor {
|
|
78
|
+
#stream;
|
|
79
|
+
#entry;
|
|
80
|
+
#mtime = 0;
|
|
81
|
+
|
|
82
|
+
_getEntry (descriptor) {
|
|
83
|
+
return descriptor.#entry;
|
|
113
84
|
}
|
|
114
|
-
}
|
|
115
85
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
86
|
+
constructor (entry, isStream) {
|
|
87
|
+
if (isStream)
|
|
88
|
+
this.#stream = entry;
|
|
89
|
+
else
|
|
90
|
+
this.#entry = entry;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
readViaStream(_offset) {
|
|
94
|
+
const source = getSource(this.#entry);
|
|
95
|
+
let offset = Number(_offset);
|
|
96
|
+
return new InputStream({
|
|
97
|
+
blockingRead (len) {
|
|
98
|
+
if (offset === source.byteLength)
|
|
99
|
+
throw { tag: 'closed' };
|
|
100
|
+
const bytes = source.slice(offset, offset + Number(len));
|
|
101
|
+
offset += bytes.byteLength;
|
|
102
|
+
return bytes;
|
|
127
103
|
}
|
|
128
104
|
});
|
|
129
|
-
}
|
|
105
|
+
}
|
|
130
106
|
|
|
131
|
-
writeViaStream(
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
entry: descriptor.entry,
|
|
107
|
+
writeViaStream(_offset) {
|
|
108
|
+
const entry = this.#entry;
|
|
109
|
+
let offset = Number(_offset);
|
|
110
|
+
return new OutputStream({
|
|
136
111
|
write (buf) {
|
|
137
|
-
const newSource = new Uint8Array(buf.byteLength +
|
|
138
|
-
newSource.set(
|
|
139
|
-
newSource.set(buf,
|
|
140
|
-
|
|
141
|
-
|
|
112
|
+
const newSource = new Uint8Array(buf.byteLength + entry.source.byteLength);
|
|
113
|
+
newSource.set(entry.source, 0);
|
|
114
|
+
newSource.set(buf, offset);
|
|
115
|
+
offset += buf.byteLength;
|
|
116
|
+
entry.source = newSource;
|
|
142
117
|
return buf.byteLength;
|
|
143
118
|
}
|
|
144
119
|
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
appendViaStream(fd) {
|
|
148
|
-
console.log(`[filesystem] APPEND STREAM ${fd}`);
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
advise(fd, offset, length, advice) {
|
|
152
|
-
console.log(`[filesystem] ADVISE`, fd, offset, length, advice);
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
syncData(fd) {
|
|
156
|
-
console.log(`[filesystem] SYNC DATA ${fd}`);
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
getFlags(fd) {
|
|
160
|
-
console.log(`[filesystem] FLAGS FOR ${fd}`);
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
getType(fd) {
|
|
164
|
-
if (fd < 3) return 'fifo';
|
|
165
|
-
const descriptor = getDescriptor(fd);
|
|
166
|
-
if (descriptor.stream) return 'fifo';
|
|
167
|
-
if (descriptor.entry.dir) return 'directory';
|
|
168
|
-
if (descriptor.entry.source) return 'regular-file';
|
|
169
|
-
return 'unknown';
|
|
170
|
-
},
|
|
120
|
+
}
|
|
171
121
|
|
|
172
|
-
|
|
173
|
-
console.log(`[filesystem]
|
|
174
|
-
}
|
|
122
|
+
appendViaStream() {
|
|
123
|
+
console.log(`[filesystem] APPEND STREAM`);
|
|
124
|
+
}
|
|
175
125
|
|
|
176
|
-
|
|
177
|
-
console.log(`[filesystem]
|
|
178
|
-
}
|
|
126
|
+
advise(descriptor, offset, length, advice) {
|
|
127
|
+
console.log(`[filesystem] ADVISE`, descriptor, offset, length, advice);
|
|
128
|
+
}
|
|
179
129
|
|
|
180
|
-
|
|
181
|
-
console.log(`[filesystem]
|
|
182
|
-
}
|
|
130
|
+
syncData() {
|
|
131
|
+
console.log(`[filesystem] SYNC DATA`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getFlags() {
|
|
135
|
+
console.log(`[filesystem] FLAGS FOR`);
|
|
136
|
+
}
|
|
183
137
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
138
|
+
getType() {
|
|
139
|
+
if (this.#stream) return 'fifo';
|
|
140
|
+
if (this.#entry.dir) return 'directory';
|
|
141
|
+
if (this.#entry.source) return 'regular-file';
|
|
142
|
+
return 'unknown';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setSize(size) {
|
|
146
|
+
console.log(`[filesystem] SET SIZE`, size);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
setTimes(dataAccessTimestamp, dataModificationTimestamp) {
|
|
150
|
+
console.log(`[filesystem] SET TIMES`, dataAccessTimestamp, dataModificationTimestamp);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
read(length, offset) {
|
|
154
|
+
const source = getSource(this.#entry);
|
|
187
155
|
return [source.slice(offset, offset + length), offset + length >= source.byteLength];
|
|
188
|
-
}
|
|
156
|
+
}
|
|
189
157
|
|
|
190
|
-
write(
|
|
191
|
-
const descriptor = getDescriptor(fd);
|
|
158
|
+
write(buffer, offset) {
|
|
192
159
|
if (offset !== 0) throw 'invalid-seek';
|
|
193
|
-
|
|
160
|
+
this.#entry.source = buffer;
|
|
194
161
|
return buffer.byteLength;
|
|
195
|
-
}
|
|
162
|
+
}
|
|
196
163
|
|
|
197
|
-
readDirectory(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return
|
|
201
|
-
}
|
|
164
|
+
readDirectory() {
|
|
165
|
+
if (!this.#entry?.dir)
|
|
166
|
+
throw 'bad-descriptor';
|
|
167
|
+
return new DirectoryEntryStream(Object.entries(this.#entry.dir).sort(([a], [b]) => a > b ? 1 : -1));
|
|
168
|
+
}
|
|
202
169
|
|
|
203
|
-
sync(
|
|
204
|
-
console.log(`[filesystem] SYNC
|
|
205
|
-
}
|
|
170
|
+
sync() {
|
|
171
|
+
console.log(`[filesystem] SYNC`);
|
|
172
|
+
}
|
|
206
173
|
|
|
207
|
-
createDirectoryAt(
|
|
208
|
-
const entry = getChildEntry(
|
|
174
|
+
createDirectoryAt(path) {
|
|
175
|
+
const entry = getChildEntry(this.#entry, path, { create: true, directory: true });
|
|
209
176
|
if (entry.source) throw 'exist';
|
|
210
|
-
}
|
|
177
|
+
}
|
|
211
178
|
|
|
212
|
-
stat(
|
|
213
|
-
const descriptor = getDescriptor(fd);
|
|
179
|
+
stat() {
|
|
214
180
|
let type = 'unknown', size = BigInt(0);
|
|
215
|
-
if (
|
|
181
|
+
if (this.#entry.source) {
|
|
216
182
|
type = 'directory';
|
|
217
183
|
}
|
|
218
|
-
else if (
|
|
184
|
+
else if (this.#entry.dir) {
|
|
219
185
|
type = 'regular-file';
|
|
220
|
-
const source = getSource(
|
|
186
|
+
const source = getSource(this.#entry);
|
|
221
187
|
size = BigInt(source.byteLength);
|
|
222
188
|
}
|
|
223
189
|
return {
|
|
@@ -228,10 +194,10 @@ export const types = {
|
|
|
228
194
|
dataModificationTimestamp: timeZero,
|
|
229
195
|
statusChangeTimestamp: timeZero,
|
|
230
196
|
}
|
|
231
|
-
}
|
|
197
|
+
}
|
|
232
198
|
|
|
233
|
-
statAt(
|
|
234
|
-
const entry = getChildEntry(
|
|
199
|
+
statAt(_pathFlags, path) {
|
|
200
|
+
const entry = getChildEntry(this.#entry, path);
|
|
235
201
|
let type = 'unknown', size = BigInt(0);
|
|
236
202
|
if (entry.source) {
|
|
237
203
|
type = 'regular-file';
|
|
@@ -249,95 +215,71 @@ export const types = {
|
|
|
249
215
|
dataModificationTimestamp: timeZero,
|
|
250
216
|
statusChangeTimestamp: timeZero,
|
|
251
217
|
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
setTimesAt(fd) {
|
|
255
|
-
console.log(`[filesystem] SET TIMES AT`, fd);
|
|
256
|
-
},
|
|
257
|
-
|
|
258
|
-
linkAt(fd) {
|
|
259
|
-
console.log(`[filesystem] LINK AT`, fd);
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
openAt(fd, _pathFlags, path, openFlags, _descriptorFlags, _modes) {
|
|
263
|
-
return createChildDescriptor(fd, path, openFlags);
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
readlinkAt(fd) {
|
|
267
|
-
console.log(`[filesystem] READLINK AT`, fd);
|
|
268
|
-
},
|
|
269
|
-
|
|
270
|
-
removeDirectoryAt(fd) {
|
|
271
|
-
console.log(`[filesystem] REMOVE DIR AT`, fd);
|
|
272
|
-
},
|
|
273
|
-
|
|
274
|
-
renameAt(fd) {
|
|
275
|
-
console.log(`[filesystem] RENAME AT`, fd);
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
symlinkAt(fd) {
|
|
279
|
-
console.log(`[filesystem] SYMLINK AT`, fd);
|
|
280
|
-
},
|
|
281
|
-
|
|
282
|
-
unlinkFileAt(fd) {
|
|
283
|
-
console.log(`[filesystem] UNLINK FILE AT`, fd);
|
|
284
|
-
},
|
|
285
|
-
|
|
286
|
-
changeFilePermissionsAt(fd) {
|
|
287
|
-
console.log(`[filesystem] CHANGE FILE PERMISSIONS AT`, fd);
|
|
288
|
-
},
|
|
218
|
+
}
|
|
289
219
|
|
|
290
|
-
|
|
291
|
-
console.log(`[filesystem]
|
|
292
|
-
}
|
|
220
|
+
setTimesAt() {
|
|
221
|
+
console.log(`[filesystem] SET TIMES AT`);
|
|
222
|
+
}
|
|
293
223
|
|
|
294
|
-
|
|
295
|
-
console.log(`[filesystem]
|
|
296
|
-
}
|
|
224
|
+
linkAt() {
|
|
225
|
+
console.log(`[filesystem] LINK AT`);
|
|
226
|
+
}
|
|
297
227
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
228
|
+
openAt(_pathFlags, path, openFlags, _descriptorFlags, _modes) {
|
|
229
|
+
const childEntry = getChildEntry(this.#entry, path, openFlags);
|
|
230
|
+
return new Descriptor(childEntry);
|
|
231
|
+
}
|
|
301
232
|
|
|
302
|
-
|
|
303
|
-
console.log(`[filesystem]
|
|
304
|
-
}
|
|
233
|
+
readlinkAt() {
|
|
234
|
+
console.log(`[filesystem] READLINK AT`);
|
|
235
|
+
}
|
|
305
236
|
|
|
306
|
-
|
|
307
|
-
console.log(`[filesystem]
|
|
308
|
-
}
|
|
237
|
+
removeDirectoryAt() {
|
|
238
|
+
console.log(`[filesystem] REMOVE DIR AT`);
|
|
239
|
+
}
|
|
309
240
|
|
|
310
|
-
|
|
311
|
-
console.log(`[filesystem]
|
|
312
|
-
}
|
|
241
|
+
renameAt() {
|
|
242
|
+
console.log(`[filesystem] RENAME AT`);
|
|
243
|
+
}
|
|
313
244
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
delete descriptorTable[fd];
|
|
318
|
-
},
|
|
245
|
+
symlinkAt() {
|
|
246
|
+
console.log(`[filesystem] SYMLINK AT`);
|
|
247
|
+
}
|
|
319
248
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
249
|
+
unlinkFileAt() {
|
|
250
|
+
console.log(`[filesystem] UNLINK FILE AT`);
|
|
251
|
+
}
|
|
323
252
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
253
|
+
isSameObject(other) {
|
|
254
|
+
return other === this;
|
|
255
|
+
}
|
|
327
256
|
|
|
328
|
-
metadataHash(
|
|
329
|
-
const descriptor = getDescriptor(fd);
|
|
257
|
+
metadataHash() {
|
|
330
258
|
let upper = BigInt(0);
|
|
331
|
-
upper += BigInt(
|
|
259
|
+
upper += BigInt(this.#mtime);
|
|
332
260
|
return { upper, lower: BigInt(0) };
|
|
333
|
-
}
|
|
261
|
+
}
|
|
334
262
|
|
|
335
|
-
metadataHashAt(
|
|
336
|
-
const descriptor = getDescriptor(fd);
|
|
263
|
+
metadataHashAt(_pathFlags, _path) {
|
|
337
264
|
let upper = BigInt(0);
|
|
338
|
-
upper += BigInt(
|
|
265
|
+
upper += BigInt(this.#mtime);
|
|
339
266
|
return { upper, lower: BigInt(0) };
|
|
340
267
|
}
|
|
268
|
+
}
|
|
269
|
+
const descriptorGetEntry = Descriptor.prototype._getEntry;
|
|
270
|
+
delete Descriptor.prototype._getEntry;
|
|
271
|
+
|
|
272
|
+
let _preopens = [[new Descriptor(_fileData), '/']], _rootPreopen = _preopens[0];
|
|
273
|
+
|
|
274
|
+
export const preopens = {
|
|
275
|
+
getDirectories () {
|
|
276
|
+
return _preopens;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export const types = {
|
|
281
|
+
Descriptor,
|
|
282
|
+
DirectoryEntryStream
|
|
341
283
|
};
|
|
342
284
|
|
|
343
|
-
export { types as filesystemTypes }
|
|
285
|
+
export { types as filesystemTypes }
|
package/lib/browser/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as clocks from "./clocks.js";
|
|
2
2
|
import * as filesystem from "./filesystem.js";
|
|
3
3
|
import * as http from "./http.js";
|
|
4
|
-
import * as io from "
|
|
4
|
+
import * as io from "./io.js";
|
|
5
5
|
import * as random from "./random.js";
|
|
6
6
|
import * as sockets from "./sockets.js";
|
|
7
7
|
import * as cli from "./cli.js";
|
|
@@ -15,5 +15,3 @@ export {
|
|
|
15
15
|
sockets,
|
|
16
16
|
cli,
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
export { WasiHttp } from "../http/wasi-http.js";
|