Documentation
¶
Overview ¶
Package sse reads Server-Sent Events streams line by line.
bufio.Scanner stops at a fixed token size, so one event larger than its buffer ends the whole stream with "token too long". LineReader reads lines of any length up to a high safety limit instead, and skips a line past that limit (keeping its start, so the caller can tell what it was) rather than failing the stream.
Index ¶
Constants ¶
const DefaultMaxLine = 64 << 20
DefaultMaxLine is the longest line read whole: well past any event a DocsGPT server sends, but a bound on what one line can make the client hold.
const PrefixBytes = 4096
PrefixBytes is how much of an oversized line is kept, enough to read the event's type.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Line ¶
type Line struct {
// Text is the line without its line ending; for an oversized line, only
// its first PrefixBytes.
Text []byte
// Oversized marks a line longer than the reader's limit, which was skipped.
Oversized bool
// Size is the line's full length in bytes, line ending excluded.
Size int
}
Line is one line of the stream.
type LineReader ¶
type LineReader struct {
// contains filtered or unexported fields
}
LineReader reads newline-terminated lines with no fixed buffer cap.
func NewLineReader ¶
func NewLineReader(r io.Reader, max int) *LineReader
NewLineReader reads lines from r, reading whole those up to max bytes.
func (*LineReader) Next ¶
func (l *LineReader) Next() (Line, error)
Next returns the next line. At the end of the stream it returns io.EOF, after any final line that had no line ending.