Documentation
¶
Overview ¶
Package ringbuf provides a bounded output writer used by the bash runtime to enforce the spec's MaxOutputSize limit.
Despite the package name (which mirrors the spec's layout table), the current implementation is a forward-only limited writer; the "ring" semantics — where over-cap writes overwrite the oldest bytes — are not needed for the limit-enforcement path. The package name is kept so the import path matches the spec; a true ring-buffered variant can land later under the same package without breaking the limit wiring.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LimitedWriter ¶
type LimitedWriter struct {
// contains filtered or unexported fields
}
LimitedWriter wraps an io.Writer and accounts every byte written to it against a shared Tracker.
Once the Tracker overflows, further Write calls write nothing and return the Tracker's overflow error. Partial writes are still flushed to the underlying writer up to the remaining budget on the call that trips the limit, so the caller's captured output reflects what would have been written had there been room.
func NewLimitedWriter ¶
func NewLimitedWriter(w io.Writer, t *Tracker) *LimitedWriter
NewLimitedWriter wraps w to enforce t's limit. If t is nil the limit is not enforced and writes pass through unchanged.
func (*LimitedWriter) Write ¶
func (l *LimitedWriter) Write(p []byte) (int, error)
Write implements io.Writer. It returns the number of bytes actually written to the underlying writer. When the Tracker's limit is tripped, Write returns the Tracker's overflow error (n may be > 0 for the call that crosses the boundary).
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker holds the shared output budget enforced by one or more LimitedWriter instances. Stdout and stderr both wrap the same Tracker so MaxOutputSize caps the combined output of a single Exec call.
All methods are safe for concurrent use.
func NewTracker ¶
NewTracker returns a Tracker enforcing the given byte limit. onOver is invoked exactly once, the first time a write would push the cumulative count past limit; its return value is the error returned from subsequent Write calls.
A non-positive limit is treated as "no limit" — Write always succeeds and onOver is never called.
func (*Tracker) Err ¶
Err returns the error returned by the onOver callback the first time the limit was tripped, or nil if the tracker has not overflowed.
func (*Tracker) Overflowed ¶
Overflowed reports whether the limit has been tripped.