writer

package
v0.24.8 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const Closed = errutil.Error("Closed")

Closed is used by ChunkOutput to indicate a request to close the writer. ( why not io.EOF? ChunkWriter is custom so the error can be custom too. )

Variables

This section is empty.

Functions

func WriteRune

func WriteRune(w io.Writer, q rune) (ret int, err error)

WriteRune helper mimics io.WriteString, this invokes RuneWriter.WriteRune if w implements it. Otherwise w.Write gets called with the bytes necessary to encode the specified rune. Returns the number of bytes written.

func WriteString

func WriteString(w io.Writer, s string) (ret int, err error)

WriteString helper mimics io.WriteString, invoking w.WriteString if it implements it otherwise falling back to WriteRune, if it implements it or Write otherwise. using io.WriteString is generally enough because the formatting layers use ChunkWriter which use this.

Types

type Chunk

type Chunk struct {
	Data interface{}
}

Chunk unifies the four possible output data types: rune, byte, []rune, and string.

func (*Chunk) DecodeLastRune

func (c *Chunk) DecodeLastRune() (ret rune, cnt int)

DecodeRune - return the last rune in the data.

func (*Chunk) DecodeRune

func (c *Chunk) DecodeRune() (ret rune, cnt int)

DecodeRune - return the first rune of the data.

func (*Chunk) IsClosed

func (c *Chunk) IsClosed() bool

IsClosed - return true if the chunk was explicitly set to writer.Closed

func (*Chunk) IsEmpty

func (c *Chunk) IsEmpty() (okay bool)

IsEmpty - return true if has no data or if the data is empty.

func (*Chunk) Reset

func (c *Chunk) Reset()

Reset - forget the chunk's data; empty will return true, valid will return false.

func (*Chunk) String

func (c *Chunk) String() (ret string)

String - convert the chunk's data to string.

func (*Chunk) WriteTo

func (c *Chunk) WriteTo(w Output) (ret int, err error)

WriteTo - output the chunk's data to w; return the number of bytes written.

type ChunkOutput

type ChunkOutput func(Chunk) (int, error)

ChunkOutput - adapts go standard output for various methods: when go writes bytes, runes, or strings; this turns them all into chunks. this is a convenience so that filters, etc. only have to implement one write method ( WriteChunk ) not the full set of go's five methods. It should return the number of bytes of the *chunk* that were consumed, and any error encountered along the way. Noting that the returned value might not match the number of bytes written if the output is padded or reduced in someway.

func (ChunkOutput) Close

func (n ChunkOutput) Close() error

Close redirects the call to WriteChunk with a Closed error

func (ChunkOutput) Write

func (n ChunkOutput) Write(p []byte) (int, error)

Write redirects the call to WriteChunk

func (ChunkOutput) WriteByte

func (n ChunkOutput) WriteByte(b byte) error

WriteByte redirects the call to WriteChunk

func (ChunkOutput) WriteRune

func (n ChunkOutput) WriteRune(q rune) (int, error)

WriteRune redirects the call to WriteChunk

func (ChunkOutput) WriteString

func (n ChunkOutput) WriteString(s string) (int, error)

WriteString redirects the call to WriteChunk

type ChunkWriter

type ChunkWriter struct{ io.Writer }

ChunkWriter - adapter a regular io.Writer into a chunk writer

func (ChunkWriter) Close

func (c ChunkWriter) Close() error

func (ChunkWriter) WriteByte

func (c ChunkWriter) WriteByte(b byte) error

func (ChunkWriter) WriteRune

func (c ChunkWriter) WriteRune(q rune) (int, error)

func (ChunkWriter) WriteString

func (c ChunkWriter) WriteString(s string) (ret int, err error)

type Output

type Output interface {
	Write(p []byte) (int, error)
	WriteByte(c byte) error
	WriteRune(r rune) (int, error)
	WriteString(s string) (int, error)
}

Output defines a sink for go friendly text output. It's a subset of strings.Builder.

type OutputCloser

type OutputCloser interface {
	Output
	Close() error
}

OutputCloser - callers should attempt to Close() when they are done with a writer. ( this conforms to the io.Closer interface )

type RuneWriter

type RuneWriter interface {
	WriteRune(q rune) (int, error)
}

type Sink

type Sink struct {
	Output io.Writer
}

Sink implements a container for Output. it just happens to help provide simple output handling for rt.Runtime implementations.

func (*Sink) SetWriter

func (k *Sink) SetWriter(out io.Writer) (ret io.Writer)

func (*Sink) Writer

func (k *Sink) Writer() io.Writer

Jump to

Keyboard shortcuts

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