Skip to content

Commit

Permalink
feat: Pass transform options through (#262)
Browse files Browse the repository at this point in the history
* Pass transform options through

* Update readme
  • Loading branch information
juanjoDiaz authored and knownasilya committed Feb 27, 2018
1 parent e7f943c commit 650913f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ const Json2csvTransform = require('json2csv').Transform;

const fields = ['field1', 'field2', 'field3'];
const opts = { fields };
const transformOpts = { highWaterMark: 16384, encoding: 'utf-8' };

const input = fs.createReadStream(inputPath, { encoding: 'utf8' });
const output = fs.createWriteStream(outputPath, { encoding: 'utf8' });
const json2csv = new Json2csvTransform(opts);
const json2csv = new Json2csvTransform(opts, transformOpts);

const processor = input.pipe(json2csv).pipe(output);

Expand Down
4 changes: 2 additions & 2 deletions lib/JSON2CSVTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const Parser = require('jsonparse');
const JSON2CSVBase = require('./JSON2CSVBase');

class JSON2CSVTransform extends Transform {
constructor(opts) {
super(opts);
constructor(opts, transformOpts) {
super(transformOpts);

// Inherit methods from JSON2CSVBase since extends doesn't
// allow multiple inheritance and manually preprocess opts
Expand Down

0 comments on commit 650913f

Please sign in to comment.