Skip to main content

Stream

Reads lines from a reader, groups them into batches, and invokes a flush function for each batch. Batches are also flushed when the underlying reader has no buffered data available.

def Stream(
ctx: context.Context,
r: io.Reader,
batchSize: int,
flush: func([]*dataplane.LogLine) error
) - > error

Reads lines from a given reader, groups them into batches, and invokes a flush function for each batch. Batches are also flushed when the underlying reader has no buffered data available to prevent callers from waiting indefinitely on partially-filled batches during idle periods.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the stream operation, used to signal cancellation. If the context is cancelled, any read errors are ignored.
rio.ReaderThe reader from which lines are read. This reader is expected to provide line-delimited data.
batchSizeintThe maximum number of log lines to include in a single batch before flushing. If set to 0 or less, a default batch size will be used.
flushfunc([]*dataplane.LogLine) errorA callback function invoked for each batch of log lines. This function processes the collected lines and should return an error if the processing fails.

Returns

TypeDescription
errorReturns nil on successful completion or if the context is cancelled. A non-EOF read error is returned only if the context has not been cancelled.