Forked from LewisJEllis/gist:1ac2e10e9309b3f59017
Last active
August 29, 2015 14:13
-
-
Save eiriklv/1c3e6a6534fd6fb499a2 to your computer and use it in GitHub Desktop.
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 express = require('express'); | |
| var _ = require('highland'); | |
| var fs = require('fs'); | |
| var app = express(); | |
| function chain(s, f) { | |
| return s.flatMap(_.wrapCallback(f)) | |
| } | |
| app.post('/process-file', function(req, res) { | |
| var inputFile = 'input.txt'; | |
| var outputFile = 'output.txt'; | |
| var data = _([inputFile]); | |
| _([ | |
| fs.readFile, | |
| process1, | |
| process2, | |
| process3, | |
| writeToFileName(outputFile) | |
| ]).reduce(data, chain).flatten() | |
| .stopOnError(function (err) { | |
| return res.status(500).send(err); | |
| }).apply(function (data) { | |
| return res.status(200).send('processed'); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment