[Pkg-javascript-commits] [node-stream-splicer] 24/71: example not quite working yet

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:55:49 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stream-splicer.

commit a3cfb6b611f09768d167fbc618261adc8f80ba58
Author: James Halliday <mail at substack.net>
Date:   Sun Jun 8 23:20:10 2014 -0700

    example not quite working yet
---
 example/header.js | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/example/header.js b/example/header.js
index c32946d..b06c55e 100644
--- a/example/header.js
+++ b/example/header.js
@@ -1,15 +1,27 @@
 var pipeline = require('../');
 var through = require('through2');
-var stringify = require('JSONStream').stringify;
+var JSONStream = require('JSONStream');
 var split = require('split');
 
-var a = split();
-var b = through.obj(function (row, enc, next) {
-    this.push(JSON.parse(row));
+var headerData = {};
+var headers = through.obj(function (buf, enc, next) {
+    var line = buf.toString('utf8');
+    
+    if (line === '') { // break on \n\n
+        this.push(headerData);
+        
+        // replace header parsing with json row parsing
+        outer.splice(0, 2, JSONStream.parse([ true ]));
+    }
+    else {
+        var m = /^(\S+):(.+)/.exec(line);
+        var key = m && m[1].trim();
+        var value = m && m[2].trim();
+        if (m) headerData[key] = value;
+    }
+    
     next();
 });
-var c = through.obj(function (row, enc, next) { this.push(row.x); next() });
-var d = through.obj(function (x, enc, next) { this.push(x * 111); next() });
-var e = stringify();
 
-pipeline([ process.stdin, a, b, c, d, e, process.stdout ]);
+var outer = pipeline([ split(), headers, JSONStream.stringify() ]);
+process.stdin.pipe(outer).pipe(process.stdout);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-splicer.git



More information about the Pkg-javascript-commits mailing list