blobaccess

package
v0.19.0 Latest Latest
Warning

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

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

Documentation

Overview

Package blobaccess provides the basic set of types and supporting functions for using BlobAccess implementations. It is intended to be used by generic BlobAccess users not referring to dedicated implementations. Dedicated implementations can be accessed using the appropriate implementation package. This separation is required to avoid cycles for BlobAccess implementations using again BlobAccess objects. Alternatively, the parent package can be used, if there are no cycles. The parent package provides the basic functionality plus access to various implementation flavors in one package to offer a simplified discovery of available implementations .

Package blobutils provides some utility types and functions for blobaccesses, which cannot be put into the blobaccess package, because this would introduce cycles in some blobaccess implementation packages.

Index

Constants

View Source
const (
	KIND_BLOB      = internal.KIND_BLOB
	KIND_MEDIATYPE = internal.KIND_MEDIATYPE

	BLOB_UNKNOWN_SIZE   = internal.BLOB_UNKNOWN_SIZE
	BLOB_UNKNOWN_DIGEST = internal.BLOB_UNKNOWN_DIGEST
)
View Source
const KIND_DATASOURCE = "data source"

Variables

View Source
var ErrClosed = refmgmt.ErrClosed

Functions

func BlobData

func BlobData(blob DataGetter, err ...error) ([]byte, error)

BlobData can be applied directly to a function result providing a BlobAccess to get the data for the provided blob. If the blob access providing function provides an error result it is passed to the caller.

func BlobReader

func BlobReader(blob DataReader, err ...error) (io.ReadCloser, error)

BlobReader can be applied directly to a function result providing a BlobAccess to get a reader for the provided blob. If the blob access providing function provides an error result it is passed to the caller.

func Cast

func Cast[I interface{}](acc BlobAccess) I

func DataAccessForData

func DataAccessForData(data []byte, origin ...string) bpi.DataSource

func DataAccessForString

func DataAccessForString(data string, origin ...string) bpi.DataSource

func DataFromProvider

func DataFromProvider(s BlobAccessProvider) ([]byte, error)

DataFromProvider extracts the data for a given BlobAccess provider.

func Digest

func Digest(access bpi.DataAccess) (digest.Digest, error)

func ErrBlobNotFound

func ErrBlobNotFound(digest digest.Digest) error

func ForData

func ForData(mime string, data []byte) bpi.BlobAccess

ForData wraps data into a BlobAccess, which does not need a close.

func ForString

func ForString(mime string, data string) bpi.BlobAccess

ForString wraps a string into a BlobAccess, which does not need a close.

func GetData

func GetData(src GenericData) ([]byte, error)

GetData provides data as byte sequence from some generic data sources like byte arrays, strings, DataReader and DataGetters. This means we can pass all BlobAccess or DataAccess objects. If no an unknown data source is passes an ErrInvalid(KIND_DATASOURCE) is returned.

func GetGenericData

func GetGenericData(src GenericData) (interface{}, error)

GetGenericData evaluates some input provided by well-known types or interfaces and provides some data output by mapping the input to either a byte sequence or some specialized object. If the input type is not known an ErrInvalid(KIND_DATASOURCE) // is returned. In extension to GetData, it additionally evaluates the interface GenericDataGetter to map the input to some evaluated object.

func IsErrBlobNotFound

func IsErrBlobNotFound(err error) bool

func MimeReaderFromProvider

func MimeReaderFromProvider(s BlobAccessProvider) (io.ReadCloser, string, error)

MimeReaderFromProvider gets a reader for a BlobAccess provided by a BlobAccesssProvider. Closing the Reader also closes the BlobAccess. Additionally, the mime type of the blob is returned.

func NonClosable

func NonClosable(blob bpi.BlobAccess) bpi.BlobAccess

func ProviderForBlobAccess

func ProviderForBlobAccess(blob bpi.BlobAccess) *blobprovider

ProviderForBlobAccess provides subsequent bloc accesses as long as the given blob access is not closed. If required the blob can be closed with the additionally provided Close method. ATTENTION: the underlying BlobAccess wil not be closed as long as the provider is not closed, but the BlobProvider interface is no io.Closer. To be on the safe side, this method should only be called with static blob access, featuring a NOP closer without anny attached external resources, which should be released.

func ProviderForData

func ProviderForData(mime string, data []byte) bpi.BlobAccessProvider

func ProviderForString

func ProviderForString(mime, data string) bpi.BlobAccessProvider

func ReaderFromProvider

func ReaderFromProvider(s BlobAccessProvider) (io.ReadCloser, error)

ReaderFromProvider gets a reader for a BlobAccess provided by a BlobAccesssProvider. Closing the Reader also closes the BlobAccess.

func Validate

func Validate(o BlobAccess) error

Validate checks whether a blob access is in error state. If yes, an appropriate error is returned.

func WithCompression

func WithCompression(blob bpi.BlobAccess) (bpi.BlobAccess, error)

func WithDecompression

func WithDecompression(blob bpi.BlobAccess) (bpi.BlobAccess, error)

func WithMimeType

func WithMimeType(mimeType string, blob bpi.BlobAccess) bpi.BlobAccess

WithMimeType changes the mime type for a blob access by wrapping the given blob access. It does NOT provide a new view for the given blob access, so closing the resulting blob access will directly close the backing blob access.

Types

type AnnotatedBlobAccess

type AnnotatedBlobAccess[T bpi.DataAccess] interface {
	Source() T
	// contains filtered or unexported methods
}

AnnotatedBlobAccess provides access to the original underlying data source.

func ForDataAccess

func ForDataAccess[T bpi.DataAccess](digest digest.Digest, size int64, mimeType string, access T) AnnotatedBlobAccess[T]

ForDataAccess wraps the general access object into a blob access. It closes the wrapped access, if closed. If the wrapped data access does not need a close, the BlobAccess does not need a close, also. It adds the additional blob access metadata (mime, digest, and size). Digest and size can be set to unknown using the constants (BLOB_UNKNOWN_DIGEST and BLOB_UNKNOWN_SIZE).

type BlobAccess

type BlobAccess = internal.BlobAccess

func ForCachedBlobAccess

func ForCachedBlobAccess(blob BlobAccess, fss ...vfs.FileSystem) (BlobAccess, error)

type BlobAccessProvider

type BlobAccessProvider = internal.BlobAccessProvider

type DataAccess

type DataAccess = internal.DataAccess

func DataAccessForReaderFunction

func DataAccessForReaderFunction(reader func() (io.ReadCloser, error), origin string) DataAccess

type DataGetter

type DataGetter = internal.DataGetter

type DataReader

type DataReader = internal.DataReader

type DataSource

type DataSource = internal.DataSource

type DigestSource

type DigestSource = internal.DigestSource

type FileLocation

type FileLocation = internal.FileLocation

type GenericData

type GenericData = interface{}

type GenericDataGetter

type GenericDataGetter interface {
	Get() (GenericData, error)
}

type MimeType

type MimeType = internal.MimeType

type Validatable

type Validatable = utils.Validatable

Validatable is an optional interface for DataAccess implementations or any other object, which might reach an error state. The error can then be queried with the method ErrorProvider.Validate. This is used to support objects with access methods not returning an error. If the object is not valid, those methods return an unknown/default state, but the object should be queryable for its state.

Jump to

Keyboard shortcuts

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