-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.js
52 lines (40 loc) · 1.21 KB
/
convert.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
42
43
44
45
46
47
48
49
50
var fs = require('fs-extra'),
readline = require('readline'),
archiver = require('archiver');
fs.removeSync("export")
fs.mkdirSync("export")
fs.rm("export.zip")
var rd = readline.createInterface({
input: fs.createReadStream('vonkentries.json'),
console: false
});
let index = 0;
console.time("convert");
rd.on('line', function(line) {
const e = JSON.parse(line)
if(e.res_json){
// console.log(`[${index}] –– ${e._id.$oid}`); // speeedddd - no extra interrupts!!!
fs.writeFileSync(`export/${e.type}-${e._id.$oid}.json`, e.res_json)
index++
}
});
const archive = () => {
var output = fs.createWriteStream('export.zip');
var archive = archiver('zip');
output.on('close', function () {
console.log(archive.pointer() + ' (archived) total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
fs.removeSync("export") // remove dir again
});
archive.on('error', function(err){
throw err;
});
archive.pipe(output);
archive.directory('export', false);
archive.finalize();
}
rd.on('close', ()=>{
console.log(`[${index}]`);
console.timeEnd('convert')
archive()
})