我的理解是它们都创建了可写的流,但我不确定如果你只是像下面的例子那样去格式化数据,解析数据的意义是什么。
fs.createReadStream(path.resolve(__dirname, 'assets', 'snake_case_users.csv'))
.pipe(csv.parse({ headers: true }))
.pipe(csv.format({ headers: true }))
.transform((row, next) => {
User.findById(row.id, (err, user) => {
if (err) {
return next(err);
}
return next(null, {
id: row.id,
firstName: row.first_name,
lastName: row.last_name,
address: row.address,
// properties from user
isVerified: user.isVerified,
hasLoggedIn: user.hasLoggedIn,
age: user.age,
});
});
})
.pipe(process.stdout)
.on('end', () => process.exit());