import { createChunkReader } from 'root/app/log-parser/chunk_reader' ; import { LogFileOperationResult , ParsingMetadata } from 'root/app/log-parser/model' ; export async function checkDetailedLogEnabled ( path , options ) { return new Promise < LogFileOperationResult < boolean > > ( ( resolve , reject ) => { const chunkStream = createChunkReader ( path , 0 ) ; chunkStream . onData ( ( chunk , bytesRead ) => { const res = chunk . split ( options . detailedLogInfo . prefix , 2 ) ; if ( res . length === 1 ) { bytesRead += chunk . length ; return ; } const [ beforePrefix , afterPrefix ] = res ; bytesRead += beforePrefix . length + options . detailedLogInfo . prefix . length ; const [ detailedLogString ] = afterPrefix . split ( /\r?\n/ , 2 ) ; const additionalByteRead = beforePrefix . length + options . detailedLogInfo . prefix . length + detailedLogString . length ; const normalizedString = detailedLogString . trim ( ) . toUpperCase ( ) ; if ( normalizedString === options . detailedLogInfo . enabledValue . toUpperCase ( ) ) { resolve ( [ true , { bytesRead : bytesRead + additionalByteRead } ] ) ; } else if ( normalizedString === options . detailedLogInfo . disabledValue . toUpperCase ( ) ) { resolve ( [ false , { bytesRead : bytesRead + additionalByteRead } ] ) ; } else { reject ( new Error ( `Unknown value for detailed log info: "${ detailedLogString }"` ) ) ; } chunkStream . close ( ) ; } ) ; chunkStream . onEnd ( ( ) => { resolve ( [ false , { bytesRead : 0 } ] ) ; chunkStream . close ( ) ; } ) ; chunkStream . onError ( ( err ) => { reject ( err ) ; chunkStream . close ( ) ; } ) ; } ) ; }