Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bhurlow
Created December 19, 2012 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhurlow/4338594 to your computer and use it in GitHub Desktop.
Save bhurlow/4338594 to your computer and use it in GitHub Desktop.
line by line stream readers from npm, a case study

Stream, npm, cli utilities all awesome. But some tools get repeated waaayyy too much. For example, node line-by-line stream utilities are everywhere. But they can't be created equal can they? What's the criteria for this tool? In my mind, a great line by line stream tool should:

  1. follow the node.js stream api as closely as possible
  2. Use the new stream2 api if possible and remain backwards compatible
  3. perform well (there can be a pretty significant performance difference between different parsing methods)
  4. be very well documented and tested
  1. interface

looks like the most noteworthy difference between the interfaces of is the use of events. some of these interfaces go like this:

var line_tool = require('line tool')

fs.createReadStream('thing.txt')
  .pipe(line_tool)

line_tool.on('line', function(line) {
  // do stuff with line
})
  1. backwards compatibility

........

  1. performance

how do you benchmark streams?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment