stream

package
v5.0.0-rc+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(src Source, dest Dest) error

Copy copies data from a source stream to a destination stream.

func NopWriteCloser

func NopWriteCloser(w io.Writer) io.WriteCloser

NopWriteCloser works like io.NopCloser, but for writers.

Types

type Dest

type Dest func() (io.WriteCloser, error)

func ToBuffer

func ToBuffer(closeCallback func(*bytes.Buffer) error) Dest

ToBuffer buffers the contents of the stream and on Close() calls the callback returning its error.

func ToDiscard

func ToDiscard() Dest

ToDiscard discards any data written to it.

func ToError

func ToError(err error) Dest

ToError returns an error when Dest is initialized.

func ToFile

func ToFile(path ...string) Dest

ToFile concatenates the given path segments with filepath.Join, creates any parent directoreis if needed, and writes the file.

func ToModeFile

func ToModeFile(mode os.FileMode, path ...string) Dest

ToModeFile is like ToFile, but sets the permissions on the created file.

func ToWriteCloser

func ToWriteCloser(w io.WriteCloser) Dest

ToWriteCloser forwards data to the given WriteCloser which will be closed after the copy finishes.

func ToWriter

func ToWriter(writer io.Writer) Dest

ToWriter forwards data to the given writer, this function WILL NOT close the underlying stream so it is safe to use with things like stdout.

func ToYaml

func ToYaml(v interface{}) Dest

ToYaml unmarshals the contents of the stream as YAML to the given struct.

type MultiCloser

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

MultiCloser calls Close() once on every added closer and returns a multierror of all errors encountered.

Example
var mc MultiCloser

mc.Add(ioutil.NopCloser(nil))

fmt.Println("closed:", mc.Close())
Output:

closed: <nil>

func (*MultiCloser) Add

func (mc *MultiCloser) Add(c io.Closer)

Add appends the closer to the internal list of closers.

func (*MultiCloser) Close

func (mc *MultiCloser) Close() error

Close calls close on all closers, discarding them from the list. Modifying MultiCloser in your Close method will create a deadlock. At the end of this function, the close list will be empty and any encountered errors will be returned.

type Source

type Source func() (io.ReadCloser, error)

func FromBytes

func FromBytes(b []byte) Source

FromBytes streams the given bytes as a buffer.

func FromError

func FromError(err error) Source

FromError returns a nil ReadCloser and the error passed when called.

func FromFile

func FromFile(path ...string) Source

FromFile joins the segments of the path and reads from it.

func FromReadCloser

func FromReadCloser(rc io.ReadCloser) Source

FromReadCloser reads the contents of the readcloser and takes ownership of closing it.

func FromReadCloserError

func FromReadCloserError(rc io.ReadCloser, err error) Source

FromReadCloserError reads the contents of the readcloser and takes ownership of closing it. If err is non-nil, it is returned as a source.

func FromReader

func FromReader(rc io.Reader) Source

FromReader converts a Reader to a Source.

func FromString

func FromString(s string) Source

FromBytes streams the given bytes as a buffer.

func FromYaml

func FromYaml(v interface{}) Source

FromYaml converts the interface to a stream of Yaml.

Jump to

Keyboard shortcuts

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