@bytecodealliance/preview2-shim 0.0.17 → 0.0.18
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/lib/browser/index.js +1 -3
- package/lib/common/io.js +150 -104
- package/lib/nodejs/cli.js +55 -6
- package/lib/nodejs/filesystem.js +247 -251
- package/lib/nodejs/http.js +2 -2
- package/lib/nodejs/index.js +1 -3
- package/package.json +5 -1
- package/types/interfaces/wasi-cli-terminal-input.d.ts +0 -11
- package/types/interfaces/wasi-cli-terminal-output.d.ts +0 -11
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +1 -1
- package/types/interfaces/wasi-clocks-timezone.d.ts +2 -17
- package/types/interfaces/wasi-filesystem-types.d.ts +75 -67
- package/types/interfaces/wasi-io-poll.d.ts +30 -0
- package/types/interfaces/wasi-io-streams.d.ts +123 -143
- package/types/interfaces/wasi-random-random.d.ts +13 -11
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +10 -14
- package/types/interfaces/wasi-sockets-network.d.ts +15 -57
- package/types/interfaces/wasi-sockets-tcp-create-socket.d.ts +2 -3
- package/types/interfaces/wasi-sockets-tcp.d.ts +91 -93
- package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +2 -3
- package/types/interfaces/wasi-sockets-udp.d.ts +49 -56
- package/types/wasi-cli-command.d.ts +1 -1
- package/lib/browser/logging.js +0 -14
- package/lib/nodejs/io.js +0 -16
- package/lib/nodejs/logging.js +0 -14
- package/types/interfaces/wasi-poll-poll.d.ts +0 -39
package/lib/nodejs/filesystem.js
CHANGED
|
@@ -1,63 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { streams } from '../common/io.js';
|
|
2
2
|
import { environment } from './cli.js';
|
|
3
|
-
import { constants, readSync, openSync, opendirSync, closeSync, fstatSync, lstatSync, statSync, writeSync } from 'node:fs';
|
|
3
|
+
import { constants, readSync, openSync, opendirSync, closeSync, fstatSync, lstatSync, statSync, writeSync, mkdirSync } from 'node:fs';
|
|
4
4
|
import { platform } from 'node:process';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
class ReadableFileStream {
|
|
9
|
-
constructor (hostFd, position) {
|
|
10
|
-
this.hostFd = hostFd;
|
|
11
|
-
this.position = Number(position);
|
|
12
|
-
}
|
|
13
|
-
read (len) {
|
|
14
|
-
const buf = new Uint8Array(Number(len));
|
|
15
|
-
const bytesRead = readSync(this.hostFd, buf, 0, buf.byteLength, this.position);
|
|
16
|
-
this.position += bytesRead;
|
|
17
|
-
if (bytesRead < buf.byteLength)
|
|
18
|
-
return [new Uint8Array(buf.buffer, 0, bytesRead), bytesRead === 0 ? 'ended' : 'open'];
|
|
19
|
-
return [buf, 'open'];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
6
|
+
const { InputStream, OutputStream, Error: StreamError } = streams;
|
|
22
7
|
|
|
23
|
-
|
|
24
|
-
constructor (hostFd, position) {
|
|
25
|
-
this.hostFd = hostFd;
|
|
26
|
-
this.position = Number(position);
|
|
27
|
-
}
|
|
28
|
-
write (contents) {
|
|
29
|
-
let totalWritten = 0;
|
|
30
|
-
while (totalWritten !== contents.byteLength) {
|
|
31
|
-
const bytesWritten = writeSync(this.hostFd, contents, null, null, this.position);
|
|
32
|
-
totalWritten += bytesWritten;
|
|
33
|
-
contents = new Uint8Array(contents.buffer, bytesWritten);
|
|
34
|
-
}
|
|
35
|
-
this.position += contents.byteLength;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
class DirStream {
|
|
40
|
-
constructor (dir) {
|
|
41
|
-
this.dir = dir;
|
|
42
|
-
}
|
|
43
|
-
read () {
|
|
44
|
-
let entry;
|
|
45
|
-
try {
|
|
46
|
-
entry = this.dir.readSync();
|
|
47
|
-
} catch (e) {
|
|
48
|
-
throw convertFsError(e);
|
|
49
|
-
}
|
|
50
|
-
if (entry === null) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
const name = entry.name;
|
|
54
|
-
const type = lookupType(entry);
|
|
55
|
-
return { name, type };
|
|
56
|
-
}
|
|
57
|
-
drop () {
|
|
58
|
-
this.dir.closeSync();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
8
|
+
const isWindows = platform === 'win32';
|
|
61
9
|
|
|
62
10
|
const nsMagnitude = 1_000_000_000_000n;
|
|
63
11
|
function nsToDateTime (ns) {
|
|
@@ -86,24 +34,17 @@ function lookupType (obj) {
|
|
|
86
34
|
|
|
87
35
|
/**
|
|
88
36
|
* @typedef {
|
|
89
|
-
* { stream: number } |
|
|
90
37
|
* { hostPreopen: string } |
|
|
91
38
|
* { fullPath: string, fd: number }
|
|
92
|
-
* }
|
|
39
|
+
* } DescriptorProps
|
|
93
40
|
*/
|
|
94
41
|
export class FileSystem {
|
|
95
|
-
getDescriptor (fd) {
|
|
96
|
-
const descriptor = this.descriptors[fd];
|
|
97
|
-
if (!descriptor) throw 'bad-descriptor';
|
|
98
|
-
return descriptor;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
42
|
// Note: This should implement per-segment semantics of openAt, but we cannot currently
|
|
102
43
|
// due to the lack of support for openat() in Node.js.
|
|
103
44
|
// Tracking issue: https://github.com/libuv/libuv/issues/4167
|
|
104
45
|
|
|
105
46
|
// TODO: support followSymlinks
|
|
106
|
-
getFullPath (
|
|
47
|
+
getFullPath (descriptor, subpath, _followSymlinks) {
|
|
107
48
|
if (subpath.indexOf('\\') !== -1)
|
|
108
49
|
subpath = subpath.replace(/\\/g, '/');
|
|
109
50
|
if (subpath[0] === '/') {
|
|
@@ -115,14 +56,13 @@ export class FileSystem {
|
|
|
115
56
|
}
|
|
116
57
|
if (!bestPreopenMatch)
|
|
117
58
|
throw 'no-entry';
|
|
118
|
-
|
|
59
|
+
descriptor = bestPreopenMatch[0];
|
|
119
60
|
subpath = subpath.slice(bestPreopenMatch[1]);
|
|
120
61
|
if (subpath[0] === '/')
|
|
121
62
|
subpath = subpath.slice(1);
|
|
122
63
|
}
|
|
123
64
|
if (subpath.startsWith('.'))
|
|
124
65
|
subpath = subpath.slice(subpath[1] === '/' ? 2 : 1);
|
|
125
|
-
const descriptor = this.getDescriptor(fd);
|
|
126
66
|
if (descriptor.hostPreopen)
|
|
127
67
|
return descriptor.hostPreopen + (descriptor.hostPreopen.endsWith('/') ? '' : '/') + subpath;
|
|
128
68
|
return descriptor.fullPath + '/' + subpath;
|
|
@@ -130,131 +70,186 @@ export class FileSystem {
|
|
|
130
70
|
|
|
131
71
|
/**
|
|
132
72
|
*
|
|
133
|
-
* @param {import('./io.js').Io} io
|
|
134
73
|
* @param {[string, string][]} preopens
|
|
74
|
+
* @param {import('./cli.js').environment} environment
|
|
135
75
|
* @returns
|
|
136
76
|
*/
|
|
137
|
-
constructor (
|
|
77
|
+
constructor (preopens, environment) {
|
|
78
|
+
const fs = this;
|
|
138
79
|
this.cwd = environment.initialCwd();
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
80
|
+
|
|
81
|
+
class FileInputStream extends InputStream {
|
|
82
|
+
constructor (hostFd, position) {
|
|
83
|
+
super({
|
|
84
|
+
blockingRead (len) {
|
|
85
|
+
const buf = new Uint8Array(Number(len));
|
|
86
|
+
try {
|
|
87
|
+
var bytesRead = readSync(this.hostFd, buf, 0, buf.byteLength, this.position);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
throw { tag: 'last-operation-failed', val: new StreamError(e.message) };
|
|
90
|
+
}
|
|
91
|
+
this.position += bytesRead;
|
|
92
|
+
if (bytesRead < buf.byteLength) {
|
|
93
|
+
if (bytesRead === 0)
|
|
94
|
+
throw { tag: 'closed' };
|
|
95
|
+
return new Uint8Array(buf.buffer, 0, bytesRead);
|
|
96
|
+
}
|
|
97
|
+
return buf;
|
|
98
|
+
},
|
|
99
|
+
subscribe () {
|
|
100
|
+
// TODO
|
|
101
|
+
},
|
|
102
|
+
drop () {
|
|
103
|
+
// TODO
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
this.hostFd = hostFd;
|
|
107
|
+
this.position = Number(position);
|
|
108
|
+
}
|
|
154
109
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
110
|
+
|
|
111
|
+
class FileOutputStream extends OutputStream {
|
|
112
|
+
constructor (hostFd, position) {
|
|
113
|
+
super({
|
|
114
|
+
write (contents) {
|
|
115
|
+
let totalWritten = 0;
|
|
116
|
+
while (totalWritten !== contents.byteLength) {
|
|
117
|
+
const bytesWritten = writeSync(this.hostFd, contents, null, null, this.position);
|
|
118
|
+
totalWritten += bytesWritten;
|
|
119
|
+
contents = new Uint8Array(contents.buffer, bytesWritten);
|
|
120
|
+
}
|
|
121
|
+
this.position += contents.byteLength;
|
|
122
|
+
},
|
|
123
|
+
blockingFlush () {
|
|
124
|
+
|
|
125
|
+
},
|
|
126
|
+
drop () {
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.hostFd = hostFd;
|
|
131
|
+
this.position = Number(position);
|
|
159
132
|
}
|
|
160
|
-
}
|
|
161
|
-
this.types = {
|
|
162
|
-
readViaStream(fd, offset) {
|
|
163
|
-
const descriptor = fs.getDescriptor(fd);
|
|
164
|
-
if (descriptor.stream)
|
|
165
|
-
return descriptor.stream;
|
|
166
|
-
if (descriptor.hostPreopen)
|
|
167
|
-
throw 'is-directory';
|
|
168
|
-
return io.createStream(new ReadableFileStream(descriptor.fd, offset));
|
|
169
|
-
},
|
|
133
|
+
}
|
|
170
134
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
135
|
+
class DirectoryEntryStream {
|
|
136
|
+
constructor (dir) {
|
|
137
|
+
this.dir = dir;
|
|
138
|
+
}
|
|
139
|
+
readDirectoryEntry () {
|
|
140
|
+
let entry;
|
|
141
|
+
try {
|
|
142
|
+
entry = this.dir.readSync();
|
|
143
|
+
} catch (e) {
|
|
144
|
+
throw convertFsError(e);
|
|
145
|
+
}
|
|
146
|
+
if (entry === null) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const name = entry.name;
|
|
150
|
+
const type = lookupType(entry);
|
|
151
|
+
return { name, type };
|
|
152
|
+
}
|
|
153
|
+
drop () {
|
|
154
|
+
this.dir.closeSync();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @implements {DescriptorProps}
|
|
160
|
+
*/
|
|
161
|
+
class Descriptor {
|
|
162
|
+
constructor () {
|
|
163
|
+
this.id = fs.descriptorCnt++;
|
|
164
|
+
}
|
|
165
|
+
readViaStream(offset) {
|
|
166
|
+
if (this.hostPreopen)
|
|
167
|
+
throw { tag: 'last-operation-failed', val: new StreamError };
|
|
168
|
+
return new FileInputStream(this.fd, offset);
|
|
169
|
+
}
|
|
170
|
+
writeViaStream(offset) {
|
|
171
|
+
if (this.hostPreopen)
|
|
176
172
|
throw 'is-directory';
|
|
177
|
-
return
|
|
178
|
-
}
|
|
173
|
+
return new FileOutputStream(this.fd, offset);
|
|
174
|
+
}
|
|
179
175
|
|
|
180
|
-
appendViaStream(
|
|
181
|
-
console.log(`[filesystem] APPEND STREAM ${
|
|
182
|
-
}
|
|
176
|
+
appendViaStream() {
|
|
177
|
+
console.log(`[filesystem] APPEND STREAM ${this.id}`);
|
|
178
|
+
}
|
|
183
179
|
|
|
184
|
-
advise(
|
|
185
|
-
console.log(`[filesystem] ADVISE`,
|
|
186
|
-
}
|
|
180
|
+
advise(offset, length, advice) {
|
|
181
|
+
console.log(`[filesystem] ADVISE`, this.id, offset, length, advice);
|
|
182
|
+
}
|
|
187
183
|
|
|
188
|
-
syncData(
|
|
189
|
-
console.log(`[filesystem] SYNC DATA ${
|
|
190
|
-
}
|
|
184
|
+
syncData() {
|
|
185
|
+
console.log(`[filesystem] SYNC DATA ${this.id}`);
|
|
186
|
+
}
|
|
191
187
|
|
|
192
|
-
getFlags(
|
|
193
|
-
console.log(`[filesystem] FLAGS FOR ${
|
|
194
|
-
}
|
|
188
|
+
getFlags() {
|
|
189
|
+
console.log(`[filesystem] FLAGS FOR ${this.id}`);
|
|
190
|
+
}
|
|
195
191
|
|
|
196
|
-
getType(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (descriptor.hostPreopen) return 'directory';
|
|
200
|
-
const stats = fstatSync(descriptor.fd);
|
|
192
|
+
getType() {
|
|
193
|
+
if (this.hostPreopen) return 'directory';
|
|
194
|
+
const stats = fstatSync(this.fd);
|
|
201
195
|
return lookupType(stats);
|
|
202
|
-
}
|
|
196
|
+
}
|
|
203
197
|
|
|
204
|
-
setFlags(
|
|
205
|
-
console.log(`[filesystem] SET FLAGS ${
|
|
206
|
-
}
|
|
198
|
+
setFlags(flags) {
|
|
199
|
+
console.log(`[filesystem] SET FLAGS ${this.id} ${JSON.stringify(flags)}`);
|
|
200
|
+
}
|
|
207
201
|
|
|
208
|
-
setSize(
|
|
209
|
-
console.log(`[filesystem] SET SIZE`,
|
|
210
|
-
}
|
|
202
|
+
setSize(size) {
|
|
203
|
+
console.log(`[filesystem] SET SIZE`, this.id, size);
|
|
204
|
+
}
|
|
211
205
|
|
|
212
|
-
setTimes(
|
|
213
|
-
console.log(`[filesystem] SET TIMES`,
|
|
214
|
-
}
|
|
206
|
+
setTimes(dataAccessTimestamp, dataModificationTimestamp) {
|
|
207
|
+
console.log(`[filesystem] SET TIMES`, this.id, dataAccessTimestamp, dataModificationTimestamp);
|
|
208
|
+
}
|
|
215
209
|
|
|
216
|
-
read(
|
|
217
|
-
|
|
218
|
-
if (!descriptor.fullPath) throw 'bad-descriptor';
|
|
210
|
+
read(length, offset) {
|
|
211
|
+
if (!this.fullPath) throw 'bad-descriptor';
|
|
219
212
|
const buf = new Uint8Array(length);
|
|
220
|
-
const bytesRead = readSync(
|
|
213
|
+
const bytesRead = readSync(this.fd, buf, Number(offset), length, 0);
|
|
221
214
|
const out = new Uint8Array(buf.buffer, 0, bytesRead);
|
|
222
215
|
return [out, bytesRead === 0 ? 'ended' : 'open'];
|
|
223
|
-
}
|
|
216
|
+
}
|
|
224
217
|
|
|
225
|
-
write(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
},
|
|
218
|
+
write(buffer, offset) {
|
|
219
|
+
if (!this.fullPath) throw 'bad-descriptor';
|
|
220
|
+
return BigInt(writeSync(this.fd, buffer, Number(offset), buffer.byteLength - offset, 0));
|
|
221
|
+
}
|
|
230
222
|
|
|
231
|
-
readDirectory(
|
|
232
|
-
|
|
233
|
-
if (!descriptor.fullPath) throw 'bad-descriptor';
|
|
223
|
+
readDirectory() {
|
|
224
|
+
if (!this.fullPath) throw 'bad-descriptor';
|
|
234
225
|
try {
|
|
235
|
-
const dir = opendirSync(isWindows ?
|
|
236
|
-
return
|
|
226
|
+
const dir = opendirSync(isWindows ? this.fullPath.slice(1) : this.fullPath);
|
|
227
|
+
return new DirectoryEntryStream(dir);
|
|
237
228
|
}
|
|
238
229
|
catch (e) {
|
|
239
230
|
throw convertFsError(e);
|
|
240
231
|
}
|
|
241
|
-
}
|
|
232
|
+
}
|
|
242
233
|
|
|
243
|
-
sync(
|
|
244
|
-
console.log(`[filesystem] SYNC`,
|
|
245
|
-
}
|
|
234
|
+
sync() {
|
|
235
|
+
console.log(`[filesystem] SYNC`, this.id);
|
|
236
|
+
}
|
|
246
237
|
|
|
247
|
-
createDirectoryAt(
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
238
|
+
createDirectoryAt(path) {
|
|
239
|
+
const fullPath = fs.getFullPath(this, path);
|
|
240
|
+
try {
|
|
241
|
+
mkdirSync(fullPath);
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
throw convertFsError(e);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
stat() {
|
|
249
|
+
if (this.hostPreopen) throw 'invalid';
|
|
255
250
|
let stats;
|
|
256
251
|
try {
|
|
257
|
-
stats = fstatSync(
|
|
252
|
+
stats = fstatSync(this.fd, { bigint: true });
|
|
258
253
|
}
|
|
259
254
|
catch (e) {
|
|
260
255
|
convertFsError(e);
|
|
@@ -268,10 +263,10 @@ export class FileSystem {
|
|
|
268
263
|
dataModificationTimestamp: nsToDateTime(stats.mtimeNs),
|
|
269
264
|
statusChangeTimestamp: nsToDateTime(stats.ctimeNs),
|
|
270
265
|
};
|
|
271
|
-
}
|
|
266
|
+
}
|
|
272
267
|
|
|
273
|
-
statAt(
|
|
274
|
-
const fullPath = fs.getFullPath(
|
|
268
|
+
statAt(pathFlags, path) {
|
|
269
|
+
const fullPath = fs.getFullPath(this, path, false);
|
|
275
270
|
let stats;
|
|
276
271
|
try {
|
|
277
272
|
stats = (pathFlags.symlinkFollow ? statSync : lstatSync)(isWindows ? fullPath.slice(1) : fullPath, { bigint: true });
|
|
@@ -288,19 +283,18 @@ export class FileSystem {
|
|
|
288
283
|
dataModificationTimestamp: nsToDateTime(stats.mtimeNs),
|
|
289
284
|
statusChangeTimestamp: nsToDateTime(stats.ctimeNs),
|
|
290
285
|
};
|
|
291
|
-
}
|
|
286
|
+
}
|
|
292
287
|
|
|
293
|
-
setTimesAt(
|
|
294
|
-
console.log(`[filesystem] SET TIMES AT`,
|
|
295
|
-
}
|
|
288
|
+
setTimesAt() {
|
|
289
|
+
console.log(`[filesystem] SET TIMES AT`, this.id);
|
|
290
|
+
}
|
|
296
291
|
|
|
297
|
-
linkAt(
|
|
298
|
-
console.log(`[filesystem] LINK AT`,
|
|
299
|
-
}
|
|
292
|
+
linkAt() {
|
|
293
|
+
console.log(`[filesystem] LINK AT`, this.id);
|
|
294
|
+
}
|
|
300
295
|
|
|
301
|
-
openAt(
|
|
302
|
-
const fullPath = fs.getFullPath(
|
|
303
|
-
const childFd = fs.descriptorCnt++;
|
|
296
|
+
openAt(pathFlags, path, openFlags, descriptorFlags, modes) {
|
|
297
|
+
const fullPath = fs.getFullPath(this, path, pathFlags.symlinkFollow);
|
|
304
298
|
let fsOpenFlags = 0x0;
|
|
305
299
|
if (openFlags.create)
|
|
306
300
|
fsOpenFlags |= constants.O_CREAT;
|
|
@@ -331,94 +325,80 @@ export class FileSystem {
|
|
|
331
325
|
|
|
332
326
|
try {
|
|
333
327
|
const fd = openSync(isWindows ? fullPath.slice(1) : fullPath, fsOpenFlags, fsMode);
|
|
334
|
-
|
|
328
|
+
return Object.assign(new Descriptor(), { fullPath, fd });
|
|
335
329
|
}
|
|
336
330
|
catch (e) {
|
|
337
331
|
throw convertFsError(e);
|
|
338
332
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
readDirectoryEntry(sid) {
|
|
398
|
-
return io.getStream(sid).read();
|
|
399
|
-
},
|
|
400
|
-
|
|
401
|
-
dropDirectoryEntryStream(sid) {
|
|
402
|
-
io.dropStream(sid);
|
|
403
|
-
},
|
|
404
|
-
|
|
405
|
-
metadataHash(fd) {
|
|
406
|
-
const descriptor = fs.getDescriptor(fd);
|
|
407
|
-
if (descriptor.stream)
|
|
408
|
-
return { upper: 0n, lower: descriptor.stream}
|
|
409
|
-
if (descriptor.hostPreopen)
|
|
410
|
-
return { upper: 0n, lower: BigInt(fd) };
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
readlinkAt() {
|
|
336
|
+
console.log(`[filesystem] READLINK AT`, this.id);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
removeDirectoryAt() {
|
|
340
|
+
console.log(`[filesystem] REMOVE DIR AT`, this.id);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
renameAt() {
|
|
344
|
+
console.log(`[filesystem] RENAME AT`, this.id);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
symlinkAt() {
|
|
348
|
+
console.log(`[filesystem] SYMLINK AT`, this.id);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
unlinkFileAt() {
|
|
352
|
+
console.log(`[filesystem] UNLINK FILE AT`, this.id);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
changeFilePermissionsAt() {
|
|
356
|
+
console.log(`[filesystem] CHANGE FILE PERMISSIONS AT`, this.id);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
changeDirectoryPermissionsAt() {
|
|
360
|
+
console.log(`[filesystem] CHANGE DIR PERMISSIONS AT`, this.id);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
lockShared() {
|
|
364
|
+
console.log(`[filesystem] LOCK SHARED`, this.id);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
lockExclusive() {
|
|
368
|
+
console.log(`[filesystem] LOCK EXCLUSIVE`, this.id);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
tryLockShared() {
|
|
372
|
+
console.log(`[filesystem] TRY LOCK SHARED`, this.id);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
tryLockExclusive() {
|
|
376
|
+
console.log(`[filesystem] TRY LOCK EXCLUSIVE`, this.id);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
unlock() {
|
|
380
|
+
console.log(`[filesystem] UNLOCK`, this.id);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
drop() {
|
|
384
|
+
if (this.fd)
|
|
385
|
+
closeSync(this.fd);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
metadataHash() {
|
|
389
|
+
if (this.hostPreopen)
|
|
390
|
+
return { upper: 0n, lower: BigInt(this.id) };
|
|
411
391
|
try {
|
|
412
|
-
const stats = fstatSync(
|
|
392
|
+
const stats = fstatSync(this.fd, { bigint: true });
|
|
413
393
|
return { upper: stats.mtimeNs, lower: stats.ino };
|
|
414
394
|
}
|
|
415
395
|
catch (e) {
|
|
416
396
|
convertFsError(e);
|
|
417
397
|
}
|
|
418
|
-
}
|
|
398
|
+
}
|
|
419
399
|
|
|
420
|
-
metadataHashAt(
|
|
421
|
-
const fullPath = fs.getFullPath(
|
|
400
|
+
metadataHashAt(pathFlags, path) {
|
|
401
|
+
const fullPath = fs.getFullPath(this, path, false);
|
|
422
402
|
try {
|
|
423
403
|
const stats = (pathFlags.symlinkFollow ? statSync : lstatSync)(isWindows ? fullPath.slice(1) : fullPath, { bigint: true });
|
|
424
404
|
return { upper: stats.mtimeNs, lower: stats.ino };
|
|
@@ -427,11 +407,27 @@ export class FileSystem {
|
|
|
427
407
|
convertFsError(e);
|
|
428
408
|
}
|
|
429
409
|
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
this.descriptorCnt = 3;
|
|
413
|
+
this.preopenEntries = [];
|
|
414
|
+
for (const [virtualPath, hostPreopen] of Object.entries(preopens)) {
|
|
415
|
+
const preopenEntry = [Object.assign(new Descriptor(), { hostPreopen }), virtualPath];
|
|
416
|
+
this.preopenEntries.push(preopenEntry);
|
|
417
|
+
}
|
|
418
|
+
this.preopens = {
|
|
419
|
+
Descriptor,
|
|
420
|
+
getDirectories () {
|
|
421
|
+
return fs.preopenEntries;
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
this.types = {
|
|
425
|
+
Descriptor,
|
|
430
426
|
};
|
|
431
427
|
}
|
|
432
428
|
}
|
|
433
429
|
|
|
434
|
-
const _fs = new FileSystem(
|
|
430
|
+
const _fs = new FileSystem({ '/': '/' }, environment);
|
|
435
431
|
|
|
436
432
|
export const { preopens, types } = _fs;
|
|
437
433
|
|
package/lib/nodejs/http.js
CHANGED
package/lib/nodejs/index.js
CHANGED
|
@@ -1,8 +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 "
|
|
5
|
-
import * as logging from "./logging.js";
|
|
4
|
+
import * as io from "../common/io.js";
|
|
6
5
|
import * as poll from "./poll.js";
|
|
7
6
|
import * as random from "./random.js";
|
|
8
7
|
import * as sockets from "./sockets.js";
|
|
@@ -13,7 +12,6 @@ export {
|
|
|
13
12
|
filesystem,
|
|
14
13
|
http,
|
|
15
14
|
io,
|
|
16
|
-
logging,
|
|
17
15
|
poll,
|
|
18
16
|
random,
|
|
19
17
|
sockets,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytecodealliance/preview2-shim",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "WASI Preview2 shim for JS environments",
|
|
5
5
|
"author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"node": "./lib/nodejs/index.js",
|
|
12
12
|
"default": "./lib/browser/index.js"
|
|
13
13
|
},
|
|
14
|
+
"./io": {
|
|
15
|
+
"types": "./types/io.d.ts",
|
|
16
|
+
"default": "./lib/common/io.js"
|
|
17
|
+
},
|
|
14
18
|
"./*": {
|
|
15
19
|
"types": "./types/*.d.ts",
|
|
16
20
|
"node": "./lib/nodejs/*.js",
|
|
@@ -1,13 +1,2 @@
|
|
|
1
1
|
export namespace WasiCliTerminalInput {
|
|
2
|
-
/**
|
|
3
|
-
* Dispose of the specified terminal-input after which it may no longer
|
|
4
|
-
* be used.
|
|
5
|
-
*/
|
|
6
|
-
export function dropTerminalInput(this_: TerminalInput): void;
|
|
7
2
|
}
|
|
8
|
-
/**
|
|
9
|
-
* The input side of a terminal.
|
|
10
|
-
*
|
|
11
|
-
* This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
|
|
12
|
-
*/
|
|
13
|
-
export type TerminalInput = number;
|