Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/binocarlos/group-cascade-stream
A cascade stream that groups created streams by a chunk id
https://github.com/binocarlos/group-cascade-stream
Last synced: 10 days ago
JSON representation
A cascade stream that groups created streams by a chunk id
- Host: GitHub
- URL: https://github.com/binocarlos/group-cascade-stream
- Owner: binocarlos
- License: mit
- Created: 2014-04-21T16:59:46.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-04-22T14:47:46.000Z (over 10 years ago)
- Last Synced: 2024-10-31T19:00:11.804Z (19 days ago)
- Language: JavaScript
- Size: 172 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
group-cascade-stream
====================[![NPM](https://nodei.co/npm/group-cascade-stream.png?global=true)](https://nodei.co/npm/group-cascade-stream/)
[![Travis](http://img.shields.io/travis/binocarlos/group-cascade-stream.svg?style=flat)](https://travis-ci.org/binocarlos/group-cascade-stream)
A cascade stream that groups created streams by a chunk id
## example
```js
var from = require('from2-array')
var through = require('through2')
var cascade = require('group-cascade-stream')var coeffs = {
a:2,
b:5,
c:10
}// create a stream for a single letter
function createLetterStream(letter){
var coeff = coeffs[letter]
return through.obj(function(chunk, enc, cb){
var num = parseFloat(chunk.replace(/\D/g, ''))
this.push(num * coeff)
cb()
})
}var source = from.obj(['a1', 'b3', 'a4', 'c3', 'c8', 'b5'])
var splitter = cascade(function(chunk){
// return just 'a' for the id
return chunk.toString().charAt(0)
}, function(id){
return createLetterStream(id)
})var sink = through.obj(function(chunk, enc, cb){
console.log(chunk);
cb()
})source.pipe(splitter).pipe(sink)
/*
2 (a1 -> 1 * 2)
15 (b3 -> 3 * 5)
8 (a4 -> 4 * 2)
30 (c3 -> 3 * 10)
80 (c8 -> 8 * 10)
25 (b5 -> 5 * 5)*/
```## license
MIT