iobus

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package iobus converts an io.Reader or io.Writer to a chan []byte.

Index

Constants

This section is empty.

Variables

View Source
var BufSize uint = 512

BufSize is the default buffer size that will be used if BufSize is not explicitly set on a Reader.

Functions

func NewWriter

func NewWriter(w io.Writer) (chan<- []byte, <-chan error)

NewWriter will write anything sent to the returned channel to the provided writer.

func Writer

func Writer(w io.Writer, ch <-chan []byte, errCh chan<- error)

Writer reads from a channel and writes anything received to the Writer. If there is an error writing, that will be sent on the errCh, if errCh is not nil.

Types

type Config

type Config struct {
	// CloseOnEOF causes a reader to close when it receives and EOF
	CloseOnEOF bool
	// Buffer size to use
	BufSize int
	// MakeErrCh is used by NewReader and NewWriter to set if an error channel
	// should be created.
	MakeErrCh bool
	// Sleep determines how long to wait before reading again after an empty
	// read.
	Sleep time.Duration
}

Config sets operational details for a Bus.

func (Config) NewReadWriter

func (cfg Config) NewReadWriter(rw io.ReadWriter) *ReadWriter

NewReadWriter runs both a Reader and a BusWriter on an io.ReaderWriter using the ReaderConfig for the reader.

func (Config) NewReader

func (cfg Config) NewReader(r io.Reader) *Reader

New creates a Reader from the provided io.Reader.

func (Config) NewWriter

func (cfg Config) NewWriter(w io.Writer) (chan<- []byte, <-chan error)

NewWriter creates the channels and runs Writer in a Go routine.

func (Config) Reader

func (cfg Config) Reader(r io.Reader, ch chan<- []byte, errCh chan<- error, stop *bool)

Reader runs a loop reading from r and writing the results to ch.

func (Config) Writer

func (cfg Config) Writer(w io.Writer, ch <-chan []byte, errCh chan<- error)

Writer reads from the channel and writes anything it receives to the writer.

type Duplex

type Duplex struct {
	io.Reader
	io.Writer
}

type ReadWriter

type ReadWriter struct {
	channel.Pipe[[]byte]
	Err  <-chan error
	Stop bool
}

ReadWriter runs both a Reader and a BusWriter on an io.ReaderWriter.

func NewReadWriter

func NewReadWriter(rw io.ReadWriter) *ReadWriter

NewReadWriter runs both a Reader and a BusWriter on an io.ReaderWriter.

type Reader

type Reader struct {
	Out  <-chan []byte
	Err  <-chan error
	Stop bool
}

func NewReader

func NewReader(r io.Reader) *Reader

NewReader creates a default Reader from the provided io.Reader.

Jump to

Keyboard shortcuts

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