api: google.golang.org/api/transport/bytestream Index | Examples | Files | Directories

package bytestream

import "google.golang.org/api/transport/bytestream"

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.

Index

Examples

Package Files

client.go

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 Uses

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

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

func NewClient Uses

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

NewClient creates a new bytestream.Client.

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", buf.String())

func (*Client) NewReader Uses

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

NewReader creates a new Reader to read a resource.

func (*Client) NewReaderAt Uses

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

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

func (*Client) NewWriter Uses

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 Uses

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

Reader reads from a byte stream.

func (*Reader) Close Uses

func (r *Reader) Close() error

Close implements io.Closer.

func (*Reader) Read Uses

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 Uses

func (r *Reader) ResourceName() string

ResourceName gets the resource name this Reader is reading.

type Writer Uses

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

Writer writes to a byte stream.

func (*Writer) Close Uses

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 Uses

func (w *Writer) ResourceName() string

ResourceName gets the resource name this Writer is writing.

func (*Writer) Write Uses

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

Write implements io.Writer.

Directories

PathSynopsis
internal

Package bytestream imports 6 packages (graph). Updated 2019-09-20. Refresh now. Tools for package owners.