@agoric/internal 0.3.3-dev-d122756.0 → 0.3.3-dev-7ae1f27.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/package.json +3 -3
- package/src/node/fs-stream.d.ts +1 -1
- package/src/node/fs-stream.d.ts.map +1 -1
- package/src/node/fs-stream.js +40 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/internal",
|
|
3
|
-
"version": "0.3.3-dev-
|
|
3
|
+
"version": "0.3.3-dev-7ae1f27.0+7ae1f27",
|
|
4
4
|
"description": "Externally unsupported utilities internal to agoric-sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint:types": "tsc"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@agoric/base-zone": "0.1.1-dev-
|
|
23
|
+
"@agoric/base-zone": "0.1.1-dev-7ae1f27.0+7ae1f27",
|
|
24
24
|
"@endo/common": "^1.2.7",
|
|
25
25
|
"@endo/errors": "^1.2.7",
|
|
26
26
|
"@endo/far": "^1.1.8",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"typeCoverage": {
|
|
60
60
|
"atLeast": 93.42
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "7ae1f278fa8cbeb0cfc777b7cebf507b1f07c958"
|
|
63
63
|
}
|
package/src/node/fs-stream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function fsStreamReady(stream: import("fs").ReadStream | import("fs").WriteStream): Promise<void>;
|
|
1
|
+
export function fsStreamReady(stream: import("fs").ReadStream | import("fs").WriteStream | import("net").Socket): Promise<void>;
|
|
2
2
|
export function makeFsStreamWriter(filePath: string | undefined | null): Promise<{
|
|
3
3
|
write: (data: any) => Promise<void>;
|
|
4
4
|
flush: () => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-stream.d.ts","sourceRoot":"","sources":["fs-stream.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fs-stream.d.ts","sourceRoot":"","sources":["fs-stream.js"],"names":[],"mappings":"AAUO,sCALI,OAAO,IAAI,EAAE,UAAU,GAC3B,OAAO,IAAI,EAAE,WAAW,GACxB,OAAO,KAAK,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAgCtB;AAQG,6CADK,MAAM,GAAG,SAAS,GAAG,IAAI;;;;eAqEpC;6BAtEa,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC"}
|
package/src/node/fs-stream.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import process from 'node:process';
|
|
2
3
|
import { open } from 'node:fs/promises';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
* @param {import('fs').ReadStream
|
|
6
|
+
* @param {import('fs').ReadStream
|
|
7
|
+
* | import('fs').WriteStream
|
|
8
|
+
* | import('net').Socket} stream
|
|
6
9
|
* @returns {Promise<void>}
|
|
7
10
|
*/
|
|
8
11
|
export const fsStreamReady = stream =>
|
|
@@ -48,45 +51,51 @@ export const makeFsStreamWriter = async filePath => {
|
|
|
48
51
|
return undefined;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
const handle = await open(filePath, 'a');
|
|
54
|
+
const handle = await (filePath !== '-' ? open(filePath, 'a') : undefined);
|
|
52
55
|
|
|
53
|
-
const stream =
|
|
56
|
+
const stream = handle
|
|
57
|
+
? createWriteStream(noPath, { fd: handle.fd })
|
|
58
|
+
: process.stdout;
|
|
54
59
|
await fsStreamReady(stream);
|
|
55
60
|
|
|
56
61
|
let flushed = Promise.resolve();
|
|
57
62
|
let closed = false;
|
|
58
63
|
|
|
59
|
-
const
|
|
60
|
-
if (closed) {
|
|
61
|
-
throw Error('Stream closed');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** @type {Promise<void>} */
|
|
65
|
-
const written = new Promise((resolve, reject) => {
|
|
66
|
-
stream.write(data, err => {
|
|
67
|
-
if (err) {
|
|
68
|
-
reject(err);
|
|
69
|
-
} else {
|
|
70
|
-
resolve();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
64
|
+
const updateFlushed = p => {
|
|
74
65
|
flushed = flushed.then(
|
|
75
|
-
() =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
() => p,
|
|
67
|
+
err =>
|
|
68
|
+
p.then(
|
|
69
|
+
() => Promise.reject(err),
|
|
70
|
+
pError =>
|
|
71
|
+
Promise.reject(
|
|
72
|
+
pError !== err ? AggregateError([err, pError]) : err,
|
|
73
|
+
),
|
|
82
74
|
),
|
|
83
75
|
);
|
|
76
|
+
flushed.catch(() => {});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const write = async data => {
|
|
80
|
+
/** @type {Promise<void>} */
|
|
81
|
+
const written = closed
|
|
82
|
+
? Promise.reject(Error('Stream closed'))
|
|
83
|
+
: new Promise((resolve, reject) => {
|
|
84
|
+
stream.write(data, err => {
|
|
85
|
+
if (err) {
|
|
86
|
+
reject(err);
|
|
87
|
+
} else {
|
|
88
|
+
resolve();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
updateFlushed(written);
|
|
84
93
|
return written;
|
|
85
94
|
};
|
|
86
95
|
|
|
87
96
|
const flush = async () => {
|
|
88
97
|
await flushed;
|
|
89
|
-
await handle
|
|
98
|
+
await handle?.sync().catch(err => {
|
|
90
99
|
if (err.code === 'EINVAL') {
|
|
91
100
|
return;
|
|
92
101
|
}
|
|
@@ -95,10 +104,14 @@ export const makeFsStreamWriter = async filePath => {
|
|
|
95
104
|
};
|
|
96
105
|
|
|
97
106
|
const close = async () => {
|
|
107
|
+
// TODO: Consider creating a single Error here to use a write rejection
|
|
98
108
|
closed = true;
|
|
99
109
|
await flush();
|
|
100
|
-
|
|
110
|
+
// @ts-expect-error calling a possibly missing method
|
|
111
|
+
stream.close?.();
|
|
101
112
|
};
|
|
102
113
|
|
|
114
|
+
stream.on('error', err => updateFlushed(Promise.reject(err)));
|
|
115
|
+
|
|
103
116
|
return harden({ write, flush, close });
|
|
104
117
|
};
|