File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ var fs = require ( 'fs' ) ;
2
+ var BsonJsonTransform = require ( 'bson-json-transform' ) ;
3
+ var filesDir = 'dump/github/' ;
4
+ var files = fs . readdirSync ( filesDir ) ;
5
+ var path = require ( 'path' ) ;
6
+
7
+ console . log ( process . argv ) ;
8
+
9
+
10
+ function convertFile ( ) {
11
+ for ( var file in files ) {
12
+ if ( process . argv [ 2 ] ) {
13
+ if ( files . indexOf ( process . argv [ 2 ] ) !== - 1 ) {
14
+ fs
15
+ . createReadStream ( filesDir + process . argv [ 2 ] )
16
+ . pipe ( BsonJsonTransform ( { arrayOfBsons : true , preserveInt64 : 'string' } ) )
17
+ . pipe ( fs . createWriteStream ( filesDir + 'json/' + files [ file ] . slice ( 0 , - 4 ) + 'json' ) )
18
+ . on ( 'end' , function ( data ) {
19
+ console . log ( 'No more data!' ) ;
20
+ } ) ;
21
+ }
22
+ }
23
+ else {
24
+ if ( path . extname ( files [ file ] ) === ".bson" && files [ file ] . indexOf ( "metadata" ) === - 1 ) {
25
+ fs
26
+ . createReadStream ( filesDir + files [ file ] )
27
+ . pipe ( BsonJsonTransform ( { arrayOfBsons : true , preserveInt64 : 'string' } ) )
28
+ . pipe ( fs . createWriteStream ( filesDir + 'json/' + files [ file ] . slice ( 0 , - 4 ) + 'json' ) )
29
+ . on ( 'end' , function ( data ) {
30
+ console . log ( 'No more data!' ) ;
31
+ } ) ;
32
+ }
33
+ }
34
+ }
35
+ }
36
+
You can’t perform that action at this time.
0 commit comments