A fast, bounded-memory line scanner for Go.
- Callback and Go 1.23 iterator APIs
- Configurable initial and maximum buffer sizes
- trimming for Windows-style line endings
- Memory-bounded long-line handling via
ErrTokenTooLong - Race-tested
go get github.com/monitoring-forge/linebufpackage main
import (
"os"
"github.com/monitoring-forge/linebuf"
)
func main() {
err := linebuf.Scan(os.Stdin, func(line []byte) error {
// process line
return nil
})
if err != nil {
// handle error
}
}scanner := linebuf.New()
for line := range scanner.Iter(r) {
// process line
}
if err := scanner.IterErr(); err != nil {
// handle error
}scanner := linebuf.New(
linebuf.WithStartBufSize(4096), // initial buffer size
linebuf.WithMaxBufSize(65536), // maximum buffer size
)If a line exceeds MaxBufSize, scanning stops with linebuf.ErrTokenTooLong.
See LICENSE.