@naturalcycles/nodejs-lib 13.23.0 → 13.23.1
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/fs2.d.ts +2 -2
- package/dist/fs/fs2.js +13 -12
- package/dist/stream/ndjson/ndjsonMap.js +1 -1
- package/package.json +1 -1
- package/src/fs/fs2.ts +13 -16
- package/src/stream/ndjson/ndjsonMap.ts +1 -1
package/dist/fs/fs2.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { RmOptions } from 'node:fs';
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import { DumpOptions } from 'js-yaml';
|
|
7
|
-
import { ReadableTyped,
|
|
7
|
+
import { ReadableTyped, TransformTyped } from '../stream/stream.model';
|
|
8
8
|
/**
|
|
9
9
|
* fs2 conveniently groups filesystem functions together.
|
|
10
10
|
* Supposed to be almost a drop-in replacement for these things together:
|
|
@@ -77,7 +77,7 @@ declare class FS2 {
|
|
|
77
77
|
createWriteStream: typeof fs.createWriteStream;
|
|
78
78
|
createReadStream: typeof fs.createReadStream;
|
|
79
79
|
createReadStreamAsNDJSON<ROW = any>(inputPath: string): ReadableTyped<ROW>;
|
|
80
|
-
createWriteStreamAsNDJSON(outputPath: string):
|
|
80
|
+
createWriteStreamAsNDJSON(outputPath: string): TransformTyped<any, any>[];
|
|
81
81
|
}
|
|
82
82
|
export declare const fs2: FS2;
|
|
83
83
|
export interface JsonOptions {
|
package/dist/fs/fs2.js
CHANGED
|
@@ -311,7 +311,8 @@ class FS2 {
|
|
|
311
311
|
// .pipe(transformJsonParse<ROW>())
|
|
312
312
|
}
|
|
313
313
|
/*
|
|
314
|
-
Returns
|
|
314
|
+
Returns an array of Transforms, so that you can ...destructure them at
|
|
315
|
+
the end of the _pipeline.
|
|
315
316
|
|
|
316
317
|
Replaces a list of operations:
|
|
317
318
|
- transformToNDJson
|
|
@@ -320,17 +321,17 @@ class FS2 {
|
|
|
320
321
|
*/
|
|
321
322
|
createWriteStreamAsNDJSON(outputPath) {
|
|
322
323
|
this.ensureFile(outputPath);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
324
|
+
return [
|
|
325
|
+
(0, transformToNDJson_1.transformToNDJson)(),
|
|
326
|
+
outputPath.endsWith('.gz')
|
|
327
|
+
? (0, node_zlib_1.createGzip)({
|
|
328
|
+
// chunkSize: 64 * 1024, // no observed speedup
|
|
329
|
+
})
|
|
330
|
+
: undefined,
|
|
331
|
+
node_fs_1.default.createWriteStream(outputPath, {
|
|
332
|
+
// highWaterMark: 64 * 1024, // no observed speedup
|
|
333
|
+
}),
|
|
334
|
+
].filter(js_lib_1._isTruthy);
|
|
334
335
|
}
|
|
335
336
|
}
|
|
336
337
|
exports.fs2 = new FS2();
|
|
@@ -26,7 +26,7 @@ async function ndjsonMap(mapper, opt) {
|
|
|
26
26
|
}),
|
|
27
27
|
(0, __1.transformLimit)({ limit: limitOutput, sourceReadable: readable }),
|
|
28
28
|
(0, __1.transformLogProgress)({ metric: 'saved', logEvery: logEveryOutput }),
|
|
29
|
-
__1.fs2.createWriteStreamAsNDJSON(outputFilePath),
|
|
29
|
+
...__1.fs2.createWriteStreamAsNDJSON(outputFilePath),
|
|
30
30
|
]);
|
|
31
31
|
}
|
|
32
32
|
exports.ndjsonMap = ndjsonMap;
|
package/package.json
CHANGED
package/src/fs/fs2.ts
CHANGED
|
@@ -19,10 +19,10 @@ import fs from 'node:fs'
|
|
|
19
19
|
import fsp from 'node:fs/promises'
|
|
20
20
|
import path from 'node:path'
|
|
21
21
|
import { createGzip, createUnzip } from 'node:zlib'
|
|
22
|
-
import { _jsonParse } from '@naturalcycles/js-lib'
|
|
22
|
+
import { _isTruthy, _jsonParse } from '@naturalcycles/js-lib'
|
|
23
23
|
import yaml, { DumpOptions } from 'js-yaml'
|
|
24
24
|
import { transformToNDJson } from '../stream/ndjson/transformToNDJson'
|
|
25
|
-
import { ReadableTyped,
|
|
25
|
+
import { ReadableTyped, TransformTyped } from '../stream/stream.model'
|
|
26
26
|
import { transformSplitOnNewline } from '../stream/transform/transformSplit'
|
|
27
27
|
import { requireFileToExist } from '../util/env.util'
|
|
28
28
|
|
|
@@ -353,31 +353,28 @@ class FS2 {
|
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
/*
|
|
356
|
-
Returns
|
|
356
|
+
Returns an array of Transforms, so that you can ...destructure them at
|
|
357
|
+
the end of the _pipeline.
|
|
357
358
|
|
|
358
359
|
Replaces a list of operations:
|
|
359
360
|
- transformToNDJson
|
|
360
361
|
- createGzip (only if path ends with '.gz')
|
|
361
362
|
- fs.createWriteStream
|
|
362
363
|
*/
|
|
363
|
-
createWriteStreamAsNDJSON(outputPath: string):
|
|
364
|
+
createWriteStreamAsNDJSON(outputPath: string): TransformTyped<any, any>[] {
|
|
364
365
|
this.ensureFile(outputPath)
|
|
365
366
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
)
|
|
374
|
-
}
|
|
375
|
-
transform.pipe(
|
|
367
|
+
return [
|
|
368
|
+
transformToNDJson(),
|
|
369
|
+
outputPath.endsWith('.gz')
|
|
370
|
+
? createGzip({
|
|
371
|
+
// chunkSize: 64 * 1024, // no observed speedup
|
|
372
|
+
})
|
|
373
|
+
: undefined,
|
|
376
374
|
fs.createWriteStream(outputPath, {
|
|
377
375
|
// highWaterMark: 64 * 1024, // no observed speedup
|
|
378
376
|
}),
|
|
379
|
-
)
|
|
380
|
-
return transform1
|
|
377
|
+
].filter(_isTruthy) as TransformTyped<any, any>[]
|
|
381
378
|
}
|
|
382
379
|
}
|
|
383
380
|
|
|
@@ -60,6 +60,6 @@ export async function ndjsonMap<IN = any, OUT = any>(
|
|
|
60
60
|
}),
|
|
61
61
|
transformLimit({ limit: limitOutput, sourceReadable: readable }),
|
|
62
62
|
transformLogProgress({ metric: 'saved', logEvery: logEveryOutput }),
|
|
63
|
-
fs2.createWriteStreamAsNDJSON(outputFilePath),
|
|
63
|
+
...fs2.createWriteStreamAsNDJSON(outputFilePath),
|
|
64
64
|
])
|
|
65
65
|
}
|