-
-
Save jbenet/caa07c196f78cf30c748 to your computer and use it in GitHub Desktop.
This file contains 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 noop = function() {} | |
var jsonpath = require('jsonpath-rep') | |
var duplexer2 = require('duplexer2.jbenet') | |
function processJsonpathStream(path, otherStream) { | |
var queue = [] | |
var spliter = through2.obj(split) | |
var joiner = through2.obj(join) | |
spliter.pipe(otherStream).pipe(joiner) | |
return duplexer2(spliter, joiner) | |
function split(item, enc, next) { | |
queue.unshift(item) | |
var val = jsonpath.eval(item, path) | |
this.push(val) | |
next() | |
} | |
function join(item, enc, nect) { | |
var orig = queue.pop() | |
var replaced = jsonpath.eval(orig, path, undefined, item) | |
this.push(replaced) | |
next() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using https://github.com/mafintosh/write-transform-read
use it like so