import fileReaderStream from 'filereader-stream' ; import { Sav2JsonTransform , SaveGame } from 'satisfactory-json' ; import { SaveFileReader } from '../core/SaveGameLoading' ; export class WebFileReader implements SaveFileReader { constructor ( private file ) { } readFile ( filepath , asJson , progressCallback , errorCallback , successCallback ) { window . data = this . file ; try { let json ; if ( asJson ) { const reader = new FileReader ( ) ; reader . onload = response => { try { json = JSON . parse ( Buffer . from ( reader . result as string ) . toString ( 'utf-8' ) ) ; successCallback ( json ) ; } catch ( error ) { console . error ( error ) ; errorCallback ( error as Error ) ; } } ; reader . readAsArrayBuffer ( this . file ) ; } else { console . time ( 'sav2json' ) ; const reader = fileReaderStream ( this . file ) ; reader . pipe ( new Sav2JsonTransform ( ) ) . on ( 'data' , ( data ) => { console . timeEnd ( 'sav2json' ) ; successCallback ( data ) ; } ) . on ( 'progress' , ( progress ) => { progressCallback ( progress ) ; } ) . on ( 'error' , ( error ) => { console . error ( 'error' , error ) ; errorCallback ( error ) ; } ) ; } } catch ( error ) { console . error ( error ) ; errorCallback ( error as Error ) ; } } }