import fs from 'fs' ; import { Sav2JsonTransform , SaveGame } from 'satisfactory-json' ; param path param asJson param callback export function openFileFromFilesystem ( path , asJson , callback ) { console . time ( 'readDesktop' ) ; window . data = path ; if ( asJson ) { fs . readFile ( path , ( err , data ) => { console . timeEnd ( 'readDesktop' ) ; if ( err ) { console . error ( err ) ; callback ( err , undefined , undefined ) ; return ; } callback ( undefined , 25 , undefined ) ; setTimeout ( ( ) => { try { const json = JSON . parse ( data . toString ( 'utf-8' ) ) ; callback ( undefined , 50 , undefined ) ; callback ( undefined , undefined , json ) ; } catch ( err ) { callback ( err as Error , undefined , undefined ) ; } } , 100 ) ; } ) ; } else { const stream = fs . createReadStream ( path ) ; const sav2json = new Sav2JsonTransform ( ) ; stream . pipe ( sav2json ) . on ( 'data' , ( saveGame ) => { console . timeEnd ( 'readDesktop' ) ; callback ( undefined , undefined , saveGame ) ; } ) . on ( 'progress' , ( progress ) => { callback ( undefined , progress , undefined ) ; } ) . on ( 'error' , error => { callback ( error , undefined , undefined ) ; } ) ; } }