Created
June 1, 2015 10:03
-
-
Save gido/2995cfbee73ab9789cca to your computer and use it in GitHub Desktop.
Playing with Stream and Nodejs
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 request = require("request"); | |
var zlib = require("zlib"); | |
var csv = require("csv-streamify"); | |
var Handlebars = require("handlebars"); | |
var es = require("event-stream"); | |
var tmpl = Handlebars.compile("<li><a href="{{URL}}">{{Name}}</a> ({{City}})</li>"); | |
// HTTP GET Request | |
request("http://nodestreams.com/input/people.csv.gz") | |
// Un-Gzip | |
.pipe(zlib.createGunzip()) | |
// Parse CSV as Object | |
.pipe(csv({objectMode: true, columns: true})) | |
// Convert Object w/ Handlebars | |
.pipe(es.mapSync(tmpl)) | |
// Join Strings | |
.pipe(es.join("\n")) | |
// Concat Strings | |
.pipe(es.wait()) | |
// Wrap Strings | |
.pipe(es.mapSync(function(data) { return "<ul>" + data + "\n</ul>"; })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment