Created
September 20, 2015 10:52
-
-
Save anonymous/ea8c550d45f09ba07c0a 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
import fs from 'fs' | |
import { join } from 'path'; | |
import Promise, { coroutine, all } from 'bluebird'; | |
const joinPath = init => tail => join(init, tail); | |
const readFileP = Promise.promisify(fs.readFile); | |
const readUtf8P = (file) => readFileP(file, { encoding: 'utf8' }); | |
const pipe = (f, g) => x => g(f(x)); | |
const concatFiles = coroutine(function* (dir) { | |
const readInDir = pipe(joinPath(dir), readUtf8P); | |
const index = yield readInDir('index.txt'); | |
const results = yield all(index.match(/^.*(?=\n)/gm).map(readInDir)); | |
return results.join(''); | |
}); | |
const main = process => concatFiles(process.argv[2]) | |
.then(s => process.stdout.write(s)); | |
main(process); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment