download

package
v0.0.0-...-2b7c813 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// PartSize is the number of bytes that a object part has, currently 5MB per part.
	PartSize = 5 << 20
)

Variables

View Source
var ErrBufferLength error = fmt.Errorf("len(p) is required to be at least %d", PartSize)

ErrBufferLength is the error returned by StreamReadCloser.Read when len(p) <= PartSize.

Functions

This section is empty.

Types

type Service

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

Service is a structure used for downloading objects from S3.

func NewService

func NewService(s3Client *s3.S3, logger *logrus.Logger) *Service

NewService creates a Service and returns it.

func (Service) Download

func (s Service) Download(req *pb.DownloadRequest, stream pb.Download_DownloadServer) error

Download is the request to download a object from S3. It receives a request for a object. Responds with a stream of the object bytes in chunks.

func (Service) GetS3Client

func (s Service) GetS3Client() *s3.S3

GetS3Client returns the internal s3 client.

type StreamReadCloser

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

StreamReadCloser is a structure that implements io.Reader to read a object's bytes from stream.

func NewStreamReadCloser

func NewStreamReadCloser(stream pb.Download_DownloadClient) StreamReadCloser

NewStreamReadCloser returns a StreamReadCloser initialized with stream to read the object's bytes from.

func (StreamReadCloser) Close

func (r StreamReadCloser) Close() error

Close closes the send direction of the underlying r.stream.

func (StreamReadCloser) Read

func (r StreamReadCloser) Read(p []byte) (n int, err error)

Read implements io.Reader to read object's bytes into p, len(p) MUST be >= PartSize, otherwise Read wouldn't read the chunk into p, Read doesn't call r.stream.Recv() unless len(p) >= PartSize. If Read would've read the chunk into p where len(p) < PartSize, it would read incomplete object bytes into p and the reader would miss bytes from the object stream. Implementation does not retain p.

Jump to

Keyboard shortcuts

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