import fs from 'fs' ; import { ParsingMetadata } from 'root/app/log-parser/model' ; export async function initialpositioner ( path , DisplayName , options ) { return new Promise < number > ( ( resolve , reject ) => { const stream = fs . createReadStream ( path , { encoding : 'utf8' , autoClose : true , start : 0 , } ) ; let foundId = false ; let lastchunk = '' ; let meaningfulBytesRead = 0 ; let bytesRead = 0 ; stream . on ( 'data' , ( chunk ) => { const userLoginPosition = chunk . lastIndexOf ( `Logged in successfully. Display Name: ${ DisplayName }` ) ; lastchunk = chunk ; if ( userLoginPosition === - 1 ) { bytesRead += chunk . length ; } else { bytesRead += userLoginPosition ; foundId = true ; meaningfulBytesRead = bytesRead ; stream . close ( ) ; } return ; } ) ; stream . on ( 'close' , ( ) => { if ( foundId ) { resolve ( meaningfulBytesRead ) ; } else { resolve ( 0 ) ; } stream . close ( ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; stream . close ( ) ; } ) ; } ) ; }