stream

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package stream provides functions to operate with data streams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tar

func Tar(writer io.Writer, src string) error

Tar archive tars the contents of src into a writer stream

func TarBytes

func TarBytes(writer io.Writer, bytes []byte) error

TarBytes tars bytes as a single logical file into a tar file writer.

func Untar

func Untar(r io.Reader, dst string) error

Untar untars the contents of a reader into dst

func UntarBytes

func UntarBytes(dst io.Writer, r io.Reader) error

UntarBytes untars a tar r to a dst writer. This assumes that the tar contains only a single file.

Types

type MessageCloser

type MessageCloser interface {
	BuildMsg() interface{}
	CloseMsg() interface{}
}

MessageCloser defines a generic interface create a message that closes a stream.

type MessageReadWriteCloser

type MessageReadWriteCloser interface {
	BuildMsg() interface{}
	GetBytes(interface{}) ([]byte, error)
	SetBytes(interface{}, []byte)
	CloseMsg() interface{}
}

MessageReadWriteCloser defines a generic interface to build messages with byte contents.

type MessageReader

type MessageReader interface {
	BuildMsg() interface{}
	GetBytes(interface{}) ([]byte, error)
}

MessageReader defines a generic interface to read bytes from a message.

type MessageWriter

type MessageWriter interface {
	BuildMsg() interface{}
	SetBytes(interface{}, []byte)
}

MessageWriter defines a generic interface to set bytes in a message.

type ReadWriteCloser

type ReadWriteCloser struct {
	Stream
	MessageReadWriteCloser
	// contains filtered or unexported fields
}

ReadWriteCloser wraps arbitrary grpc streams around a ReadWriteCloser implementation. Users create a new ReadWriteCloser by calling NewReadWriteCloser passing a base stream. The stream needs to implement RecvMsg and SendMsg (i.e. ClientStream and ServerStream types), And a function to set bytes in the stream message type, get bytes from the message and close the stream. NOTE: The reader follows the same semantics as <Server|Client>Stream. It is ok to have concurrent writes and reads, but it's not ok to have multiple concurrent reads or multiple concurrent writes.

func NewReadWriteCloser

func NewReadWriteCloser(stream Stream, sm MessageReadWriteCloser) *ReadWriteCloser

NewReadWriteCloser returns an initialized ReadWriteCloser.

func (*ReadWriteCloser) Close

func (s *ReadWriteCloser) Close() error

Close closes the stream.

func (*ReadWriteCloser) CloseRead

func (s *ReadWriteCloser) CloseRead() error

CloseRead closes the read side of the stream.

func (*ReadWriteCloser) CloseWrite

func (s *ReadWriteCloser) CloseWrite() error

CloseWrite closes the write side of the stream and signals the other side.

func (*ReadWriteCloser) Read

func (s *ReadWriteCloser) Read(b []byte) (int, error)

Read calls the Read method of the underlying Reader if the stream is not closed.

func (*ReadWriteCloser) Write

func (s *ReadWriteCloser) Write(b []byte) (int, error)

Write writes b to the underlying stream.

type Reader

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

Reader wraps arbitrary grpc streams around a Reader implementation.

func NewReader

func NewReader(stream Stream, sm MessageReader) *Reader

NewReader creates and initializes a new Reader.

func (*Reader) Read

func (s *Reader) Read(b []byte) (int, error)

Read reads from the underlying stream handling cases where the amount read > len(b).

type Stream

type Stream interface {
	SendMsg(m interface{}) error
	RecvMsg(m interface{}) error
}

Stream defines an interface to send and receive messages.

type Writer

type Writer struct {
	Stream
	MessageWriter
}

Writer implements a Writer backed by a stream.

func NewWriter

func NewWriter(stream Stream, sm MessageWriter) *Writer

NewWriter creates a new Writer.

func (*Writer) Write

func (s *Writer) Write(b []byte) (int, error)

Writer writes b to the message in the underlying stream.

Jump to

Keyboard shortcuts

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