forked from plaid/deprecated-async-problem
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kgo.js
41 lines (32 loc) · 1.05 KB
/
kgo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const fs = require('fs');
const path = require('path');
const foreign = require('foreign');
const kgo = require('kgo');
const R = require('ramda');
const S = require('sanctuary');
// join :: String -> String -> String
const join = R.curryN(2, path.join);
// data Text = Buffer | String
// readFile ::
// String -> String -> ((Error?, Text?) -> Undefined) -> Undefined
const readFile = R.curry((encoding, filename, callback) => {
fs.readFile(filename, {encoding: encoding}, callback);
});
const main = () => {
const dir = process.argv[2];
kgo
('index', readFile('utf8', join(dir, 'index.txt')))
('filePaths', ['index'], kgo.sync(S.compose(R.map(join(dir)), S.lines)))
('files', ['filePaths'], R.partial(foreign.parallel, [readFile('utf8')]))
('concated', ['files'], kgo.sync(R.join('')))
(['concated'], data => {
process.stdout.write(data);
process.exit(0);
})
(['*'], err => {
process.stderr.write(String(err) + '\n');
process.exit(1);
});
};
if (process.mainModule.filename === __filename) main();