streams

package
v0.0.0-...-e081c89 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package streams provides the standard streams used by murex and thus is REQUIRED by murex.

Index

Constants

This section is empty.

Variables

View Source
var DefaultMaxBufferSize = 1024 * 1024 * 1 // 1 meg

DefaultMaxBufferSize is the maximum size of buffer for stdin var DefaultMaxBufferSize = 1024 * 1024 * 1000 // 10 meg

Functions

func NewTee

func NewTee(primary stdio.Io) (primaryTee *Tee, secondaryTee *Stdin)

NewTee creates a new tee stdio interface

Types

type ReadCloser

type ReadCloser struct {
	Reader
}

ReadCloser is a wrapper around an io.ReadCloser interface

func NewReadCloser

func NewReadCloser(reader io.ReadCloser) (r *ReadCloser)

NewReadCloser creates a new Stdio.Io interface wrapper around a io.ReadCloser interface

type Reader

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

Reader is a wrapper around an io.Reader interface

func NewReader

func NewReader(reader io.Reader) (r *Reader)

NewReader creates a new Stdio.Io interface wrapper around a io.Reader interface

func (*Reader) Close

func (r *Reader) Close()

Close the stream.Io interface

func (*Reader) DefaultDataType

func (r *Reader) DefaultDataType(err bool)

DefaultDataType defines the murex data type for the stream.Io interface if it's not already set

func (*Reader) File

func (t *Reader) File() *os.File

func (*Reader) ForceClose

func (r *Reader) ForceClose()

ForceClose forces the stream.Io interface to close. This should only be called by a STDIN reader

func (*Reader) GetDataType

func (r *Reader) GetDataType() (dt string)

GetDataType returns the murex data type for the stream.Io interface

func (*Reader) IsTTY

func (r *Reader) IsTTY() bool

IsTTY returns false because the reader interface is not a pseudo-TTY

func (*Reader) Open

func (r *Reader) Open()

Open the stream.Io interface for another dependant

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read is the reader interface Read() method.

func (*Reader) ReadAll

func (r *Reader) ReadAll() (b []byte, err error)

ReadAll reads everything and dump it into one byte slice.

func (*Reader) ReadArray

func (r *Reader) ReadArray(ctx context.Context, callback func([]byte)) error

ReadArray returns a data type-specific array returned via a callback function

func (*Reader) ReadArrayWithType

func (r *Reader) ReadArrayWithType(ctx context.Context, callback func(interface{}, string)) error

ReadArrayWithType returns a data type-specific array returned via a callback function

func (*Reader) ReadLine

func (r *Reader) ReadLine(callback func([]byte)) error

ReadLine returns each line in the stream as a callback function

func (*Reader) ReadMap

func (r *Reader) ReadMap(config *config.Config, callback func(*stdio.Map)) error

ReadMap returns a data type-specific key/values returned via a callback function

func (*Reader) SetDataType

func (r *Reader) SetDataType(dt string)

SetDataType defines the murex data type for the stream.Io interface

func (*Reader) Stats

func (r *Reader) Stats() (bytesWritten, bytesRead uint64)

Stats provides real time stream stats. Useful for progress bars etc.

func (*Reader) Write

func (r *Reader) Write(p []byte) (int, error)

Write is a dummy function because it's a reader interface

func (*Reader) WriteArray

func (r *Reader) WriteArray(dataType string) (stdio.ArrayWriter, error)

WriteArray is a dummy function because it's a reader interface

func (*Reader) WriteTo

func (r *Reader) WriteTo(w io.Writer) (int64, error)

WriteTo reads from the stream.Io interface and writes to a destination io.Writer interface

func (*Reader) Writeln

func (r *Reader) Writeln(b []byte) (int, error)

Writeln is a dummy function because it's a reader interface

type Stdin

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

Stdin is the default stdio.Io interface. Despite it's name, this interface can and is used for Stdout and Stderr streams too.

func NewStdin

func NewStdin() (stdin *Stdin)

NewStdin creates a new stream.Io interface for piping data between processes. Despite it's name, this interface can and is used for Stdout and Stderr streams too.

func NewStdinWithContext

func NewStdinWithContext(ctx context.Context, forceClose context.CancelFunc) (stdin *Stdin)

NewStdinWithContext creates a new stream.Io interface for piping data between processes. Despite it's name, this interface can and is used for Stdout and Stderr streams too. This function is also useful as a context aware version of ioutil.ReadAll

func (*Stdin) Close

func (stdin *Stdin) Close()

Close the stream.Io interface

func (*Stdin) File

func (stdin *Stdin) File() *os.File

func (*Stdin) ForceClose

func (stdin *Stdin) ForceClose()

ForceClose forces the stream.Io interface to close. This should only be called by a STDIN reader

func (*Stdin) GetDataType

func (stdin *Stdin) GetDataType() (dt string)

GetDataType returns the murex data type for the stream.Io interface

func (*Stdin) IsTTY

func (stdin *Stdin) IsTTY() bool

IsTTY returns false because the Stdin stream is not a pseudo-TTY

func (*Stdin) Open

func (stdin *Stdin) Open()

Open the stream.Io interface for another dependant

func (*Stdin) Read

func (stdin *Stdin) Read(p []byte) (i int, err error)

Read is the standard Reader interface Read() method.

func (*Stdin) ReadAll

func (stdin *Stdin) ReadAll() ([]byte, error)

ReadAll reads everything and dump it into one byte slice.

func (*Stdin) ReadArray

func (stdin *Stdin) ReadArray(ctx context.Context, callback func([]byte)) error

ReadArray returns a data type-specific array returned via a callback function

func (*Stdin) ReadArrayWithType

func (stdin *Stdin) ReadArrayWithType(ctx context.Context, callback func(interface{}, string)) error

ReadArrayWithType returns an array like "ReadArray" plus data type via a callback function

func (*Stdin) ReadFrom

func (stdin *Stdin) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads data from r until EOF and appends it to the buffer.

func (*Stdin) ReadLine

func (stdin *Stdin) ReadLine(callback func([]byte)) error

ReadLine returns each line in the stream as a callback function

func (*Stdin) ReadMap

func (stdin *Stdin) ReadMap(config *config.Config, callback func(*stdio.Map)) error

ReadMap returns a data type-specific key/values returned via a callback function

func (*Stdin) SetDataType

func (stdin *Stdin) SetDataType(dt string)

SetDataType defines the murex data type for the stream.Io interface

func (*Stdin) Stats

func (stdin *Stdin) Stats() (bytesWritten, bytesRead uint64)

Stats provides real time stream stats. Useful for progress bars etc.

func (*Stdin) Write

func (stdin *Stdin) Write(p []byte) (int, error)

Write is the standard Writer interface Write() method.

func (*Stdin) WriteArray

func (stdin *Stdin) WriteArray(dataType string) (stdio.ArrayWriter, error)

WriteArray performs data type specific buffered writes to an stdio.Io interface

func (*Stdin) WriteTo

func (stdin *Stdin) WriteTo(w io.Writer) (int64, error)

WriteTo reads from the stream.Io interface and writes to a destination io.Writer interface

func (*Stdin) Writeln

func (stdin *Stdin) Writeln(b []byte) (int, error)

Writeln just calls Write() but with an appended, OS specific, new line.

type Stdtest

type Stdtest struct {
	Stdin
}

Stdtest is a testing Io interface user to workaround writing to the terminal

func NewStdtest

func NewStdtest() (stdtest *Stdtest)

NewStdtest creates a new stream.Io interface for piping data between test processes that need to spoof an PTY

func (*Stdtest) IsTTY

func (stdtest *Stdtest) IsTTY() bool

IsTTY returns true because the Stdtest stream is a pseudo-TTY mockup

type Tee

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

Tee is a stream interface with two output streams (like the `tee` command on UNIX/Linux)

func (*Tee) Close

func (tee *Tee) Close()

Close the stream.Io interface

func (*Tee) File

func (tee *Tee) File() *os.File

func (*Tee) ForceClose

func (tee *Tee) ForceClose()

ForceClose forces the stream.Io interface to close. This should only be called by a STDIN reader

func (*Tee) GetDataType

func (tee *Tee) GetDataType() (dt string)

GetDataType returns the murex data type for the stream.Io interface

func (*Tee) IsTTY

func (tee *Tee) IsTTY() bool

IsTTY calls the primary STDOUT stream in tee to see if it's a TTY

func (*Tee) Open

func (tee *Tee) Open()

Open the stream.Io interface for another dependant

func (*Tee) Read

func (tee *Tee) Read(p []byte) (int, error)

Read from STDIN (uses primary tee stream)

func (*Tee) ReadAll

func (tee *Tee) ReadAll() ([]byte, error)

ReadAll from STDIN (uses the primary tee stream)

func (*Tee) ReadArray

func (tee *Tee) ReadArray(ctx context.Context, callback func([]byte)) error

ReadArray reads an array from STDIN (uses the primary tee stream)

func (*Tee) ReadArrayWithType

func (tee *Tee) ReadArrayWithType(ctx context.Context, callback func(interface{}, string)) error

ReadArrayWithType reads an array from STDIN (uses the primary tee stream)

func (*Tee) ReadLine

func (tee *Tee) ReadLine(callback func([]byte)) error

ReadLine reads a line from STDIN (uses the primary tee stream)

func (*Tee) ReadMap

func (tee *Tee) ReadMap(config *config.Config, callback func(*stdio.Map)) error

ReadMap reads a hash table from STDIN (uses the primary tee stream)

func (*Tee) SetDataType

func (tee *Tee) SetDataType(dt string)

SetDataType defines the murex data type for the stream.Io interface

func (*Tee) Stats

func (tee *Tee) Stats() (uint64, uint64)

Stats is stored against the primary STDOUT stream in tee

func (*Tee) Write

func (tee *Tee) Write(p []byte) (int, error)

Write is the standard Writer interface Write() method.

func (*Tee) WriteArray

func (tee *Tee) WriteArray(dataType string) (stdio.ArrayWriter, error)

WriteArray performs data type specific buffered writes to an stdio.Io interface

func (*Tee) WriteTo

func (tee *Tee) WriteTo(w io.Writer) (n int64, err error)

WriteTo reads from the stream.Io interface and writes to a destination io.Writer interface

func (*Tee) Writeln

func (tee *Tee) Writeln(p []byte) (int, error)

Writeln just calls Write() but with an appended, OS specific, new line.

Jump to

Keyboard shortcuts

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