stream

package
v0.12.0-beta3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package stream provides stream-processing utilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrMaximumBufferSizeExceeded = errors.New("maximum buffer size exceed")

ErrMaximumBufferSizeExceeded is returned when a write would exceed the maximum internal buffer size for a writer.

View Source
var (
	// ErrWritePreempted indicates that a write operation was preempted.
	ErrWritePreempted = errors.New("write preempted")
)

Functions

func NewPreemptableWriter

func NewPreemptableWriter(writer io.Writer, cancelled <-chan struct{}, interval uint) io.Writer

NewPreemptableWriter wraps an io.Writer and provides preemption capabilities for long copy operations. It takes an underlying writer, a channel that (once closed) indicates cancellation, and an interval that specifies the maximum number of Write calls that should be processed between cancellation checks. If interval is 0, a cancellation check will be performed before every write.

Types

type LineProcessor

type LineProcessor struct {
	// Callback is the line processing callback.
	Callback func(string)
	// MaximumBufferSize is the maximum allowed internal buffer size. If writes
	// to the writer exceed this size without incorporating a newline, then an
	// error will be raised. A value of 0 causes the writer to use a reasonable
	// default. A negative value indicates no limit.
	MaximumBufferSize int
	// contains filtered or unexported fields
}

LineProcessor is an io.Writer that splits its input stream into lines and writes those lines to a callback function. Line splits are performed on any instance of '\n' or '\r\n', with the split character(s) removed from the callback value.

func (*LineProcessor) Write

func (p *LineProcessor) Write(data []byte) (int, error)

Write implements io.Writer.Write.

type ValveWriter

type ValveWriter struct {
	// contains filtered or unexported fields
}

ValveWriter is an io.Writer that wraps another io.Writer and performs writes to it until the valve is shut, after which writes will continue to succeed but not be written to the underlying writer.

func NewValveWriter

func NewValveWriter(writer io.Writer) *ValveWriter

NewValveWriter creates a new ValveWriter instance using the specified writer. The write may be nil, in which case the writer will start pre-shut.

func (*ValveWriter) Shut

func (w *ValveWriter) Shut()

Shut closes the valve and stops writes to the underlying writer.

func (*ValveWriter) Write

func (w *ValveWriter) Write(buffer []byte) (int, error)

Write implements io.Writer.Write.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL