Skip to content

Commit 53eabda

Browse files
Igor Drobiazkojhorbulyk
Igor Drobiazko
authored andcommitted
Supporting startRow option
1 parent 769b60f commit 53eabda

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/actions/write.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,25 @@ function init(cfg) {
4545
function processAction(msg, cfg) {
4646
const self = this;
4747

48+
const startRow = cfg.reader.startRow || 0;
49+
50+
if (startRow !== 0 && rowCount === 0) {
51+
console.log('Skipping the first %s rows', startRow + 1);
52+
}
53+
4854
if (timeout) {
4955
clearTimeout(timeout);
5056
}
5157

5258
timeout = setTimeout(()=> {
5359
console.log('Closing the stream due to inactivity');
5460
co(function* gen() {
55-
console.log('The resulting CSV file contains %s rows', rowCount);
61+
const finalRowCount = rowCount - startRow;
62+
console.log('The resulting CSV file contains %s rows', finalRowCount);
5663
stringifier.end();
5764

5865
const messageToEmit = messages.newMessageWithBody({
59-
rowCount
66+
rowCount: finalRowCount
6067
});
6168
const fileName = messageToEmit.id + '.csv';
6269
messageToEmit.attachments[fileName] = {
@@ -73,12 +80,14 @@ function processAction(msg, cfg) {
7380
});
7481
}, 10000);
7582

76-
let row = msg.body;
77-
if( cfg.reader.columns) {
78-
const columns = Object.keys(_.keyBy(cfg.reader.columns, 'property'));
79-
row = _.pick(msg.body, columns);
83+
if (startRow <= rowCount) {
84+
let row = msg.body;
85+
if( cfg.reader.columns) {
86+
const columns = Object.keys(_.keyBy(cfg.reader.columns, 'property'));
87+
row = _.pick(msg.body, columns);
88+
}
89+
stringifier.write(row);
8090
}
81-
stringifier.write(row);
8291
rowCount++;
8392
this.emit('end');
8493
}

0 commit comments

Comments
 (0)