accessobj

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACC_WRITABLE = AccessMode(0)
	ACC_READONLY = AccessMode(1)
	ACC_CREATE   = AccessMode(2)
)
View Source
const (
	DirMode  = 0o755
	FileMode = 0o644
)
View Source
const KIND_FILEFORMAT = accessio.KIND_FILEFORMAT

Variables

View Source
var ErrReadOnly = accessio.ErrReadOnly
View Source
var FormatDirectory = DirectoryHandler{}
View Source
var FormatTAR = NewTarHandler()
View Source
var ModTime = time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)

Functions

func CachedBlobAccessForDataAccess

func CachedBlobAccessForDataAccess(ctx datacontext.Context, mime string, src blobaccess.DataAccess) blobaccess.BlobAccess

func CachedBlobAccessForWriter

func CachedBlobAccessForWriter(ctx datacontext.Context, mime string, src accessio.DataWriter) blobaccess.BlobAccess

func CheckFile

func CheckFile(kind string, createHint string, forcedType bool, path string, fs vfs.FileSystem, descriptorname string) (bool, bool, error)

CheckFile returns create, acceptable, error.

func GetFormats

func GetFormats() map[accessio.FileFormat]FormatHandler

func HandleAccessMode

func HandleAccessMode(acc AccessMode, path string, opts accessio.Options, olist ...accessio.Option) (accessio.Options, bool, error)

func InternalRepresentationFilesystem

func InternalRepresentationFilesystem(acc AccessMode, fs vfs.FileSystem, setup FilesystemSetup, mode vfs.FileMode) (bool, vfs.FileSystem, error)

InternalRepresentationFilesystem defaults a filesystem to temp filesystem and adapts.

func MapType added in v0.5.0

func MapType(hint string, efftyp string, deffmt accessio.FileFormat, useFormats bool, alt ...string) (string, accessio.FileFormat)

MapType maps a given type name to an effective type and a format.

func RegisterFormat

func RegisterFormat(f FormatHandler)

Types

type AccessMode

type AccessMode byte

func (AccessMode) IsCreate

func (m AccessMode) IsCreate() bool

func (AccessMode) IsReadonly

func (m AccessMode) IsReadonly() bool

type AccessObject

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

AccessObject provides a basic functionality for descriptor based access objects using a virtual filesystem for the internal representation.

func DefaultCreateOptsFileHandling

func DefaultCreateOptsFileHandling(kind string, info AccessObjectInfo, path string, opts accessio.Options, mode vfs.FileMode, handler StandardReaderHandler) (*AccessObject, error)

func DefaultOpenOptsFileHandling

func DefaultOpenOptsFileHandling(kind string, info AccessObjectInfo, acc AccessMode, path string, opts accessio.Options, handler StandardReaderHandler) (*AccessObject, error)

func NewAccessObject

func NewAccessObject(info AccessObjectInfo, acc AccessMode, fs vfs.FileSystem, setup Setup, closer Closer, mode vfs.FileMode) (*AccessObject, error)

func (*AccessObject) Close

func (a *AccessObject) Close() error

func (*AccessObject) GetFileSystem

func (a *AccessObject) GetFileSystem() vfs.FileSystem

func (*AccessObject) GetInfo

func (a *AccessObject) GetInfo() AccessObjectInfo

func (*AccessObject) GetMode

func (a *AccessObject) GetMode() vfs.FileMode

func (*AccessObject) GetState

func (a *AccessObject) GetState() State

func (*AccessObject) IsClosed

func (a *AccessObject) IsClosed() bool

func (*AccessObject) IsReadOnly

func (a *AccessObject) IsReadOnly() bool

func (*AccessObject) SetReadOnly added in v0.9.0

func (a *AccessObject) SetReadOnly()

func (*AccessObject) Update

func (a *AccessObject) Update() error

func (*AccessObject) Write

func (a *AccessObject) Write(path string, mode vfs.FileMode, opts ...accessio.Option) error

type AccessObjectInfo

type AccessObjectInfo interface {
	SetupFor(fs vfs.FileSystem) error
	GetDescriptorFileName() string
	GetObjectTypeName() string
	GetElementTypeName() string
	GetElementDirectoryName() string
	GetAdditionalFiles(fs vfs.FileSystem) []string
	SetupFileSystem(fs vfs.FileSystem, mode vfs.FileMode) error
	SetupDescriptorState(fs vfs.FileSystem) StateHandler
	SubPath(name string) string
}

AccessObjectInfo is used to control the persistence of a serialization format for sets of elements.

type BlobStateAccess

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

BlobStateAccess provides state handling for data given by a blob access.

func (*BlobStateAccess) Digest

func (b *BlobStateAccess) Digest() digest.Digest

func (*BlobStateAccess) Get

func (*BlobStateAccess) Put

func (b *BlobStateAccess) Put(data []byte) error

type CachedBlobAccess

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

func (*CachedBlobAccess) Close

func (c *CachedBlobAccess) Close() error

func (*CachedBlobAccess) Digest

func (c *CachedBlobAccess) Digest() digest.Digest

func (*CachedBlobAccess) DigestKnown

func (c *CachedBlobAccess) DigestKnown() bool

func (*CachedBlobAccess) Get

func (c *CachedBlobAccess) Get() ([]byte, error)

func (*CachedBlobAccess) MimeType

func (c *CachedBlobAccess) MimeType() string

func (*CachedBlobAccess) Reader

func (c *CachedBlobAccess) Reader() (io.ReadCloser, error)

func (*CachedBlobAccess) Size

func (c *CachedBlobAccess) Size() int64

type Closer

type Closer interface {
	Close(*AccessObject) error
}

type CloserFunction

type CloserFunction func(*AccessObject) error

func (CloserFunction) Close

func (f CloserFunction) Close(obj *AccessObject) error

type DefaultAccessObjectInfo

type DefaultAccessObjectInfo struct {
	DescriptorFileName       string
	ObjectTypeName           string
	ElementDirectoryName     string
	ElementTypeName          string
	DescriptorHandlerFactory DescriptorHandlerFactory
	AdditionalFiles          []string
}

DefaultAccessObjectInfo is a default implementation for AccessObjectInfo that can be used to describe a simple static configuration. The methods do not change the content, therefore an instance can be reused.

func (*DefaultAccessObjectInfo) GetAdditionalFiles

func (i *DefaultAccessObjectInfo) GetAdditionalFiles(fs vfs.FileSystem) []string

func (*DefaultAccessObjectInfo) GetDescriptorFileName

func (i *DefaultAccessObjectInfo) GetDescriptorFileName() string

func (*DefaultAccessObjectInfo) GetElementDirectoryName

func (i *DefaultAccessObjectInfo) GetElementDirectoryName() string

func (*DefaultAccessObjectInfo) GetElementTypeName

func (i *DefaultAccessObjectInfo) GetElementTypeName() string

func (*DefaultAccessObjectInfo) GetObjectTypeName

func (i *DefaultAccessObjectInfo) GetObjectTypeName() string

func (*DefaultAccessObjectInfo) SetupDescriptorState

func (i *DefaultAccessObjectInfo) SetupDescriptorState(fs vfs.FileSystem) StateHandler

func (*DefaultAccessObjectInfo) SetupFileSystem

func (i *DefaultAccessObjectInfo) SetupFileSystem(fs vfs.FileSystem, mode vfs.FileMode) error

func (*DefaultAccessObjectInfo) SetupFor

func (i *DefaultAccessObjectInfo) SetupFor(fs vfs.FileSystem) error

func (*DefaultAccessObjectInfo) SubPath

func (i *DefaultAccessObjectInfo) SubPath(name string) string

type DescriptorHandlerFactory

type DescriptorHandlerFactory func(fs vfs.FileSystem) StateHandler

type DirectoryHandler

type DirectoryHandler struct{}

func (DirectoryHandler) ApplyOption

func (o DirectoryHandler) ApplyOption(options accessio.Options) error

ApplyOption applies the configured path filesystem.

func (DirectoryHandler) Create

func (_ DirectoryHandler) Create(info AccessObjectInfo, path string, opts accessio.Options, mode vfs.FileMode) (*AccessObject, error)

func (DirectoryHandler) Format

func (DirectoryHandler) Open

func (DirectoryHandler) Write

func (_ DirectoryHandler) Write(obj *AccessObject, path string, opts accessio.Options, mode vfs.FileMode) error

WriteToFilesystem writes the current object to a filesystem.

type FileFormat

type FileFormat = accessio.FileFormat

type FileSystemBlobAccess

type FileSystemBlobAccess struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewFileSystemBlobAccess

func NewFileSystemBlobAccess(access *AccessObject) *FileSystemBlobAccess

func (*FileSystemBlobAccess) Access

func (a *FileSystemBlobAccess) Access() *AccessObject

func (*FileSystemBlobAccess) AddBlob

func (*FileSystemBlobAccess) BlobPath

func (a *FileSystemBlobAccess) BlobPath(name string) string

BlobPath returns the path to the blob for a given name.

func (*FileSystemBlobAccess) Close

func (a *FileSystemBlobAccess) Close() error

func (*FileSystemBlobAccess) DigestPath

func (a *FileSystemBlobAccess) DigestPath(digest digest.Digest) string

DigestPath returns the path to the blob for a given name.

func (*FileSystemBlobAccess) GetBlobData

func (a *FileSystemBlobAccess) GetBlobData(digest digest.Digest) (int64, blobaccess.DataAccess, error)

func (*FileSystemBlobAccess) GetBlobDataByName

func (a *FileSystemBlobAccess) GetBlobDataByName(name string) (blobaccess.DataAccess, error)

func (*FileSystemBlobAccess) GetState

func (a *FileSystemBlobAccess) GetState() State

func (*FileSystemBlobAccess) IsClosed

func (a *FileSystemBlobAccess) IsClosed() bool

func (*FileSystemBlobAccess) IsReadOnly

func (a *FileSystemBlobAccess) IsReadOnly() bool

func (*FileSystemBlobAccess) SetReadOnly added in v0.9.0

func (a *FileSystemBlobAccess) SetReadOnly()

func (*FileSystemBlobAccess) Update

func (a *FileSystemBlobAccess) Update() error

func (*FileSystemBlobAccess) Write

func (a *FileSystemBlobAccess) Write(path string, mode vfs.FileMode, opts ...accessio.Option) error

type FilesystemSetup

type FilesystemSetup func(fs vfs.FileSystem, mode vfs.FileMode) error

type FormatHandler

type FormatHandler interface {
	accessio.Option

	Format() accessio.FileFormat

	Open(info AccessObjectInfo, acc AccessMode, path string, opts accessio.Options) (*AccessObject, error)
	Create(info AccessObjectInfo, path string, opts accessio.Options, mode vfs.FileMode) (*AccessObject, error)
	Write(obj *AccessObject, path string, opts accessio.Options, mode vfs.FileMode) error
}

func GetFormat

func GetFormat(name FileFormat) FormatHandler

type Setup

type Setup interface {
	Setup(vfs.FileSystem) error
}

type SetupFunction

type SetupFunction func(vfs.FileSystem) error

func (SetupFunction) Setup

func (f SetupFunction) Setup(fs vfs.FileSystem) error

type StandardReaderHandler

type StandardReaderHandler interface {
	Write(obj *AccessObject, path string, opts accessio.Options, mode vfs.FileMode) error
	NewFromReader(info AccessObjectInfo, acc AccessMode, in io.Reader, opts accessio.Options, closer Closer) (*AccessObject, error)
}

type State

type State interface {
	IsReadOnly() bool
	IsCreate() bool

	GetOriginalBlob() blobaccess.BlobAccess
	GetBlob() (blobaccess.BlobAccess, error)

	HasChanged() bool
	GetOriginalState() interface{}
	GetState() interface{}

	// Update updates the technical representation in its persistence
	Update() (bool, error)

	SetReadOnly()
}

State manages the modification and access of state with a technical representation as byte array It tries to keep the byte representation unchanged as long as possible.

func NewBlobStateForBlob

func NewBlobStateForBlob(mode AccessMode, blob blobaccess.BlobAccess, p StateHandler) (State, error)

NewBlobStateForBlob provides state handling for an object persisted as a blob. It tries to keep the blob representation unchanged as long as possible consulting the state handler responsible for analysing the binary blob data and the object.

func NewBlobStateForObject

func NewBlobStateForObject(mode AccessMode, obj interface{}, p StateHandler) (State, error)

NewBlobStateForObject returns a representation state handling for a given object.

func NewFileBasedState

func NewFileBasedState(acc AccessMode, fs vfs.FileSystem, path string, mimeType string, h StateHandler, mode vfs.FileMode) (State, error)

NewFileBasedState create a new State object based on a file based persistence of the state carrying object.

func NewState

func NewState(mode AccessMode, a StateAccess, p StateHandler) (State, error)

NewState creates a new State based on its persistence handling and the management of its technical representation as byte array.

type StateAccess

type StateAccess interface {
	// Get returns the technical representation of a state object from its persistence
	// It MUST return an errors.IsErrNotFound compatible error
	// if the persistence not yet exists.
	Get() (blobaccess.BlobAccess, error)
	// Digest() digest.Digest
	Put(data []byte) error
}

StateAccess is responsible to handle the persistence of a state object.

func NewBlobStateAccess

func NewBlobStateAccess(blob blobaccess.BlobAccess) StateAccess

func NewBlobStateAccessForData

func NewBlobStateAccessForData(mimeType string, data []byte) StateAccess

type StateHandler

type StateHandler interface {
	Initial() interface{}
	Encode(d interface{}) ([]byte, error)
	Decode([]byte) (interface{}, error)
	Equivalent(a, b interface{}) bool
}

StateHandler is responsible to handle the technical representation of state carrying object as byte array.

type TarHandler

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

func NewTarHandler

func NewTarHandler() *TarHandler

func NewTarHandlerWithCompression

func NewTarHandlerWithCompression(format FileFormat, algorithm compression.Algorithm) *TarHandler

func (*TarHandler) ApplyOption

func (h *TarHandler) ApplyOption(options accessio.Options) error

ApplyOption applies the configured path filesystem.

func (*TarHandler) Create

func (h *TarHandler) Create(info AccessObjectInfo, path string, opts accessio.Options, mode vfs.FileMode) (*AccessObject, error)

func (*TarHandler) Format

func (h *TarHandler) Format() accessio.FileFormat

func (*TarHandler) NewFromReader

func (h *TarHandler) NewFromReader(info AccessObjectInfo, acc AccessMode, in io.Reader, opts accessio.Options, closer Closer) (*AccessObject, error)

func (*TarHandler) Open

func (h *TarHandler) Open(info AccessObjectInfo, acc AccessMode, path string, opts accessio.Options) (*AccessObject, error)

func (*TarHandler) Write

func (h *TarHandler) Write(obj *AccessObject, path string, opts accessio.Options, mode vfs.FileMode) error

Write tars the current descriptor and its artifacts.

func (TarHandler) WriteToStream

func (h TarHandler) WriteToStream(obj *AccessObject, writer io.Writer, opts accessio.Options) error

Jump to

Keyboard shortcuts

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