Documentation
¶
Overview ¶
Package content provides implementations to access content stores.
Index ¶
- Variables
- func Equal(a, b ocispec.Descriptor) bool
- func FetchAll(ctx context.Context, fetcher Fetcher, desc ocispec.Descriptor) ([]byte, error)
- func NewDescriptorFromBytes(mediaType string, content []byte) ocispec.Descriptor
- func ReadAll(r io.Reader, desc ocispec.Descriptor) ([]byte, error)
- func Successors(ctx context.Context, fetcher Fetcher, node ocispec.Descriptor) ([]ocispec.Descriptor, error)
- type Deleter
- type Fetcher
- type FetcherFunc
- type GraphStorage
- type LimitedStorage
- type PredecessorFinder
- type Pusher
- type ReadOnlyGraphStorage
- type ReadOnlyStorage
- type Resolver
- type Storage
- type TagResolver
- type Tagger
- type Untagger
- type VerifyReader
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidDescriptorSize is returned by ReadAll() when // the descriptor has an invalid size. ErrInvalidDescriptorSize = errors.New("invalid descriptor size") // ErrMismatchedDigest is returned by ReadAll() when // the descriptor has an invalid digest. ErrMismatchedDigest = errors.New("mismatched digest") // ErrTrailingData is returned by ReadAll() when // there exists trailing data unread when the read terminates. ErrTrailingData = errors.New("trailing data") )
Functions ¶
func Equal ¶
func Equal(a, b ocispec.Descriptor) bool
Equal returns true if two descriptors point to the same content.
func FetchAll ¶
FetchAll safely fetches the content described by the descriptor. The fetched content is verified against the size and the digest.
func NewDescriptorFromBytes ¶
func NewDescriptorFromBytes(mediaType string, content []byte) ocispec.Descriptor
NewDescriptorFromBytes returns a descriptor, given the content and media type. If no media type is specified, "application/octet-stream" will be used.
func ReadAll ¶
ReadAll safely reads the content described by the descriptor. The read content is verified against the size and the digest using a VerifyReader.
func Successors ¶
func Successors(ctx context.Context, fetcher Fetcher, node ocispec.Descriptor) ([]ocispec.Descriptor, error)
Successors returns the nodes directly pointed by the current node. In other words, returns the "children" of the current descriptor.
Types ¶
type Deleter ¶
type Deleter interface { // Delete removes the content identified by the descriptor. Delete(ctx context.Context, target ocispec.Descriptor) error }
Deleter removes content. Deleter is an extension of Storage.
type Fetcher ¶
type Fetcher interface { // Fetch fetches the content identified by the descriptor. Fetch(ctx context.Context, target ocispec.Descriptor) (io.ReadCloser, error) }
Fetcher fetches content.
type FetcherFunc ¶
type FetcherFunc func(ctx context.Context, target ocispec.Descriptor) (io.ReadCloser, error)
FetcherFunc is the basic Fetch method defined in Fetcher.
func (FetcherFunc) Fetch ¶
func (fn FetcherFunc) Fetch(ctx context.Context, target ocispec.Descriptor) (io.ReadCloser, error)
Fetch performs Fetch operation by the FetcherFunc.
type GraphStorage ¶
type GraphStorage interface { Storage PredecessorFinder }
GraphStorage represents a CAS that supports direct predecessor node finding.
type LimitedStorage ¶
LimitedStorage represents a CAS with a push size limit.
func LimitStorage ¶
func LimitStorage(s Storage, n int64) *LimitedStorage
LimitStorage returns a storage with a push size limit.
func (*LimitedStorage) Push ¶
func (ls *LimitedStorage) Push(ctx context.Context, expected ocispec.Descriptor, content io.Reader) error
Push pushes the content, matching the expected descriptor. The size of the content cannot exceed the push size limit.
type PredecessorFinder ¶
type PredecessorFinder interface { // Predecessors returns the nodes directly pointing to the current node. Predecessors(ctx context.Context, node ocispec.Descriptor) ([]ocispec.Descriptor, error) }
PredecessorFinder finds out the nodes directly pointing to a given node of a directed acyclic graph. In other words, returns the "parents" of the current descriptor. PredecessorFinder is an extension of Storage.
type Pusher ¶
type Pusher interface { // Push pushes the content, matching the expected descriptor. // Reader is preferred to Writer so that the suitable buffer size can be // chosen by the underlying implementation. Furthermore, the implementation // can also do reflection on the Reader for more advanced I/O optimization. Push(ctx context.Context, expected ocispec.Descriptor, content io.Reader) error }
Pusher pushes content.
type ReadOnlyGraphStorage ¶
type ReadOnlyGraphStorage interface { ReadOnlyStorage PredecessorFinder }
ReadOnlyGraphStorage represents a read-only GraphStorage.
type ReadOnlyStorage ¶
type ReadOnlyStorage interface { Fetcher // Exists returns true if the described content exists. Exists(ctx context.Context, target ocispec.Descriptor) (bool, error) }
ReadOnlyStorage represents a read-only Storage.
type Resolver ¶
type Resolver interface { // Resolve resolves a reference to a descriptor. Resolve(ctx context.Context, reference string) (ocispec.Descriptor, error) }
Resolver resolves reference tags.
type Storage ¶
type Storage interface { ReadOnlyStorage Pusher }
Storage represents a content-addressable storage (CAS) where contents are accessed via Descriptors. The storage is designed to handle blobs of large sizes.
type TagResolver ¶
TagResolver provides reference tag indexing services.
type Tagger ¶
type Tagger interface { // Tag tags a descriptor with a reference string. Tag(ctx context.Context, desc ocispec.Descriptor, reference string) error }
Tagger tags reference tags.
type Untagger ¶ added in v2.4.0
type Untagger interface { // Untag untags the given reference string. Untag(ctx context.Context, reference string) error }
Untagger untags reference tags.
type VerifyReader ¶
type VerifyReader struct {
// contains filtered or unexported fields
}
VerifyReader reads the content described by its descriptor and verifies against its size and digest.
Example ¶
ExampleVerifyReader gives an example of creating and using VerifyReader.
package main import ( "bytes" "fmt" "io" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras-go/v2/content" ) func main() { blob := []byte("hello world") desc := content.NewDescriptorFromBytes(ocispec.MediaTypeImageLayer, blob) r := bytes.NewReader(blob) vr := content.NewVerifyReader(r, desc) buf := bytes.NewBuffer(nil) if _, err := io.Copy(buf, vr); err != nil { panic(err) } // note: users should not trust the the read content until // Verify() returns nil. if err := vr.Verify(); err != nil { panic(err) } fmt.Println(buf) }
Output: hello world
func NewVerifyReader ¶
func NewVerifyReader(r io.Reader, desc ocispec.Descriptor) *VerifyReader
NewVerifyReader wraps r for reading content with verification against desc.
func (*VerifyReader) Read ¶
func (vr *VerifyReader) Read(p []byte) (n int, err error)
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.
func (*VerifyReader) Verify ¶
func (vr *VerifyReader) Verify() error
Verify checks for remaining unread content and verifies the read content against the digest
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package file provides implementation of a content store based on file system.
|
Package file provides implementation of a content store based on file system. |
Package memory provides implementation of a memory backed content store.
|
Package memory provides implementation of a memory backed content store. |
Package oci provides access to an OCI content store.
|
Package oci provides access to an OCI content store. |