使用Node-CSV乘以和跳过行通过管道传输流的方法如下:
npm install csv
csv
模块和fs
模块:const csv = require('csv');
const fs = require('fs');
const readStream = fs.createReadStream('path/to/input.csv');
const writeStream = fs.createWriteStream('path/to/output.csv');
const parser = csv.parse();
parser.on('skip', (count) => {
if (count < 3) {
parser.resume();
}
});
parser.on('data', (row) => {
row[1] *= 2;
parser.pause();
parser.emit('record', row);
});
parser.pipe(writeStream);
readStream.pipe(parser);
完整的代码示例如下:
const csv = require('csv');
const fs = require('fs');
const readStream = fs.createReadStream('path/to/input.csv');
const writeStream = fs.createWriteStream('path/to/output.csv');
const parser = csv.parse();
parser.on('skip', (count) => {
if (count < 3) {
parser.resume();
}
});
parser.on('data', (row) => {
row[1] *= 2;
parser.pause();
parser.emit('record', row);
});
parser.pipe(writeStream);
readStream.pipe(parser);
这样就实现了使用Node-CSV乘以和跳过行通过管道传输流的功能。你可以根据实际需求进行修改和扩展。
领取专属 10元无门槛券
手把手带您无忧上云