import { StringUtil } from "./string-util" ; export class BufferUtil { public static prettyPrint ( buffer ) { let s = buffer . toString ( ) ; return StringUtil . prettyPrint ( s ) ; } public static fromString ( s ) { return Buffer . from ( s ) ; } public static scan ( body , sequence ) { let index = - 1 ; for ( let i = 0 ; i < body . length ; i ++ ) { let val = body [ i ] ; if ( val === sequence [ 0 ] ) { let match = true ; for ( let ii = 1 ; ii < sequence . length ; ii ++ ) { let bodyIndex = i + ii ; if ( bodyIndex >= body . length ) { match = false ; break ; } val = body [ bodyIndex ] ; if ( val !== sequence [ ii ] ) { match = false ; break ; } } if ( match ) { index = i ; break ; } } } return index ; } }