Documentation
¶
Index ¶
Constants ¶
const ( // DefaultMaxFileSize is the default file-size cap (100 MiB). DefaultMaxFileSize = 100 * 1024 * 1024 // DefaultMaxLineSize is the default per-line cap (1 MiB). DefaultMaxLineSize = 1 * 1024 * 1024 )
Variables ¶
var ErrFileTooLarge = errors.New("jsonl: file exceeds size cap")
ErrFileTooLarge is returned when the file size exceeds the configured cap.
var ErrLineTooLong = errors.New("jsonl: line exceeds size cap")
ErrLineTooLong is returned when a complete line exceeds the configured cap.
Functions ¶
func ReadLines ¶
func ReadLines(path string, offset int64, opts Options) (lines [][]byte, nextOffset int64, err error)
ReadLines reads complete newline-terminated lines from the file at path starting at the given byte offset. It returns the lines (without their newline terminators) and the byte offset immediately after the last complete line consumed.
A line is "complete" only if it ends with a newline character. Any trailing bytes after the last newline are not returned and are not reflected in nextOffset, making ReadLines safe for cursor-based incremental tailing: the caller can re-invoke with the returned nextOffset once more data is written.
ReadLines returns ErrFileTooLarge when os.Stat reports a size greater than opts.MaxFileSize. ReadLines returns ErrLineTooLong when any complete line is longer than opts.MaxLineSize bytes.
Binary garbage in lines is returned as-is; callers are responsible for JSON validation.
Types ¶
type Options ¶
type Options struct {
// MaxFileSize is the maximum file size in bytes before ReadLines returns
// ErrFileTooLarge. Zero uses DefaultMaxFileSize.
MaxFileSize int64
// MaxLineSize is the maximum byte length of a single line (excluding the
// newline terminator) before ReadLines returns ErrLineTooLong. Zero uses
// DefaultMaxLineSize.
MaxLineSize int
}
Options configures the JSONL reader.