Skip to content

Instantly share code, notes, and snippets.

Created September 20, 2015 10:52
Show Gist options
  • Save anonymous/ea8c550d45f09ba07c0a to your computer and use it in GitHub Desktop.
Save anonymous/ea8c550d45f09ba07c0a to your computer and use it in GitHub Desktop.
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