bytestream - ActiveState ActiveGo 1.8
...

Package bytestream

import "google.golang.org/api/transport/bytestream"
Overview
Index
Examples
Subdirectories

Overview ▾

Package bytestream provides a client for any service that exposes a ByteStream API.

Note: This package is a work-in-progress. Backwards-incompatible changes should be expected.

Constants

const (
    // MaxBufSize is the maximum buffer size (in bytes) received in a read chunk or sent in a write chunk.
    MaxBufSize = 2 * 1024 * 1024
)

type Client

Client is the go wrapper around a ByteStreamClient and provides an interface to it.

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

func NewClient

func NewClient(cc *grpc.ClientConn, options ...grpc.CallOption) *Client

NewClient creates a new bytestream.Client.

Example

Code:

ctx := context.Background()
conn, err := grpc.Dial(fmt.Sprintf("localhost:%d", serverPort), grpc.WithInsecure())
if err != nil {
    log.Printf("grpc.Dial: %v", err)
    return
}
client := NewClient(conn)
reader, err := client.NewReader(ctx, resourceName)
if err != nil {
    log.Printf("NewReader(%q): %v", resourceName, err)
}
var buf bytes.Buffer
n, err := buf.ReadFrom(reader)
if err != nil && err != io.EOF {
    log.Printf("Read %d bytes, got err=%v", n, err)
}
log.Printf("read %q", string(buf.Bytes()))

func (*Client) NewReader

func (c *Client) NewReader(ctx context.Context, resourceName string) (*Reader, error)

NewReader creates a new Reader to read a resource.

func (*Client) NewReaderAt

func (c *Client) NewReaderAt(ctx context.Context, resourceName string, offset int64) (*Reader, error)

NewReader creates a new Reader to read a resource from the given offset.

func (*Client) NewWriter

func (c *Client) NewWriter(ctx context.Context, resourceName string) (*Writer, error)

NewWriter creates a new Writer to write a resource.

resourceName specifies the name of the resource. The resource will be available after Close has been called.

It is the caller's responsibility to call Close when writing is done.

TODO: There is currently no way to resume a write. Maybe NewWriter should begin with a call to QueryWriteStatus.

type Reader

Reader reads from a byte stream.

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

func (*Reader) Close

func (r *Reader) Close() error

Close implements io.Closer.

func (*Reader) Read

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

Read implements io.Reader. Read buffers received bytes that do not fit in p.

func (*Reader) ResourceName

func (r *Reader) ResourceName() string

ResourceName gets the resource name this Reader is reading.

type Writer

Writer writes to a byte stream.

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

func (*Writer) Close

func (w *Writer) Close() error

Close implements io.Closer. It is the caller's responsibility to call Close() when writing is done.

func (*Writer) ResourceName

func (w *Writer) ResourceName() string

ResourceName gets the resource name this Writer is writing.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write implements io.Writer.

Subdirectories

Name Synopsis
..