block by joyrexus 11153491

through2-map examples

A quick demo of through2-map usage.

Extract second column of each row in a CSV file

fs = require 'fs'
csv = require 'csv2'
map = require 'through2-map'

extract = map(objectMode: true, (row) -> row[1] + '\n')

fs.createReadStream('data.csv')
  .pipe(csv())
  .pipe(extract)
  .pipe(process.stdout)   # B, b1, b2, b3

Uppercase strings

{Readable} = require 'stream'

# a simple transform stream
tx = map((d) -> d.toString().toUpperCase())

# a simple source stream
rs = new Readable
rs.push 'the quick brown fox jumps over the lazy dog!\n'
rs.push null 

rs.pipe(tx)
  .pipe(process.stdout)   # THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG!

data.csv

index.coffee.md

package.json