@bytecodealliance/preview2-shim 0.17.1 → 0.17.3
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/cli.js +91 -94
- package/lib/browser/clocks.js +30 -29
- package/lib/browser/filesystem.js +298 -251
- package/lib/browser/http.js +129 -128
- package/lib/browser/index.js +8 -16
- package/lib/browser/io.js +143 -135
- package/lib/browser/random.js +44 -42
- package/lib/browser/sockets.js +68 -166
- package/lib/common/instantiation.js +127 -0
- package/lib/io/calls.js +7 -5
- package/lib/io/worker-http.js +175 -157
- package/lib/io/worker-io.js +402 -386
- package/lib/io/worker-socket-tcp.js +271 -219
- package/lib/io/worker-socket-udp.js +494 -429
- package/lib/io/worker-sockets.js +276 -262
- package/lib/io/worker-thread.js +946 -815
- package/lib/nodejs/cli.js +64 -63
- package/lib/nodejs/clocks.js +51 -45
- package/lib/nodejs/filesystem.js +788 -654
- package/lib/nodejs/http.js +693 -617
- package/lib/nodejs/index.js +8 -16
- package/lib/nodejs/random.js +32 -28
- package/lib/nodejs/sockets.js +538 -474
- package/lib/synckit/index.js +94 -85
- package/package.json +9 -5
- package/types/cli.d.ts +11 -23
- package/types/clocks.d.ts +2 -5
- package/types/filesystem.d.ts +2 -5
- package/types/http.d.ts +3 -7
- package/types/index.d.ts +6 -15
- package/types/instantiation.d.ts +112 -0
- package/types/interfaces/wasi-cli-environment.d.ts +21 -22
- package/types/interfaces/wasi-cli-exit.d.ts +5 -6
- package/types/interfaces/wasi-cli-run.d.ts +5 -6
- package/types/interfaces/wasi-cli-stderr.d.ts +3 -5
- package/types/interfaces/wasi-cli-stdin.d.ts +3 -5
- package/types/interfaces/wasi-cli-stdout.d.ts +3 -5
- package/types/interfaces/wasi-cli-terminal-input.d.ts +5 -3
- package/types/interfaces/wasi-cli-terminal-output.d.ts +5 -3
- package/types/interfaces/wasi-cli-terminal-stderr.d.ts +7 -9
- package/types/interfaces/wasi-cli-terminal-stdin.d.ts +7 -9
- package/types/interfaces/wasi-cli-terminal-stdout.d.ts +7 -9
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +24 -26
- package/types/interfaces/wasi-clocks-wall-clock.d.ts +23 -24
- package/types/interfaces/wasi-filesystem-preopens.d.ts +6 -8
- package/types/interfaces/wasi-filesystem-types.d.ts +34 -33
- package/types/interfaces/wasi-http-incoming-handler.d.ts +16 -19
- package/types/interfaces/wasi-http-outgoing-handler.d.ts +18 -23
- package/types/interfaces/wasi-http-types.d.ts +49 -38
- package/types/interfaces/wasi-io-error.d.ts +5 -3
- package/types/interfaces/wasi-io-poll.d.ts +27 -25
- package/types/interfaces/wasi-io-streams.d.ts +24 -21
- package/types/interfaces/wasi-random-insecure-seed.d.ts +21 -22
- package/types/interfaces/wasi-random-insecure.d.ts +19 -20
- package/types/interfaces/wasi-random-random.d.ts +23 -24
- package/types/interfaces/wasi-sockets-instance-network.d.ts +6 -8
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +32 -34
- package/types/interfaces/wasi-sockets-network.d.ts +5 -3
- package/types/interfaces/wasi-sockets-tcp-create-socket.d.ts +28 -33
- package/types/interfaces/wasi-sockets-tcp.d.ts +17 -23
- package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +28 -33
- package/types/interfaces/wasi-sockets-udp.d.ts +20 -17
- package/types/io.d.ts +3 -7
- package/types/random.d.ts +3 -7
- package/types/sockets.d.ts +7 -15
- package/types/wasi-cli-command.d.ts +29 -29
- package/types/wasi-http-proxy.d.ts +13 -13
package/lib/browser/http.js
CHANGED
|
@@ -3,142 +3,143 @@
|
|
|
3
3
|
* @returns {string}
|
|
4
4
|
*/
|
|
5
5
|
export function send(req) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
console.log(`[http] Send (browser) ${req.uri}`);
|
|
7
|
+
try {
|
|
8
|
+
const xhr = new XMLHttpRequest();
|
|
9
|
+
xhr.open(req.method.toString(), req.uri, false);
|
|
10
|
+
const requestHeaders = new Headers(req.headers);
|
|
11
|
+
for (let [name, value] of requestHeaders.entries()) {
|
|
12
|
+
if (name !== 'user-agent' && name !== 'host') {
|
|
13
|
+
xhr.setRequestHeader(name, value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
xhr.send(req.body && req.body.length > 0 ? req.body : null);
|
|
17
|
+
const body = xhr.response
|
|
18
|
+
? new TextEncoder().encode(xhr.response)
|
|
19
|
+
: undefined;
|
|
20
|
+
const headers = [];
|
|
21
|
+
xhr.getAllResponseHeaders()
|
|
22
|
+
.trim()
|
|
23
|
+
.split(/[\r\n]+/)
|
|
24
|
+
.forEach((line) => {
|
|
25
|
+
var parts = line.split(': ');
|
|
26
|
+
var key = parts.shift();
|
|
27
|
+
var value = parts.join(': ');
|
|
28
|
+
headers.push([key, value]);
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
status: xhr.status,
|
|
32
|
+
headers,
|
|
33
|
+
body,
|
|
34
|
+
};
|
|
35
|
+
} catch (err) {
|
|
36
|
+
throw new Error(err.message);
|
|
15
37
|
}
|
|
16
|
-
xhr.send(req.body && req.body.length > 0 ? req.body : null);
|
|
17
|
-
const body = xhr.response ? new TextEncoder().encode(xhr.response) : undefined;
|
|
18
|
-
const headers = [];
|
|
19
|
-
xhr.getAllResponseHeaders().trim().split(/[\r\n]+/).forEach((line) => {
|
|
20
|
-
var parts = line.split(': ');
|
|
21
|
-
var key = parts.shift();
|
|
22
|
-
var value = parts.join(': ');
|
|
23
|
-
headers.push([key, value]);
|
|
24
|
-
});
|
|
25
|
-
return {
|
|
26
|
-
status: xhr.status,
|
|
27
|
-
headers,
|
|
28
|
-
body,
|
|
29
|
-
};
|
|
30
|
-
} catch (err) {
|
|
31
|
-
throw new Error(err.message);
|
|
32
|
-
}
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export const incomingHandler = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
41
|
+
handle() {},
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
export const outgoingHandler = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
+
handle() {},
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
export const types = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
49
|
+
dropFields(_fields) {
|
|
50
|
+
console.log('[types] Drop fields');
|
|
51
|
+
},
|
|
52
|
+
newFields(_entries) {
|
|
53
|
+
console.log('[types] New fields');
|
|
54
|
+
},
|
|
55
|
+
fieldsGet(_fields, _name) {
|
|
56
|
+
console.log('[types] Fields get');
|
|
57
|
+
},
|
|
58
|
+
fieldsSet(_fields, _name, _value) {
|
|
59
|
+
console.log('[types] Fields set');
|
|
60
|
+
},
|
|
61
|
+
fieldsDelete(_fields, _name) {
|
|
62
|
+
console.log('[types] Fields delete');
|
|
63
|
+
},
|
|
64
|
+
fieldsAppend(_fields, _name, _value) {
|
|
65
|
+
console.log('[types] Fields append');
|
|
66
|
+
},
|
|
67
|
+
fieldsEntries(_fields) {
|
|
68
|
+
console.log('[types] Fields entries');
|
|
69
|
+
},
|
|
70
|
+
fieldsClone(_fields) {
|
|
71
|
+
console.log('[types] Fields clone');
|
|
72
|
+
},
|
|
73
|
+
finishIncomingStream(s) {
|
|
74
|
+
console.log(`[types] Finish incoming stream ${s}`);
|
|
75
|
+
},
|
|
76
|
+
finishOutgoingStream(s, _trailers) {
|
|
77
|
+
console.log(`[types] Finish outgoing stream ${s}`);
|
|
78
|
+
},
|
|
79
|
+
dropIncomingRequest(_req) {
|
|
80
|
+
console.log('[types] Drop incoming request');
|
|
81
|
+
},
|
|
82
|
+
dropOutgoingRequest(_req) {
|
|
83
|
+
console.log('[types] Drop outgoing request');
|
|
84
|
+
},
|
|
85
|
+
incomingRequestMethod(_req) {
|
|
86
|
+
console.log('[types] Incoming request method');
|
|
87
|
+
},
|
|
88
|
+
incomingRequestPathWithQuery(_req) {
|
|
89
|
+
console.log('[types] Incoming request path with query');
|
|
90
|
+
},
|
|
91
|
+
incomingRequestScheme(_req) {
|
|
92
|
+
console.log('[types] Incoming request scheme');
|
|
93
|
+
},
|
|
94
|
+
incomingRequestAuthority(_req) {
|
|
95
|
+
console.log('[types] Incoming request authority');
|
|
96
|
+
},
|
|
97
|
+
incomingRequestHeaders(_req) {
|
|
98
|
+
console.log('[types] Incoming request headers');
|
|
99
|
+
},
|
|
100
|
+
incomingRequestConsume(_req) {
|
|
101
|
+
console.log('[types] Incoming request consume');
|
|
102
|
+
},
|
|
103
|
+
newOutgoingRequest(_method, _pathWithQuery, _scheme, _authority, _headers) {
|
|
104
|
+
console.log('[types] New outgoing request');
|
|
105
|
+
},
|
|
106
|
+
outgoingRequestWrite(_req) {
|
|
107
|
+
console.log('[types] Outgoing request write');
|
|
108
|
+
},
|
|
109
|
+
dropResponseOutparam(_res) {
|
|
110
|
+
console.log('[types] Drop response outparam');
|
|
111
|
+
},
|
|
112
|
+
setResponseOutparam(_response) {
|
|
113
|
+
console.log('[types] Drop fields');
|
|
114
|
+
},
|
|
115
|
+
dropIncomingResponse(_res) {
|
|
116
|
+
console.log('[types] Drop incoming response');
|
|
117
|
+
},
|
|
118
|
+
dropOutgoingResponse(_res) {
|
|
119
|
+
console.log('[types] Drop outgoing response');
|
|
120
|
+
},
|
|
121
|
+
incomingResponseStatus(_res) {
|
|
122
|
+
console.log('[types] Incoming response status');
|
|
123
|
+
},
|
|
124
|
+
incomingResponseHeaders(_res) {
|
|
125
|
+
console.log('[types] Incoming response headers');
|
|
126
|
+
},
|
|
127
|
+
incomingResponseConsume(_res) {
|
|
128
|
+
console.log('[types] Incoming response consume');
|
|
129
|
+
},
|
|
130
|
+
newOutgoingResponse(_statusCode, _headers) {
|
|
131
|
+
console.log('[types] New outgoing response');
|
|
132
|
+
},
|
|
133
|
+
outgoingResponseWrite(_res) {
|
|
134
|
+
console.log('[types] Outgoing response write');
|
|
135
|
+
},
|
|
136
|
+
dropFutureIncomingResponse(_f) {
|
|
137
|
+
console.log('[types] Drop future incoming response');
|
|
138
|
+
},
|
|
139
|
+
futureIncomingResponseGet(_f) {
|
|
140
|
+
console.log('[types] Future incoming response get');
|
|
141
|
+
},
|
|
142
|
+
listenToFutureIncomingResponse(_f) {
|
|
143
|
+
console.log('[types] Listen to future incoming response');
|
|
144
|
+
},
|
|
144
145
|
};
|
package/lib/browser/index.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import * as clocks from
|
|
2
|
-
import * as filesystem from
|
|
3
|
-
import * as http from
|
|
4
|
-
import * as io from
|
|
5
|
-
import * as random from
|
|
6
|
-
import * as sockets from
|
|
7
|
-
import * as cli from
|
|
1
|
+
import * as clocks from './clocks.js';
|
|
2
|
+
import * as filesystem from './filesystem.js';
|
|
3
|
+
import * as http from './http.js';
|
|
4
|
+
import * as io from './io.js';
|
|
5
|
+
import * as random from './random.js';
|
|
6
|
+
import * as sockets from './sockets.js';
|
|
7
|
+
import * as cli from './cli.js';
|
|
8
8
|
|
|
9
|
-
export {
|
|
10
|
-
clocks,
|
|
11
|
-
filesystem,
|
|
12
|
-
http,
|
|
13
|
-
io,
|
|
14
|
-
random,
|
|
15
|
-
sockets,
|
|
16
|
-
cli,
|
|
17
|
-
}
|
|
9
|
+
export { clocks, filesystem, http, io, random, sockets, cli };
|
package/lib/browser/io.js
CHANGED
|
@@ -3,13 +3,13 @@ let id = 0;
|
|
|
3
3
|
const symbolDispose = Symbol.dispose || Symbol.for('dispose');
|
|
4
4
|
|
|
5
5
|
const IoError = class Error {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
6
|
+
constructor(msg) {
|
|
7
|
+
this.msg = msg;
|
|
8
|
+
}
|
|
9
|
+
toDebugString() {
|
|
10
|
+
return this.msg;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {{
|
|
@@ -20,7 +20,7 @@ const IoError = class Error {
|
|
|
20
20
|
* subscribe: () => void,
|
|
21
21
|
* drop?: () => void,
|
|
22
22
|
* }} InputStreamHandler
|
|
23
|
-
*
|
|
23
|
+
*
|
|
24
24
|
* @typedef {{
|
|
25
25
|
* checkWrite?: () -> BigInt,
|
|
26
26
|
* write: (buf: Uint8Array) => BigInt,
|
|
@@ -36,132 +36,140 @@ const IoError = class Error {
|
|
|
36
36
|
* subscribe?: () => void,
|
|
37
37
|
* drop?: () => void,
|
|
38
38
|
* }} OutputStreamHandler
|
|
39
|
-
*
|
|
39
|
+
*
|
|
40
40
|
**/
|
|
41
41
|
|
|
42
42
|
class InputStream {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
43
|
+
/**
|
|
44
|
+
* @param {InputStreamHandler} handler
|
|
45
|
+
*/
|
|
46
|
+
constructor(handler) {
|
|
47
|
+
if (!handler) {
|
|
48
|
+
console.trace('no handler');
|
|
49
|
+
}
|
|
50
|
+
this.id = ++id;
|
|
51
|
+
this.handler = handler;
|
|
52
|
+
}
|
|
53
|
+
read(len) {
|
|
54
|
+
if (this.handler.read) {
|
|
55
|
+
return this.handler.read(len);
|
|
56
|
+
}
|
|
57
|
+
return this.handler.blockingRead.call(this, len);
|
|
58
|
+
}
|
|
59
|
+
blockingRead(len) {
|
|
60
|
+
return this.handler.blockingRead.call(this, len);
|
|
61
|
+
}
|
|
62
|
+
skip(len) {
|
|
63
|
+
if (this.handler.skip) {
|
|
64
|
+
return this.handler.skip.call(this, len);
|
|
65
|
+
}
|
|
66
|
+
if (this.handler.read) {
|
|
67
|
+
const bytes = this.handler.read.call(this, len);
|
|
68
|
+
return BigInt(bytes.byteLength);
|
|
69
|
+
}
|
|
70
|
+
return this.blockingSkip.call(this, len);
|
|
71
|
+
}
|
|
72
|
+
blockingSkip(len) {
|
|
73
|
+
if (this.handler.blockingSkip) {
|
|
74
|
+
return this.handler.blockingSkip.call(this, len);
|
|
75
|
+
}
|
|
76
|
+
const bytes = this.handler.blockingRead.call(this, len);
|
|
77
|
+
return BigInt(bytes.byteLength);
|
|
78
|
+
}
|
|
79
|
+
subscribe() {
|
|
80
|
+
console.log(`[streams] Subscribe to input stream ${this.id}`);
|
|
81
|
+
}
|
|
82
|
+
[symbolDispose]() {
|
|
83
|
+
if (this.handler.drop) {
|
|
84
|
+
this.handler.drop.call(this);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
class OutputStream {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @param {OutputStreamHandler} handler
|
|
92
|
+
*/
|
|
93
|
+
constructor(handler) {
|
|
94
|
+
if (!handler) {
|
|
95
|
+
console.trace('no handler');
|
|
96
|
+
}
|
|
97
|
+
this.id = ++id;
|
|
98
|
+
this.open = true;
|
|
99
|
+
this.handler = handler;
|
|
100
|
+
}
|
|
101
|
+
checkWrite(len) {
|
|
102
|
+
if (!this.open) {
|
|
103
|
+
return 0n;
|
|
104
|
+
}
|
|
105
|
+
if (this.handler.checkWrite) {
|
|
106
|
+
return this.handler.checkWrite.call(this, len);
|
|
107
|
+
}
|
|
108
|
+
return 1_000_000n;
|
|
109
|
+
}
|
|
110
|
+
write(buf) {
|
|
111
|
+
this.handler.write.call(this, buf);
|
|
112
|
+
}
|
|
113
|
+
blockingWriteAndFlush(buf) {
|
|
114
|
+
/// Perform a write of up to 4096 bytes, and then flush the stream. Block
|
|
115
|
+
/// until all of these operations are complete, or an error occurs.
|
|
116
|
+
///
|
|
117
|
+
/// This is a convenience wrapper around the use of `check-write`,
|
|
118
|
+
/// `subscribe`, `write`, and `flush`, and is implemented with the
|
|
119
|
+
/// following pseudo-code:
|
|
120
|
+
///
|
|
121
|
+
/// ```text
|
|
122
|
+
/// let pollable = this.subscribe();
|
|
123
|
+
/// while !contents.is_empty() {
|
|
124
|
+
/// // Wait for the stream to become writable
|
|
125
|
+
/// poll-one(pollable);
|
|
126
|
+
/// let Ok(n) = this.check-write(); // eliding error handling
|
|
127
|
+
/// let len = min(n, contents.len());
|
|
128
|
+
/// let (chunk, rest) = contents.split_at(len);
|
|
129
|
+
/// this.write(chunk ); // eliding error handling
|
|
130
|
+
/// contents = rest;
|
|
131
|
+
/// }
|
|
132
|
+
/// this.flush();
|
|
133
|
+
/// // Wait for completion of `flush`
|
|
134
|
+
/// poll-one(pollable);
|
|
135
|
+
/// // Check for any errors that arose during `flush`
|
|
136
|
+
/// let _ = this.check-write(); // eliding error handling
|
|
137
|
+
/// ```
|
|
138
|
+
this.handler.write.call(this, buf);
|
|
139
|
+
}
|
|
140
|
+
flush() {
|
|
141
|
+
if (this.handler.flush) {
|
|
142
|
+
this.handler.flush.call(this);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
blockingFlush() {
|
|
146
|
+
this.open = true;
|
|
147
|
+
}
|
|
148
|
+
writeZeroes(len) {
|
|
149
|
+
this.write.call(this, new Uint8Array(Number(len)));
|
|
150
|
+
}
|
|
151
|
+
blockingWriteZeroes(len) {
|
|
152
|
+
this.blockingWrite.call(this, new Uint8Array(Number(len)));
|
|
153
|
+
}
|
|
154
|
+
blockingWriteZeroesAndFlush(len) {
|
|
155
|
+
this.blockingWriteAndFlush.call(this, new Uint8Array(Number(len)));
|
|
156
|
+
}
|
|
157
|
+
splice(src, len) {
|
|
158
|
+
const spliceLen = Math.min(len, this.checkWrite.call(this));
|
|
159
|
+
const bytes = src.read(spliceLen);
|
|
160
|
+
this.write.call(this, bytes);
|
|
161
|
+
return bytes.byteLength;
|
|
162
|
+
}
|
|
163
|
+
blockingSplice(_src, _len) {
|
|
164
|
+
console.log(`[streams] Blocking splice ${this.id}`);
|
|
165
|
+
}
|
|
166
|
+
forward(_src) {
|
|
167
|
+
console.log(`[streams] Forward ${this.id}`);
|
|
168
|
+
}
|
|
169
|
+
subscribe() {
|
|
170
|
+
console.log(`[streams] Subscribe to output stream ${this.id}`);
|
|
171
|
+
}
|
|
172
|
+
[symbolDispose]() {}
|
|
165
173
|
}
|
|
166
174
|
|
|
167
175
|
export const error = { Error: IoError };
|
|
@@ -170,16 +178,16 @@ export const streams = { InputStream, OutputStream };
|
|
|
170
178
|
|
|
171
179
|
class Pollable {}
|
|
172
180
|
|
|
173
|
-
function pollList
|
|
174
|
-
|
|
181
|
+
function pollList(_list) {
|
|
182
|
+
// TODO
|
|
175
183
|
}
|
|
176
184
|
|
|
177
|
-
function pollOne
|
|
178
|
-
|
|
185
|
+
function pollOne(_poll) {
|
|
186
|
+
// TODO
|
|
179
187
|
}
|
|
180
188
|
|
|
181
189
|
export const poll = {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
190
|
+
Pollable,
|
|
191
|
+
pollList,
|
|
192
|
+
pollOne,
|
|
185
193
|
};
|