File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ var Schema = require ( '../lib/schema' ) ;
2
+ var fs = require ( 'fs' ) ;
3
+ var es = require ( 'event-stream' ) ;
4
+
5
+ var ts = new Date ( ) ;
6
+
7
+ // create new schema object with fake namespace
8
+ var schema = new Schema ( {
9
+ ns : 'perf.testing'
10
+ } ) ;
11
+
12
+ if ( process . argv . length < 3 ) {
13
+ console . log ( 'Usage: node parse-from-file.js <jsonfile>' ) ;
14
+ } else {
15
+ fs . createReadStream ( process . argv [ 2 ] , {
16
+ flags : 'r'
17
+ } )
18
+ . pipe ( es . split ( ) ) // split file into individual json docs (one per line)
19
+ . pipe ( es . parse ( ) ) // parse each doc
20
+ . pipe ( schema . stream ( ) ) // comment out this line to skip schema parsing
21
+ . pipe ( es . stringify ( ) ) // stringify result
22
+ . pipe ( es . wait ( function ( err , res ) { // assemble everything back together
23
+ if ( err ) {
24
+ throw err ;
25
+ }
26
+ var dur = new Date ( ) - ts ;
27
+ console . log ( res ) ;
28
+ console . log ( 'took ' + dur + 'ms.' ) ; // log time it took to parse
29
+ } ) ) ;
30
+ }
You can’t perform that action at this time.
0 commit comments