@agoric/internal 0.4.0-u19.0 → 0.4.0-u19.2
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.map +1 -1
- package/src/node/fs-stream.js +23 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/internal",
|
|
3
|
-
"version": "0.4.0-u19.
|
|
3
|
+
"version": "0.4.0-u19.2",
|
|
4
4
|
"description": "Externally unsupported utilities internal to agoric-sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"jessie.js": "^0.3.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@agoric/cosmic-proto": "^0.5.0-u19.
|
|
37
|
+
"@agoric/cosmic-proto": "^0.5.0-u19.2",
|
|
38
38
|
"@endo/exo": "^1.5.8",
|
|
39
39
|
"@endo/init": "^1.1.8",
|
|
40
40
|
"ava": "^5.3.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"typeCoverage": {
|
|
61
61
|
"atLeast": 93.04
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "f0ae74b84cb6de3724bfdcd18b4bea7e8199dee1"
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAIG,6CADK,MAAM,GAAG,SAAS,GAAG,IAAI;;;;eAwEpC;6BAzEa,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC"}
|
package/src/node/fs-stream.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createWriteStream } from 'node:fs';
|
|
2
|
-
import process from 'node:process';
|
|
3
1
|
import { open } from 'node:fs/promises';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {import('fs').ReadStream
|
|
@@ -40,10 +40,6 @@ export const fsStreamReady = stream =>
|
|
|
40
40
|
stream.on('error', onError);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
const noPath = /** @type {import('fs').PathLike} */ (
|
|
44
|
-
/** @type {unknown} */ (undefined)
|
|
45
|
-
);
|
|
46
|
-
|
|
47
43
|
/** @typedef {NonNullable<Awaited<ReturnType<typeof makeFsStreamWriter>>>} FsStreamWriter */
|
|
48
44
|
/** @param {string | undefined | null} filePath */
|
|
49
45
|
export const makeFsStreamWriter = async filePath => {
|
|
@@ -51,12 +47,22 @@ export const makeFsStreamWriter = async filePath => {
|
|
|
51
47
|
return undefined;
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
const useStdout = filePath === '-';
|
|
51
|
+
const { handle, stream } = await (async () => {
|
|
52
|
+
if (useStdout) {
|
|
53
|
+
return { handle: undefined, stream: process.stdout };
|
|
54
|
+
}
|
|
55
|
+
const fh = await open(filePath, 'a');
|
|
56
|
+
return { handle: fh, stream: fh.createWriteStream({ flush: true }) };
|
|
57
|
+
})();
|
|
59
58
|
await fsStreamReady(stream);
|
|
59
|
+
const writeAsync = promisify(stream.write.bind(stream));
|
|
60
|
+
const closeAsync =
|
|
61
|
+
useStdout || !(/** @type {any} */ (stream).close)
|
|
62
|
+
? undefined
|
|
63
|
+
: promisify(
|
|
64
|
+
/** @type {import('fs').WriteStream} */ (stream).close.bind(stream),
|
|
65
|
+
);
|
|
60
66
|
|
|
61
67
|
let flushed = Promise.resolve();
|
|
62
68
|
let closed = false;
|
|
@@ -77,20 +83,14 @@ export const makeFsStreamWriter = async filePath => {
|
|
|
77
83
|
};
|
|
78
84
|
|
|
79
85
|
const write = async data => {
|
|
80
|
-
/** @type {Promise<void>} */
|
|
81
86
|
const written = closed
|
|
82
87
|
? Promise.reject(Error('Stream closed'))
|
|
83
|
-
:
|
|
84
|
-
stream.write(data, err => {
|
|
85
|
-
if (err) {
|
|
86
|
-
reject(err);
|
|
87
|
-
} else {
|
|
88
|
-
resolve();
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
88
|
+
: writeAsync(data);
|
|
92
89
|
updateFlushed(written);
|
|
93
|
-
|
|
90
|
+
const waitForDrain = await written;
|
|
91
|
+
if (waitForDrain) {
|
|
92
|
+
await new Promise(resolve => stream.once('drain', resolve));
|
|
93
|
+
}
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
const flush = async () => {
|
|
@@ -107,8 +107,7 @@ export const makeFsStreamWriter = async filePath => {
|
|
|
107
107
|
// TODO: Consider creating a single Error here to use a write rejection
|
|
108
108
|
closed = true;
|
|
109
109
|
await flush();
|
|
110
|
-
|
|
111
|
-
stream.close?.();
|
|
110
|
+
await closeAsync?.();
|
|
112
111
|
};
|
|
113
112
|
|
|
114
113
|
stream.on('error', err => updateFlushed(Promise.reject(err)));
|