Socket
Socket
Sign inDemoInstall

csvstream

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    csvstream

csv streaming parser


Version published
Weekly downloads
7
decreased by-53.33%
Maintainers
1
Install size
6.19 kB
Created
Weekly downloads
 

Readme

Source

csv stream

Build Status

csv streaming parser to JSON.

Install

npm install csvstream

Sample

var csvstream = require('csvstream');
var fs = require('fs');

var rs = fs.createReadStream('./test/test1.csv');
var ws_head = fs.createWriteStream('./test/output2.json');

var csvs = new csvstream({header: true}, function(err, result) {
  if(err)
    console.error(err);

  console.log(result);
  //  [ 
  //    { aaa: '1', bbb: '2', ccc: '3' },
  //    { aaa: '4', bbb: '5', ccc: '6' },
  //    { aaa: '7', bbb: '8', ccc: '9' } 
  //  ])
});

rs.pipe(csvs).pipe(ws_head);

Options (csvstream(options))

Options are optional.

  • encoding: default to utf8
  • delimiter: default to ,
  • newlint: default to \n
  • quote: default to \"
  • header: default to false
Example

Raw data

"aaa","bbb","ccc"
1, 2, 3
4, 5, 6
7, 8, 9

header equals false you get:

[
["aaa","bb\"\"b","ccc"]
,["1","2","3"]
,["4","5","6"]
,["7","8","9"]
]

header equals true you get:

[
{"aaa":"1","bbb":"2","ccc":"3"}
,{"aaa":"4","bbb":"5","ccc":"6"}
,{"aaa":"7","bbb":"8","ccc":"9"}
]

Best practice

Lint your csv files https://github.com/chilijung/csvlint.js before parsing :)

Example
var csvstream = require('../csvstream');
var csvlint = require('csvlint');
var fs = require('fs');

var rs = fs.createReadStream('./benchmark/100000.csv');
var ws = fs.createWriteStream('./benchmark/output2.json');
var csvlint = csvlint();
var csvs = csvstream({header: true});

csvlint.on('finish', function() {
    console.log('csv lint is end');
})

csvs.on('finish', function() {
    console.log('csv stream is end')
})

rs.pipe(csvlint).pipe(csvs).pipe(ws);

Tests

npm test

Inspired by

https://github.com/klaemo/csv-stream

License

MIT

Keywords

FAQs

Last updated on 12 Aug 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc