blobaccess

package
v0.0.0-...-877fc11 Latest Latest
Warning

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

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

Documentation

Overview

Package blobaccess provides the basic set of the most commonly needed BlobAccess implementations.

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 DataFromProvider

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

DataFromProvider extracts the data for a given BlobAccess provider.

func Digest

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

func ErrBlobNotFound

func ErrBlobNotFound(digest digest.Digest) error

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 ProviderForBlobAccess

func ProviderForBlobAccess(blob 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 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.

Types

type AnnotatedBlobAccess

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

AnnotatedBlobAccess provides access to the original underlying data source.

func ForDataAccess

func ForDataAccess[T 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.

type BlobAccess

type BlobAccess = internal.BlobAccess

func ForCachedBlobAccess

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

func ForData

func ForData(media string, data []byte) BlobAccess

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

func ForFile

func ForFile(mime string, path string, fss ...vfs.FileSystem) BlobAccess

ForFile wraps a file path into a BlobAccess, which does not need a close.

func ForFileWithCloser

func ForFileWithCloser(closer io.Closer, mime string, path string, fss ...vfs.FileSystem) BlobAccess

func ForString

func ForString(media string, data string) BlobAccess

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

func ForTemporaryFile

func ForTemporaryFile(mime string, temp vfs.File, fss ...vfs.FileSystem) BlobAccess

func ForTemporaryFilePath

func ForTemporaryFilePath(mime string, temp string, fss ...vfs.FileSystem) BlobAccess

func ForTemporaryFilePathWithMeta

func ForTemporaryFilePathWithMeta(mime string, digest digest.Digest, size int64, temp string, fss ...vfs.FileSystem) BlobAccess

func ForTemporaryFileWithMeta

func ForTemporaryFileWithMeta(mime string, digest digest.Digest, size int64, temp vfs.File, fss ...vfs.FileSystem) BlobAccess

func NonClosable

func NonClosable(blob BlobAccess) BlobAccess

func WithCompression

func WithCompression(blob BlobAccess) (BlobAccess, error)

func WithDecompression

func WithDecompression(blob BlobAccess) (BlobAccess, error)

func WithMimeType

func WithMimeType(mimeType string, blob BlobAccess) 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.

type BlobAccessProvider

type BlobAccessProvider = internal.BlobAccessProvider

func ProviderForData

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

func ProviderForFile

func ProviderForFile(mime string, path string, fss ...vfs.FileSystem) BlobAccessProvider

func ProviderForString

func ProviderForString(mime, data string) BlobAccessProvider

type DataAccess

type DataAccess = internal.DataAccess

func DataAccessForFile

func DataAccessForFile(fs vfs.FileSystem, path string) 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 interface {
	DataAccess
	Origin() string
}

DataSource describes some data plus its origin.

func DataAccessForBytes

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

func DataAccessForString

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

type DigestSource

type DigestSource = internal.DigestSource

type FileLocation

type FileLocation = internal.FileLocation

type GenericData

type GenericData interface{}

type GenericDataGetter

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

type MimeType

type MimeType = internal.MimeType

type TempFile

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

TempFile holds a temporary file that should be kept open. Close should never be called directly. It can be passed to another responsibility realm by calling Release For example to be transformed into a TemporaryBlobAccess. Close will close and remove an unreleased file and does nothing if it has been released. If it has been releases the new realm is responsible. to close and remove it.

func NewTempFile

func NewTempFile(dir string, pattern string, fss ...vfs.FileSystem) (*TempFile, error)

func (*TempFile) AsBlob

func (t *TempFile) AsBlob(mime string) BlobAccess

func (*TempFile) Close

func (t *TempFile) Close() error

func (*TempFile) FileSystem

func (t *TempFile) FileSystem() vfs.FileSystem

func (*TempFile) Name

func (t *TempFile) Name() string

func (*TempFile) Release

func (t *TempFile) Release() vfs.File

func (*TempFile) Sync

func (t *TempFile) Sync() error

func (*TempFile) Writer

func (t *TempFile) Writer() io.Writer

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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