multiplexio

package module
v0.0.0-...-7477705 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2014 License: Apache-2.0 Imports: 4 Imported by: 13

README

multiplexio

Go library providing I/O wrappers for aggregating streams.

Build Status GoDoc

Usage

See godoc. For usage examples, the best is currently to check the project's tests.

Versioning policy

The API defined by this package is still considered unstable. However, until a fully backward-compatible v1 branch is created, the only changes in the existing API will be new configuration or customization fields. Therefore, as long as you initialize all structs declared in this project using explicit names, you will will not be affected by them.

For example, instead of:

Source{reader1}

Prefer:

Source{Reader: reader1}

Documentation

Overview

Package multiplexio exposes structs implementing and wrapping canonical I/O interfaces to tokenize, process and aggregate them with custom functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByStringLess

func ByStringLess(i, j []byte) bool

Implementation of Options.Less using the alphabetical string ordering.

func NewReader

func NewReader(options Options, sources ...Source) io.ReadCloser

NewReader returns an io.ReadCloser aggregating, according to a given ordering, tokens extracted concurrently from a set of io.Reader wrapped in a set of Source. Tokens of a given io.Reader go through the Write function passed together in the Source struct, or WriteNewLine if it is not set.

If the corresponding functions are not passed in Options, bufio.ScanLines is used for scanning and extracting tokens from the wrapped io.Reader objects, and ByStringLess is invoked for defining the order of these onto the aggregated stream.

func WriteNewLine

func WriteNewLine(dest io.Writer, token []byte) (n int, err error)

Implementation of Source.Write adding a line break after each token.

Types

type Options

type Options struct {
	Split bufio.SplitFunc        // function used for scanning and extracting tokens
	Less  func(i, j []byte) bool // function used for ordering extracted tokens, with sort.Interface.Less semantics
}

Options are the options for creating a new Reader.

type Source

type Source struct {
	Reader io.Reader                                             // incoming stream
	Write  func(dest io.Writer, token []byte) (n int, err error) // function used for formatting and dumping extracted tokens
}

Source combines an io.Reader from which tokens will be extracted with the Write function that will format them and dump them into the aggregated stream.

Jump to

Keyboard shortcuts

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