New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

csv-streamify

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-streamify

Streaming CSV Parser. Made entirely out of streams.

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33K
increased by15.28%
Maintainers
1
Weekly downloads
 
Created
Source

csv-streamify

Parses csv files. Accepts options. Handles weird encodings. No coffee script, no weird APIs. Just streams.

Installation

npm install csv-streamify

Usage

This module implements a simple node 0.10.x stream.Transform stream.

Note: If you're still running node 0.8.x, you have to do npm install readable-stream

var csv = require('csv-streamify'),
    fs = require('fs')

var fstream = fs.createReadStream('/path/to/file'),
    parser = csv(options /* optional */, callback /* optional */)

// emits each row as a JSON.stringified array of fields
parser.on('readable', function () {
  var line = parser.read()
  // do stuff with data as it comes in
  // Array.isArray(JSON.parse(line)) === true

  // current line number
  console.log(parser.lineNo)
})

// AND/OR
function callback(err, doc) {
  if (err) throw err

  // doc is an array of row arrays
  doc.forEach(function (row) {})
}

// now pump some data into it (and pipe it somewhere else)
fstream.pipe(parser).pipe(nirvana)

Note: If you pass a callback to csv-stream it will buffer the parsed data for you and pass it to the callback when it's done.

Options

You can pass some options to the parser. All of them are optional. Here are the defaults.

{
  delimiter: ',', // comma, semicolon, whatever
  newline: '\n', // newline character
  quote: '\"', // what's considered a quote
  empty: '', // empty fields are replaced by this,
  encoding: '', // the encoding of the source, in case you need to convert it
  objectMode: false // emit arrays instead of stringified arrays
}

In order for the encoding option to take effect you need to install the excellent node-iconv by node core contributor @bnoordhuis Also, take a look at the node-iconv documentation for supported encodings.

TODO

  • more tests

Contributors

Nicolas Hery (objectMode)

Keywords

FAQs

Package last updated on 03 Jul 2013

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc