Permalink
Browse files

problem statement for the stream combiner adventure

  • Loading branch information...
1 parent 0d3801a commit 0bc08ae01903a29ebeeab05310b5c3ad3710eb63 @substack substack committed Dec 17, 2013
Showing with 51 additions and 0 deletions.
  1. +1 −0 data/order.json
  2. +50 −0 problems/combiner/problem.txt
View
@@ -11,6 +11,7 @@
"HTML STREAM",
"DUPLEXER",
"DUPLEXER REDUX",
+ "COMBINER",
"CRYPT",
"SECRETZ"
]
@@ -1 +1,51 @@
+Write a module that returns a readable/writable stream using the
+`stream-combiner` module. You can use this code to start with:
+ var combine = require('stream-combiner')
+
+ module.exports = function () {
+ return combine(
+ // read newline-separated json,
+ // group books into genres,
+ // then gzip the output
+ )
+ }
+
+Your stream will be written a newline-separated JSON list of science fiction
+genres and books. All the books after a `"type":"genre"` row belong in that
+genre until the next `"type":"genre"` comes along in the output.
+
+ {"type":"genre","name":"cyberpunk"}
+ {"type":"book","name":"Neuromancer"}
+ {"type":"book","name":"Snow Crash"}
+ {"type":"genre","name":"space opera"}
+ {"type":"book","name":"A Deepness in the Sky"}
+ {"type":"book","name":"Void"}
+
+Your program should generate a newline-separated list of JSON lines of genres,
+each with a `"books"` array containing all the books in that genre. The input
+above would yield the output:
+
+ {"name":"cyberpunk","books":["Neuromancer","Snow Crash"]}
+ {"name":"space opera","books":["A Deepness in the SKy","Void"]}
+
+Your stream should take this list of JSON lines and gzip it with
+`crypto.createGzip()`.
@substack

substack Dec 19, 2013

Collaborator

Thanks! Fixed.

@bulkan

bulkan Dec 19, 2013

👍 Thanks for that.

+
+* HINTS *
+
+The `stream-combiner` module creates a pipeline from a list of streams,
+returning a single stream that exposes the first stream as the writable side and
+the last stream as the readable side like the `duplexer` module, but with an
+arbitrary number of streams in between. Unlike the `duplexer` module, each
+stream is piped to the next. For example:
+
+ var combine = require('stream-combiner');
+ var stream = combine(a, b, c, d);
+
+will internally do `a.pipe(b).pipe(c).pipe(d)` but the `stream` returned by
+`combine()` has its writable side hooked into `a` and its readable side hooked
+into `d`.
+
+As in the previous LINES adventure, the `split` module is very handy here. You
+can put a split stream directly into the stream-combiner pipeline.

0 comments on commit 0bc08ae

Please sign in to comment.