-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertBsonJson.js
36 lines (32 loc) · 1.04 KB
/
convertBsonJson.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
var fs = require('fs');
var BsonJsonTransform = require('bson-json-transform');
var filesDir = 'dump/github/';
var files = fs.readdirSync(filesDir);
var path = require('path');
console.log(process.argv);
function convertFile() {
for (var file in files) {
if(process.argv[2]){
if(files.indexOf(process.argv[2]) !== -1){
fs
.createReadStream(filesDir + process.argv[2])
.pipe(BsonJsonTransform({arrayOfBsons: true, preserveInt64: 'string' }))
.pipe(fs.createWriteStream(filesDir + 'json/' + files[file].slice(0,-4) + 'json'))
.on('end', function (data) {
console.log('No more data!');
});
}
}
else{
if (path.extname(files[file]) === ".bson" && files[file].indexOf("metadata") === -1) {
fs
.createReadStream(filesDir + files[file])
.pipe(BsonJsonTransform({arrayOfBsons: true, preserveInt64: 'string' }))
.pipe(fs.createWriteStream(filesDir + 'json/' + files[file].slice(0,-4) + 'json'))
.on('end', function (data) {
console.log('No more data!');
});
}
}
}
}