forked from slavaGanzin/async-problem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynchronous.js
More file actions
29 lines (24 loc) · 690 Bytes
/
synchronous.js
File metadata and controls
29 lines (24 loc) · 690 Bytes
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
'use strict';
const fs = require('fs');
const path = require('path');
const S = require('sanctuary');
const main = () => {
const dir = process.argv[2];
let index;
try {
index = fs.readFileSync(path.join(dir, 'index.txt'), {encoding: 'utf8'});
} catch (err) {
process.stderr.write(String(err) + '\n');
process.exit(1);
}
const readFile = filename => {
try {
return fs.readFileSync(path.join(dir, filename), {encoding: 'utf8'});
} catch (err) {
process.stderr.write(String(err) + '\n');
process.exit(1);
}
};
process.stdout.write(S.lines(index).map(readFile).join(''));
};
if (process.mainModule.filename === __filename) main();