Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use transform #577

Open
mingxin-yang opened this issue Oct 26, 2022 · 0 comments
Open

how to use transform #577

mingxin-yang opened this issue Oct 26, 2022 · 0 comments

Comments

@mingxin-yang
Copy link

mingxin-yang commented Oct 26, 2022

I want to modify a csv file, add a status column, and add the corresponding data, but I can't use the following code, how can I modify it? went on

let path = __dirname + '/emails/' + value.filename + '.csv';

            const fields = ['email', 'fullname', 'status'];
            const opts = { fields, transform:[function (buf, enc, next) {
              return {
                ...buf,
                  email:job1.data.email,
                  fullname:job1.data.fullname,
                  status:value.status 
              }
            }]};
            const transformOpts = {objectMode: true};
            const json2csv = new Transform(opts, transformOpts);
            const input = fs.createReadStream(path, { encoding: 'utf8' });
            const output = fs.createWriteStream(path, { encoding: 'utf8' });

            const processor = input.pipe(json2csv).pipe(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant