// findSig searches for the RAR signature and version at the beginning of a file.
// It searches no more than maxSfxSize bytes.
findSig searches for the RAR signature and version at the beginning of a file.
It searches no more than maxSfxSize bytes.
// findSig searches for the RAR signature and version at the beginning of a file . // It searches no more than maxSfxSize bytes .
func findSig(br *bufio.Reader) (int, error) {
	for n := 0; n <= maxSfxSize; {
		b, err := br.ReadSlice(sigPrefix[0])
		n += len(b)
		if err == bufio.ErrBufferFull {
			continue
		} else if err != nil {
			if err == io.EOF {
				err = errNoSig
			}
			return 0, err
		}
		b, err = br.Peek(len(sigPrefix[1:]) + 2)
		if err != nil {
			if err == io.EOF {
				err = errNoSig
			}
			return 0, err
		}
		if !bytes.HasPrefix(b, []byte(sigPrefix[1:])) {
			continue
		}
		b = b[len(sigPrefix)-1:]
		var ver int
		switch {
		case b[0] == 0:
			ver = fileFmt15
		case b[0] == 1 && b[1] == 0:
			ver = fileFmt50
		default:
			continue
		}
		_, _ = br.ReadSlice('\x00')
		return ver, nil
	}
	return 0, errNoSig
}
func findSig ( br * bufio . Reader ) ( int , error ) { for n := 0 ; n <= maxSfxSize ; { b , err := br . ReadSlice ( sigPrefix [ 0 ] ) n += len ( b ) if err == bufio . ErrBufferFull { continue } else if err != nil { if err == io . EOF { err = errNoSig } return 0 , err } b , err = br . Peek ( len ( sigPrefix [ 1 : ] ) + 2 ) if err != nil { if err == io . EOF { err = errNoSig } return 0 , err } if ! bytes . HasPrefix ( b , [ ] byte ( sigPrefix [ 1 : ] ) ) { continue } b = b [ len ( sigPrefix ) - 1 : ] var ver int switch { case b [ 0 ] == 0 : ver = fileFmt15 case b [ 0 ] == 1 && b [ 1 ] == 0 : ver = fileFmt50 default : continue } _ , _ = br . ReadSlice ( '\x00' ) return ver , nil } return 0 , errNoSig }
findSig searches for the RAR signature and version at the beginning of a file.
findSig searches for the RAR signature and version at the beginning of a file .