Created
May 16, 2014 08:31
-
-
Save 1N50MN14/0001e454688e0d985bac to your computer and use it in GitHub Desktop.
multipelx id as meta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var concat = require('concat-stream') | |
var plex1 = require('multiplex') | |
var meta = {id:'mystream', collect:true} | |
var s = plex1.createStream(JSON.stringify(meta)) | |
var plex2 = multiplex(function onStream(stream, meta) { | |
var m = JSON.parse(stream.meta) | |
if (m.collect) return stream.pipe(collect(m)) | |
// do something else | |
}) | |
plex1.pipe(plex2) | |
fs.createReadStream('file.ext').pipe(s) | |
function collect(meta) { | |
return concat(function(data) { | |
self.emit('data', meta, data) | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment