-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (43 loc) · 1.14 KB
/
Copy pathindex.js
File metadata and controls
51 lines (43 loc) · 1.14 KB
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
42
43
44
45
46
47
48
49
50
51
const rdfParser = require("./lib/rdf-parser");
const nodeDir = require("node-dir");
const appConfig = require("./config/app-config");
const path = require("path");
const savedBooks = [];
async function onEachFile(err, data, next) {
if (err) {
console.log("ERROR reading file: ", err);
throw err;
}
try {
const book = await rdfParser.parseFile(data);
savedBooks.push(book);
next();
} catch(e) {
console.log("ERROR parsing file", e);
throw e;
}
}
function onFinish(cb) {
return (err, files) => {
if (err) {
console.log("ERROR on finish: ", err);
throw err;
}
console.log(`Finished parsing ${files.length} files`);
if (savedBooks.length === files.length) {
console.log("All the files were processed!")
} else {
console.log("Some files were not processed correctly!")
}
cb();
}
}
module.exports = function _parseFiles_(cb) {
console.log("Processing...");
const options = {
match: /\.rdf$/,
exclude: ["pgNaN.rdf"]
};
const filesPath = path.join(__dirname, appConfig.filesPath);
nodeDir.readFiles(filesPath, options, onEachFile, onFinish(cb));
};