sink-transform
Wrapper for concat-stream to make a transform
Last updated 5 years ago by zoubin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sink-transform 
SYNC missed versions from official npm registry.

sink-transform

version status coverage dependencies devDependencies

A wrapper for concat-stream to make a transform to process the concated result.

Examples

Concat objects

example/reverse.js:

var sink = require('sink-transform')
var JSONStream = require('JSONStream')

var stream = sink.obj(function (rows, done) {
  for (var i = rows.length - 1; i >= 0; --i) {
    this.push(rows[i])
  }
  done()
})

stream.pipe(JSONStream.stringify()).pipe(process.stdout)

stream.write({ x:1 })
stream.write({ y:2 })
stream.write({ z:3 })
stream.end()

output:

⌘ node example/reverse.js
[
{"z":3}
,
{"y":2}
,
{"x":1}
]

Concat strings

example/concat.js:

var sink = require('sink-transform')
var fs = require('fs')

fs.createReadStream(__dirname + '/files/a.js')
  .pipe(sink.str(function (body, done) {
    console.log(body)
    done()
  }))

a.js:

console.log('a')

output:

⌘ node example/concat.js
console.log('a')

Usage

var sink = require('sink-transform')
var stream = sink(opts, trs)

stream = sink(opts={}, transformFn)

opts

Type: Object

Directly passsed to concat-stream as the first argument.

transformFn

Type: Function

Signature: (concated, done) => {}

Receives the concated result of concat-stream, and a callback to mark the end of the transform operation.

stream = sink.obj(transformFn)

Same with sink({ encoding: 'object' }, transformFn)

stream = sink.str(transformFn)

Same with sink({ encoding: 'string' }, transformFn)

Current Tags

  • 2.0.0                                ...           latest (5 years ago)

7 Versions

  • 2.0.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 5
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (4)

Copyright 2014 - 2017 © taobao.org |