digest

package
v0.0.0-...-636a2a8 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package digest handles content digests of remote executon API.

You can find the Digest proto in REAPI here: https://github.com/bazelbuild/remote-apis/blob/c1c1ad2c97ed18943adb55f06657440daa60d833/build/bazel/remote/execution/v2/remote_execution.proto#L633

Index

Constants

This section is empty.

Variables

View Source
var Empty = ofBytes([]byte{})

Empty is a digest of empty content.

Functions

func DataToBytes

func DataToBytes(ctx context.Context, d Data) ([]byte, error)

DataToBytes returns byte values from a Data. Note that it reads all content. It should not be used for large blob.

Types

type Data

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

Data is a data instance that consists of Digest and Source. TODO(b/268407930): it may be possible to be merged with Source.

func FromBytes

func FromBytes(name string, b []byte) Data

FromBytes creates data from raw byte values.

func FromLocalFile

func FromLocalFile(ctx context.Context, src Source) (Data, error)

FromLocalFile creates Data from local file source. it requires LocalFileSource because it doesn't handle retriable err from src.

func FromProtoMessage

func FromProtoMessage(m proto.Message) (Data, error)

FromProtoMessage creates Data from proto message.

func NewData

func NewData(src Source, d Digest) Data

NewData creates a Data from source and digest.

func (Data) Digest

func (d Data) Digest() Digest

Digest returns the Digest of the data.

func (Data) IsZero

func (d Data) IsZero() bool

IsZero returns true when the Data is zero value struct.

func (Data) Open

func (d Data) Open(ctx context.Context) (io.ReadCloser, error)

Open opens the data source.

func (Data) String

func (d Data) String() string

String returns the digest and the source in string format.

type Digest

type Digest struct {
	Hash      string `json:"hash,omitempty"`
	SizeBytes int64  `json:"size_bytes,omitempty"`
}

Digest is a digest.

func FromProto

func FromProto(d *rpb.Digest) Digest

FromProto converts from digest proto.

func Parse

func Parse(s string) (Digest, error)

Parse parses digest string representation. It accepts the following string formats.

  • hash/size_bytes
  • json representation of digest.
  • proto text representation of digest.

func (Digest) IsZero

func (d Digest) IsZero() bool

IsZero returns true when digest is zero value (equivalent with nil digest proto).

func (Digest) Proto

func (d Digest) Proto() *rpb.Digest

Proto returns digest proto.

func (Digest) String

func (d Digest) String() string

String returns string representation of the digest (hash/sizes_bytes).

type LocalFileSource

type LocalFileSource interface {
	Source
	IsLocal()
}

LocalFileSource is a source for local file.

type Source

type Source interface {
	// Open returns io.ReadCloser of the source.
	Open(context.Context) (io.ReadCloser, error)

	// String returns the name of the data source.
	String() string
}

Source is the interface that opens a data source. It can be remote or local source. If this interface is implemented based on gRPC streaming for remote sources, the caller may need to retry Open/Read/Close in addition.

type Store

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

Store works as an in-memory content addressable storage.

func NewStore

func NewStore() *Store

NewStore creates Store.

func (*Store) Delete

func (s *Store) Delete(digest Digest)

Delete deletes digest from the store.

func (*Store) Get

func (s *Store) Get(digest Digest) (Data, bool)

Get gets data from store by the digest.

func (*Store) GetSource

func (s *Store) GetSource(digest Digest) (Source, bool)

GetSource gets source from the store.

func (*Store) List

func (s *Store) List() []Digest

List returns a list of the digests of the stored data.

func (*Store) Set

func (s *Store) Set(d Data)

Set sets data to the store.

func (*Store) Size

func (s *Store) Size() int

Size returns the number of digests in the store.

Jump to

Keyboard shortcuts

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