import * as fs from 'fs' ; import * as es from 'event-stream' ; const JSONStream = require ( 'JSONStream' ) ; export default function readJson ( path ) { return new Promise ( ( resolve , reject ) => { let parsedObject = { } ; let stream = fs . createReadStream ( path , { encoding : 'utf8' } ) . pipe ( JSONStream . parse ( '$*' ) ) . pipe ( es . mapSync ( ( data ) => { parsedObject [ data . key ] = data . value ; } ) ) ; stream . on ( 'close' , ( ) => { resolve ( parsedObject ) ; } ) ; stream . on ( 'error' , reject ) ; } ) ; }