@engine9-io/input-tools 1.7.0 → 1.7.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/ForEachEntry.js +21 -9
- package/file/FileUtilities.js +3 -3
- package/package.json +1 -1
- package/test/packet/forEach.js +2 -2
package/ForEachEntry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require('node:fs');
|
|
2
2
|
|
|
3
|
-
const { Writable } = require('node:stream');
|
|
3
|
+
const { Transform, Writable } = require('node:stream');
|
|
4
4
|
const { pipeline } = require('node:stream/promises');
|
|
5
5
|
const { throttle } = require('throttle-debounce');
|
|
6
6
|
const parallelTransform = require('parallel-transform');
|
|
@@ -35,15 +35,19 @@ class ForEachEntry {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
return this.outputStreams[name].mutex.runExclusive(async () => {
|
|
38
|
-
const
|
|
39
|
-
|
|
38
|
+
const fileInfo = {
|
|
39
|
+
filename: await getTempFilename({ postfix }),
|
|
40
|
+
records: 0,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
debug(`Output file requested, writing output to to: ${fileInfo.filename}`);
|
|
40
44
|
const outputStream = new ValidatingReadable({
|
|
41
45
|
objectMode: true,
|
|
42
46
|
}, validatorFunction);
|
|
43
47
|
// eslint-disable-next-line no-underscore-dangle
|
|
44
48
|
outputStream._read = () => {};
|
|
45
49
|
|
|
46
|
-
const writeStream = fs.createWriteStream(
|
|
50
|
+
const writeStream = fs.createWriteStream(fileInfo.filename);
|
|
47
51
|
const finishWritingOutputPromise = new Promise((resolve, reject) => {
|
|
48
52
|
writeStream.on('finish', () => {
|
|
49
53
|
resolve();
|
|
@@ -52,15 +56,23 @@ class ForEachEntry {
|
|
|
52
56
|
});
|
|
53
57
|
});
|
|
54
58
|
|
|
55
|
-
outputStream
|
|
56
|
-
.pipe(csv.stringify({ header: true }))
|
|
57
|
-
.pipe(writeStream);
|
|
58
|
-
|
|
59
59
|
this.outputStreams[name].items = {
|
|
60
60
|
stream: outputStream,
|
|
61
61
|
promises: [finishWritingOutputPromise],
|
|
62
|
-
files: [
|
|
62
|
+
files: [fileInfo],
|
|
63
63
|
};
|
|
64
|
+
|
|
65
|
+
outputStream
|
|
66
|
+
.pipe(new Transform({
|
|
67
|
+
objectMode: true,
|
|
68
|
+
transform(o, enc, cb) {
|
|
69
|
+
fileInfo.records += 1;
|
|
70
|
+
cb();
|
|
71
|
+
},
|
|
72
|
+
}))
|
|
73
|
+
.pipe(csv.stringify({ header: true }))
|
|
74
|
+
.pipe(writeStream);
|
|
75
|
+
|
|
64
76
|
return this.outputStreams[name].items;
|
|
65
77
|
});
|
|
66
78
|
}
|
package/file/FileUtilities.js
CHANGED
|
@@ -190,7 +190,6 @@ Worker.prototype.fileToObjectStream = async function (options) {
|
|
|
190
190
|
|
|
191
191
|
debug(`Reading file ${filename} with encoding:`, encoding);
|
|
192
192
|
|
|
193
|
-
const head = null;
|
|
194
193
|
let transforms = [];
|
|
195
194
|
|
|
196
195
|
if (postfix === 'gz') {
|
|
@@ -270,13 +269,14 @@ Worker.prototype.fileToObjectStream = async function (options) {
|
|
|
270
269
|
},
|
|
271
270
|
flush(cb) {
|
|
272
271
|
// If there's no records at all, push a dummy record, and specify 0 records
|
|
272
|
+
// Don't push dummy records anymore -- legacy cruft
|
|
273
273
|
debug(`Completed reading file, records=${count}`);
|
|
274
|
-
if (count === 0) {
|
|
274
|
+
/* if (count === 0) {
|
|
275
275
|
const o = { _is_placeholder: true };
|
|
276
276
|
|
|
277
277
|
if (head) head.forEach((c) => { o[c] = null; });
|
|
278
278
|
this.push(o);
|
|
279
|
-
}
|
|
279
|
+
} */
|
|
280
280
|
cb();
|
|
281
281
|
},
|
|
282
282
|
});
|
package/package.json
CHANGED
package/test/packet/forEach.js
CHANGED
|
@@ -55,8 +55,8 @@ describe('Test Person Packet For Each', async () => {
|
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
);
|
|
58
|
-
assert(result.outputFiles?.timelineOutputFileStream?.
|
|
59
|
-
assert(result.outputFiles?.sampleOutputFileStream?.
|
|
58
|
+
assert(result.outputFiles?.timelineOutputFileStream?.[0]?.records);
|
|
59
|
+
assert(result.outputFiles?.sampleOutputFileStream?.[0]?.records);
|
|
60
60
|
assert.equal(counter, 1000, `Expected to loop through 1000 people, actual:${counter}`);
|
|
61
61
|
});
|
|
62
62
|
debug('Completed tests');
|