bufcas

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DigestEqual

func DigestEqual(a Digest, b Digest) bool

DigestEqual returns true if the given Digests are considered equal.

If both Digests are nil, this returns true.

This check both the DigestType and Digest value.

func PutFileSetToBucket

func PutFileSetToBucket(
	ctx context.Context,
	fileSet FileSet,
	bucket storage.WriteBucket,
) error

PutFileSetToBucket writes the FileSet to the given WriteBucket.

Types

type Blob

type Blob interface {
	// Digest returns the Digest of the Blob.
	//
	// Always non-nil.
	//
	// NewDigestForContent(bytes.NewReader(blob.Content())) should always match this value.
	Digest() Digest
	// Content returns the content of the Blob.
	//
	// May be empty.
	Content() []byte
	// contains filtered or unexported methods
}

Blob is content with its associated Digest.

func ManifestToBlob

func ManifestToBlob(manifest Manifest) (Blob, error)

ManifestToBlob converts the string representation of the given Manifest into a Blob.

The Manifest is assumed to be non-nil.

func NewBlobForContent

func NewBlobForContent(reader io.Reader, options ...BlobOption) (Blob, error)

NewBlobForContent returns a new Blob for the content as read from the Reader.

The reader is read until io.EOF.

type BlobOption

type BlobOption func(*blobOptions)

BlobOption is an option when constructing a new Blob

func BlobWithDigestType

func BlobWithDigestType(digestType DigestType) BlobOption

BlobWithDigestType returns a new BlobOption sets the DigestType to be used.

The default is DigestTypeShake256.

func BlobWithKnownDigest

func BlobWithKnownDigest(knownDigest Digest) BlobOption

BlobWithKnownDigest returns a new BlobOption that results in validation that the Digest for the new Blob matches an existing known Digest.

type BlobSet

type BlobSet interface {
	// GetBlob gets the Blob for the given Digest, or nil if no such Blob exists.
	GetBlob(digest Digest) Blob
	// Blobs returns the Blobs associated with this BlobSet, ordered by
	// the sort value of the Digest.
	//
	// TODO: The former version of this package returns the Blobs in unspecified
	// order. We generally try to give a deterministic order in our codebase. There
	// are schools of arguments both ways, but we'd like to stay consistent.
	Blobs() []Blob
	// contains filtered or unexported methods
}

BlobSet is a set of deduplicated Blobs.

func NewBlobSet

func NewBlobSet(blobs []Blob) (BlobSet, error)

NewBlobSet returns a new BlobSet.

Blobs are deduplicated upon construction.

type Digest

type Digest interface {
	// String() prints typeString:hexValue.
	fmt.Stringer

	// Type returns the type of digest.
	// Always a valid value.
	Type() DigestType
	// Value returns the digest value.
	//
	// Always non-empty.
	Value() []byte
	// contains filtered or unexported methods
}

Digest is a digest of some content.

It consists of a DigestType and a digest value.

func ManifestToDigest added in v1.29.0

func ManifestToDigest(manifest Manifest) (Digest, error)

ManifestToDigest converts the string representation of the given Manifest into a Digest.

The Manifest is assumed to be non-nil.

func NewDigest added in v1.29.0

func NewDigest(value []byte, options ...DigestOption) (Digest, error)

NewDigest returns a new Digest for the value.

func NewDigestForContent

func NewDigestForContent(reader io.Reader, options ...DigestOption) (Digest, error)

NewDigestForContent creates a new Digest based on the given content read from the Reader.

A valid Digest is returned, even in the case of empty content.

The Reader is read until io.EOF.

func ParseDigest

func ParseDigest(s string) (Digest, error)

ParseDigest parses a Digest from its string representation.

A Digest string is of the form typeString:hexValue. The string is expected to be non-empty, If not, an error is treutned.

This reverses Digest.String().

type DigestOption

type DigestOption func(*digestOptions)

DigestOption is an option for a new Digest.

func DigestWithDigestType

func DigestWithDigestType(digestType DigestType) DigestOption

DigestWithDigestType returns a new DigestOption that specifies the DigestType to be used.

The default is DigestTypeShake256.

type DigestType

type DigestType int

DigestType is a type of digest.

const (
	// DigestTypeShake256 represents the shake256 digest type.
	//
	// This is both the default and the only currently-known value for DigestType.
	DigestTypeShake256 DigestType = iota + 1
)

func ParseDigestType

func ParseDigestType(s string) (DigestType, error)

ParseDigestType parses a DigestType from its string representation.

This reverses DigestType.String().

Returns an error of type *ParseError if thie string could not be parsed.

func (DigestType) String

func (d DigestType) String() string

String prints the string representation of the DigestType.

type FileNode

type FileNode interface {
	// String encodes the FileNode into its canonical form:
	//
	//   digestString[SP][SP]path
	fmt.Stringer

	// Path returns the Path of the file.
	//
	// The path is normalized and non-empty.
	Path() string
	// Digest returns the Digest of the file.
	//
	// The Digest is always non-nil.
	Digest() Digest
	// contains filtered or unexported methods
}

FileNode is a path and associated digest.

func NewFileNode

func NewFileNode(path string, digest Digest) (FileNode, error)

NewFileNode returns a new FileNode.

The path is validated to be normalized and non-empty. The digest is validated to be non-nil.

func ParseFileNode

func ParseFileNode(s string) (FileNode, error)

ParseFileNode parses the FileNode from its string representation.

The string representation is "digestString[SP][SP]path".

This reverses FileNode.String().

type FileSet

type FileSet interface {
	// Manifest returns the associated Manifest.
	Manifest() Manifest
	// BlobSet returns the associated BlobSet.
	BlobSet() BlobSet
	// contains filtered or unexported methods
}

FileSet is a pair of a Manifest and its associated BlobSet.

This can be read and written from and to a storage.Bucket.

The Manifest is guaranteed to exactly correlate with the Blobs in the BlobSet, that is the Digests of the FileNodes in the Manifest will exactly match the Digests in the Blobs.

func NewFileSet

func NewFileSet(manifest Manifest, blobSet BlobSet) (FileSet, error)

NewFileSet returns a new FileSet.

Validation is done to ensure the Manifest exactly matches the BlobSet.

func NewFileSetForBucket

func NewFileSetForBucket(ctx context.Context, bucket storage.ReadBucket) (FileSet, error)

NewFileSetForBucket returns a new FileSet for the given ReadBucket.

type Manifest

type Manifest interface {
	// fmt.Stringer encodes the Manifest into its canonical form, consisting of
	// an sorted list of paths and their digests, sorted by path.
	//
	// See the documentation on FileNode for how FileNodes are encoded.
	//
	// An example encoded manifest:
	//
	//	shake256:cd22db48cf7c274bbffcb5494a854000cd21b074df7c6edabbd0102c4be8d7623e3931560fcda7acfab286ae1d4f506911daa31f223ee159f59ffce0c7acbbaa  buf.lock
	//	shake256:3b353aa5aacd11015e8577f16e2c4e7a242ce773d8e3a16806795bb94f76e601b0db9bf42d5e1907fda63303e1fa1c65f1c175ecc025a3ef29c3456ad237ad84  buf.md
	//	shake256:7c88a20cf931702d042a4ddee3fde5de84814544411f1c62dbf435b1b81a12a8866a070baabcf8b5a0d31675af361ccb2d93ddada4cdcc11bab7ea3d8d7c4667  buf.yaml
	//	shake256:9db25155eafd19b36882cff129daac575baa67ee44d1cb1fd3894342b28c72b83eb21aa595b806e9cb5344759bc8308200c5af98e4329aa83014dde99afa903a  pet/v1/pet.proto
	fmt.Stringer

	// FileNodes returns the set of FileNodes that make up the Manifest.
	//
	// The paths of the given FileNodes are guaranteed to be unique.
	// The iteration order will be the sorted order of the paths.
	FileNodes() []FileNode
	// GetFileNode gets the FileNode for the given path.
	//
	// Returns nil if the path does not exist.
	GetFileNode(path string) FileNode
	// GetDigest gets the Digest for the given path.
	//
	// Returns nil if the path does not exist.
	GetDigest(path string) Digest
	// contains filtered or unexported methods
}

Manifest is a set of FileNodes.

func BlobToManifest

func BlobToManifest(blob Blob) (Manifest, error)

BlobToManifest converts the given Blob representing the string representation of a Manifest into a Manifest.

The Blob is assumed to be non-nil

This function returns ParseErrors since this is effectively parsing the blob.

func NewManifest

func NewManifest(fileNodes []FileNode) (Manifest, error)

NewManifest returns a new Manifest for the given path -> Digest map.

FileNodes are deduplicated upon construction, however if two FileNodes with the same path have different Digests, an error is returned.

func ParseManifest

func ParseManifest(s string) (Manifest, error)

ParseManifest parses a Manifest from its string representation.

This reverses Manifest.String().

type ParseError added in v1.28.1

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

ParseError is an error that occurred during parsing.

This is returned by all Parse.* functions in this package.

func (*ParseError) Error added in v1.28.1

func (p *ParseError) Error() string

Error implements the error interface.

func (*ParseError) Input added in v1.28.1

func (p *ParseError) Input() string

Input returns the input string that was attempted to be parsed.

func (*ParseError) Unwrap added in v1.28.1

func (p *ParseError) Unwrap() error

Unwrap returns the underlying error.

Jump to

Keyboard shortcuts

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