Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoubin/sink-transform
Wrapper for concat-stream to make a transform
https://github.com/zoubin/sink-transform
Last synced: 8 days ago
JSON representation
Wrapper for concat-stream to make a transform
- Host: GitHub
- URL: https://github.com/zoubin/sink-transform
- Owner: zoubin
- Created: 2015-06-10T10:23:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-18T07:49:42.000Z (over 8 years ago)
- Last Synced: 2024-10-13T14:14:56.858Z (about 1 month ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
Awesome Lists containing this project
README
# sink-transform
[![version](https://img.shields.io/npm/v/sink-transform.svg)](https://www.npmjs.org/package/sink-transform)
[![status](https://travis-ci.org/zoubin/sink-transform.svg)](https://travis-ci.org/zoubin/sink-transform)
[![coverage](https://img.shields.io/coveralls/zoubin/sink-transform.svg)](https://coveralls.io/github/zoubin/sink-transform)
[![dependencies](https://david-dm.org/zoubin/sink-transform.svg)](https://david-dm.org/zoubin/sink-transform)
[![devDependencies](https://david-dm.org/zoubin/sink-transform/dev-status.svg)](https://david-dm.org/zoubin/sink-transform#info=devDependencies)A wrapper for [concat-stream] to make a transform to process the concated result.
## Examples
### Concat objects
example/reverse.js:```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}
]
```### Concat strings
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')
```## Usage
```javascript
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)`[concat-stream]: https://www.npmjs.com/package/concat-stream