@naturalcycles/nodejs-lib 13.3.0 → 13.5.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/dist/fs/fs.util.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export declare const fs2: {
|
|
|
39
39
|
copyPathSync: typeof _copyPathSync;
|
|
40
40
|
movePath: typeof _movePath;
|
|
41
41
|
movePathSync: typeof _movePathSync;
|
|
42
|
+
statAsync: typeof fs.promises.stat;
|
|
43
|
+
mkdirAsync: typeof fs.promises.mkdir;
|
|
42
44
|
link: typeof fs.link;
|
|
43
45
|
open: typeof fs.open;
|
|
44
46
|
truncate: typeof fs.truncate;
|
package/dist/fs/fs.util.js
CHANGED
|
@@ -9,6 +9,14 @@ export interface PipelineOptions {
|
|
|
9
9
|
* Required to support graceful close when using transformLimit
|
|
10
10
|
*/
|
|
11
11
|
allowClose?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Set to true to allow graceful abort (via AbortSignal).
|
|
14
|
+
* "Graceful" means it'll swallow the AbortError and let the pipeline resolve normally.
|
|
15
|
+
*
|
|
16
|
+
* Default is false - AbortError will be thrown.
|
|
17
|
+
*/
|
|
18
|
+
allowGracefulAbort?: boolean;
|
|
19
|
+
signal?: AbortSignal;
|
|
12
20
|
}
|
|
13
21
|
/**
|
|
14
22
|
* Promisified `stream.pipeline`.
|
|
@@ -45,7 +45,7 @@ async function _pipeline(streams, opt = {}) {
|
|
|
45
45
|
};
|
|
46
46
|
rest.forEach(s => {
|
|
47
47
|
// console.log(s)
|
|
48
|
-
if (s instanceof AbortableTransform || s.constructor.name === '
|
|
48
|
+
if (s instanceof AbortableTransform || s.constructor.name === 'AbortableTransform') {
|
|
49
49
|
// console.log(`found ${s.constructor.name}, setting props`)
|
|
50
50
|
;
|
|
51
51
|
s.sourceReadable = sourceReadable;
|
|
@@ -54,13 +54,17 @@ async function _pipeline(streams, opt = {}) {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
try {
|
|
57
|
-
return await (0, promises_1.pipeline)(first, ...rest);
|
|
57
|
+
return await (0, promises_1.pipeline)([first, ...rest], opt);
|
|
58
58
|
}
|
|
59
59
|
catch (err) {
|
|
60
60
|
if (opt.allowClose && err?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
|
|
61
61
|
console.log('_pipeline closed (as expected)');
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
+
if (opt.allowGracefulAbort && err?.name === 'AbortError') {
|
|
65
|
+
console.log('_pipeline closed via AbortSignal (as expected)');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
64
68
|
// console.log(`_pipeline error`, err)
|
|
65
69
|
throw err;
|
|
66
70
|
}
|
package/package.json
CHANGED
package/src/fs/fs.util.ts
CHANGED
|
@@ -11,6 +11,16 @@ export interface PipelineOptions {
|
|
|
11
11
|
* Required to support graceful close when using transformLimit
|
|
12
12
|
*/
|
|
13
13
|
allowClose?: boolean
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Set to true to allow graceful abort (via AbortSignal).
|
|
17
|
+
* "Graceful" means it'll swallow the AbortError and let the pipeline resolve normally.
|
|
18
|
+
*
|
|
19
|
+
* Default is false - AbortError will be thrown.
|
|
20
|
+
*/
|
|
21
|
+
allowGracefulAbort?: boolean
|
|
22
|
+
|
|
23
|
+
signal?: AbortSignal
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
/**
|
|
@@ -55,7 +65,7 @@ export async function _pipeline(streams: AnyStream[], opt: PipelineOptions = {})
|
|
|
55
65
|
|
|
56
66
|
rest.forEach(s => {
|
|
57
67
|
// console.log(s)
|
|
58
|
-
if (s instanceof AbortableTransform || s.constructor.name === '
|
|
68
|
+
if (s instanceof AbortableTransform || s.constructor.name === 'AbortableTransform') {
|
|
59
69
|
// console.log(`found ${s.constructor.name}, setting props`)
|
|
60
70
|
;(s as AbortableTransform).sourceReadable = sourceReadable
|
|
61
71
|
;(s as AbortableTransform).streamDone = streamDone
|
|
@@ -64,12 +74,18 @@ export async function _pipeline(streams: AnyStream[], opt: PipelineOptions = {})
|
|
|
64
74
|
}
|
|
65
75
|
|
|
66
76
|
try {
|
|
67
|
-
return await pipeline(first, ...
|
|
77
|
+
return await pipeline([first, ...rest], opt)
|
|
68
78
|
} catch (err) {
|
|
69
79
|
if (opt.allowClose && (err as any)?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
|
|
70
80
|
console.log('_pipeline closed (as expected)')
|
|
71
81
|
return
|
|
72
82
|
}
|
|
83
|
+
|
|
84
|
+
if (opt.allowGracefulAbort && (err as any)?.name === 'AbortError') {
|
|
85
|
+
console.log('_pipeline closed via AbortSignal (as expected)')
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
73
89
|
// console.log(`_pipeline error`, err)
|
|
74
90
|
throw err
|
|
75
91
|
}
|