types

package
v0.0.0-...-c9fddc1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHash = hashSha256Name
)

Variables

This section is empty.

Functions

func IsRef

func IsRef(s string) bool

IsRef checks if string is a text representation of a Ref.

Types

type Pin

type Pin struct {
	Name string `json:"name"`
	Ref  Ref    `json:"ref"`
}

Pin is a named reference to a blob.

func (*Pin) References

func (p *Pin) References() []Ref

References implements schema.Object interface.

type Ref

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

Ref is a reference to a blob in content-addressable storage. It consists of a hash type and the hash data. Refs are comparable.

func BytesRef

func BytesRef(p []byte) Ref

BytesRef computes a Ref for a byte slice p.

func MakeRef

func MakeRef(name string, data []byte) (Ref, error)

MakeRef creates a ref with a specified hash algorithm and value.

func MustParseRef

func MustParseRef(s string) Ref

MustParseRef is the same as ParseRef, but panics on error.

func NewRef

func NewRef() Ref

NewRef creates a new zero ref with a default hash function.

Example:

ref := NewRef()
h := ref.Hash()
h.Write(p)
ref = ref.WithHash(h)

func ParseRef

func ParseRef(s string) (Ref, error)

ParseRef parses the string as a Ref.

func ParseRefBytes

func ParseRefBytes(s []byte) (Ref, error)

ParseRef parses byte slice as a string representation of a Ref.

func StringRef

func StringRef(s string) Ref

StringRef computes a Ref for a string s.

func (Ref) Data

func (r Ref) Data() []byte

Data returns the hash value of this ref.

func (Ref) Empty

func (r Ref) Empty() bool

Empty checks if this ref describes an empty blob (0 bytes).

func (Ref) GoString

func (r Ref) GoString() string

GoString returns a ref representation suitable for the use in the Go source code.

func (Ref) Hash

func (r Ref) Hash() hash.Hash

Hash initializes a new hash to populate the ref.

Example:

h := ref.Hash()
h.Write(p)
ref = ref.WithHash(h)

func (Ref) MarshalText

func (r Ref) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface.

func (Ref) Name

func (r Ref) Name() string

Name returns the name of the hash function used in this ref.

func (Ref) String

func (r Ref) String() string

String returns a string representation of a ref.

func (*Ref) UnmarshalText

func (r *Ref) UnmarshalText(s []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface.

func (Ref) WithHash

func (r Ref) WithHash(h hash.Hash) Ref

WithHash returns a ref that is described by the specified hash.

func (Ref) Zero

func (r Ref) Zero() bool

Zero checks if a ref is not initialized.

type SchemaRef

type SchemaRef struct {
	Ref  Ref    `json:"ref"`
	Size uint64 `json:"size,omitempty"`
	Type string `json:"type,omitempty"`
}

SchemaRef is a reference that describes a schema object. It stores the size of a schema object in bytes and the type of an object.

func (*SchemaRef) DataBlob

func (sr *SchemaRef) DataBlob() Ref

DataBlob implements schema.BlobWrapper interface.

func (*SchemaRef) References

func (sr *SchemaRef) References() []Ref

References implements schema.Object interface.

func (SchemaRef) SizedRef

func (sr SchemaRef) SizedRef() SizedRef

SizedRef converts SchemaRef to SizedRef by omitting the type.

type SizedRef

type SizedRef struct {
	Ref  Ref    `json:"ref"`
	Size uint64 `json:"size,omitempty"`
}

SizedRef is a object that combines a Ref and a size of a blob that it describes.

func Hash

func Hash(r io.Reader) (SizedRef, error)

Hash computes the ref for the specified reader.

func (*SizedRef) DataBlob

func (sr *SizedRef) DataBlob() Ref

DataBlob implements schema.BlobWrapper interface.

func (*SizedRef) References

func (sr *SizedRef) References() []Ref

References implements schema.Object interface.

Jump to

Keyboard shortcuts

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