Wrapper for concat-stream to make a transform
npm install sink-transformA wrapper for [concat-stream] to make a transform to process the concated result.
``javascript
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}
]
example/concat.js:
`javascript
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:
`javascript`
console.log('a')
output:
``
ā node example/concat.js
console.log('a')
`javascript`
var sink = require('sink-transform')
var stream = sink(opts, trs)
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.
$3
Same with sink({ encoding: 'string' }, transformFn)`[concat-stream]: https://www.npmjs.com/package/concat-stream