Documentation ¶
Overview ¶
This module is an implementation of the Oxford Common File Layout (OCFL) specification. The top-level package provides version-independent functionality. The ocflv1 package provides the bulk of implementation.
Index ¶
- Constants
- Variables
- func Copy(ctx context.Context, dstFS WriteFS, dst string, srcFS FS, src string) (err error)
- func ParseVNum(v string, vn *VNum) error
- func ReadAll(ctx context.Context, fsys FS, name string) ([]byte, error)
- func ReadSidecarDigest(ctx context.Context, fsys FS, name string) (string, error)
- func StatFile(ctx context.Context, fsys FS, name string) (fs.FileInfo, error)
- func ValidateInventoryBytes(byts []byte) (Inventory, *Validation)
- func ValidateInventorySidecar(ctx context.Context, inv Inventory, fsys FS, dir string) error
- func ValidateNamaste(ctx context.Context, fsys FS, name string) (err error)
- func WriteDeclaration(ctx context.Context, root WriteFS, dir string, d Namaste) error
- func WriteSpecFile(ctx context.Context, fsys WriteFS, dir string, n Spec) (string, error)
- type Commit
- type CommitError
- type ContentSource
- type CopyFS
- type DigestMap
- func (m DigestMap) Clone() DigestMap
- func (m DigestMap) Digests() []string
- func (m DigestMap) EachPath(fn func(pth, digest string) bool) bool
- func (m DigestMap) Eq(other DigestMap) bool
- func (m DigestMap) GetDigest(p string) string
- func (m DigestMap) HasDigestCase() (hasLower bool, hasUpper bool)
- func (m1 DigestMap) Merge(m2 DigestMap, replace bool) (DigestMap, error)
- func (m DigestMap) Normalize() (norm DigestMap, err error)
- func (m DigestMap) NumPaths() int
- func (m DigestMap) PathMap() PathMap
- func (m DigestMap) PathMapValid() (PathMap, error)
- func (m DigestMap) Paths() []string
- func (m DigestMap) Remap(fns ...RemapFunc)
- func (m DigestMap) Valid() error
- type FS
- type FileDigests
- type FileDigestsErrSeq
- type FileDigestsSeq
- type FileErrSeq
- type FileRef
- func (f FileRef) FullPath() string
- func (f FileRef) FullPathDir() string
- func (f FileRef) Namaste() Namaste
- func (f *FileRef) Open(ctx context.Context) (fs.File, error)
- func (f *FileRef) OpenObject(ctx context.Context, opts ...ObjectOption) (*Object, error)
- func (f *FileRef) Stat(ctx context.Context) error
- type FileSeq
- func (files FileSeq) Digest(ctx context.Context, alg digest.Algorithm, fixityAlgs ...digest.Algorithm) FileDigestsErrSeq
- func (files FileSeq) DigestBatch(ctx context.Context, numgos int, alg digest.Algorithm, ...) FileDigestsErrSeq
- func (files FileSeq) Filter(filter func(*FileRef) bool) FileSeq
- func (files FileSeq) IgnoreHidden() FileSeq
- func (files FileSeq) OpenObjects(ctx context.Context, opts ...ObjectOption) iter.Seq2[*Object, error]
- func (files FileSeq) OpenObjectsBatch(ctx context.Context, numgos int, opts ...ObjectOption) iter.Seq2[*Object, error]
- func (files FileSeq) Stat(ctx context.Context) FileErrSeq
- type FileWalker
- type FixitySource
- type Inventory
- type InventoryType
- type MapDigestConflictErr
- type MapPathConflictErr
- type MapPathInvalidErr
- type Namaste
- type Object
- func (obj *Object) Commit(ctx context.Context, commit *Commit) error
- func (obj *Object) Exists() bool
- func (obj Object) ExtensionNames(ctx context.Context) ([]string, error)
- func (obj *Object) FS() FS
- func (obj *Object) Inventory() Inventory
- func (obj *Object) OpenVersion(ctx context.Context, i int) (*ObjectVersionFS, error)
- func (obj *Object) Path() string
- func (o *Object) Root() *Root
- type ObjectOption
- type ObjectState
- func (state ObjectState) Empty() bool
- func (state ObjectState) HasExtensions() bool
- func (state ObjectState) HasInventory() bool
- func (state ObjectState) HasLogs() bool
- func (state ObjectState) HasNamaste() bool
- func (state ObjectState) HasSidecar() bool
- func (state ObjectState) HasVersionDir(v VNum) bool
- func (state ObjectState) Namaste() Namaste
- type ObjectValidation
- func (v *ObjectValidation) Add(v2 *Validation)
- func (v *ObjectValidation) AddFatal(errs ...error)
- func (v *ObjectValidation) AddWarn(errs ...error)
- func (v *ObjectValidation) DigestConcurrency() int
- func (v *ObjectValidation) Logger() *slog.Logger
- func (v *ObjectValidation) PrefixAdd(prefix string, v2 *Validation)
- func (v *ObjectValidation) SkipDigests() bool
- func (v *ObjectValidation) ValidationAlgorithms() digest.AlgorithmRegistry
- type ObjectValidationOption
- type ObjectVersion
- type ObjectVersionFS
- func (vfs *ObjectVersionFS) Close() error
- func (vfs *ObjectVersionFS) Created() time.Time
- func (vfs *ObjectVersionFS) DigestAlgorithm() digest.Algorithm
- func (vfs *ObjectVersionFS) GetContent(digest string) (FS, string)
- func (vfs *ObjectVersionFS) Message() string
- func (vfs *ObjectVersionFS) Num() int
- func (vfs *ObjectVersionFS) Open(name string) (fs.File, error)
- func (vfs *ObjectVersionFS) Stage() *Stage
- func (vfs *ObjectVersionFS) State() DigestMap
- func (vfs *ObjectVersionFS) User() *User
- type PathMap
- type RemapFunc
- type Root
- func (r *Root) Description() string
- func (r *Root) FS() FS
- func (r *Root) Layout() extension.Layout
- func (r *Root) LayoutName() string
- func (r *Root) NewObject(ctx context.Context, id string, opts ...ObjectOption) (*Object, error)
- func (r *Root) NewObjectDir(ctx context.Context, dir string, opts ...ObjectOption) (*Object, error)
- func (r *Root) ObjectDeclarations(ctx context.Context) (FileSeq, func() error)
- func (r *Root) Objects(ctx context.Context, opts ...ObjectOption) iter.Seq2[*Object, error]
- func (r *Root) ObjectsBatch(ctx context.Context, numgos int, opts ...ObjectOption) iter.Seq2[*Object, error]
- func (r *Root) Path() string
- func (r *Root) ResolveID(id string) (string, error)
- func (r *Root) Spec() Spec
- func (r *Root) ValidateObject(ctx context.Context, id string, opts ...ObjectValidationOption) *ObjectValidation
- func (r *Root) ValidateObjectDir(ctx context.Context, dir string, opts ...ObjectValidationOption) *ObjectValidation
- type RootOption
- type Spec
- type Stage
- type User
- type VNum
- func (v VNum) First() bool
- func (v VNum) IsZero() bool
- func (v VNum) Lineage() VNums
- func (v VNum) MarshalText() ([]byte, error)
- func (v VNum) Next() (VNum, error)
- func (v VNum) Num() int
- func (v VNum) Padding() int
- func (v VNum) Prev() (VNum, error)
- func (v VNum) String() string
- func (v *VNum) UnmarshalText(text []byte) error
- func (v VNum) Valid() error
- type VNums
- type Validation
- type ValidationError
- type WriteFS
Constants ¶
const ( NamasteTypeObject = "ocfl_object" // type string for OCFL Object declaration NamasteTypeStore = "ocfl" // type string for OCFL Storage Root declaration )
const ( // HasNamaste indicates that an object root directory includes a NAMASTE // object declaration file HasNamaste objectStateFlag = 1 << iota // HasInventory indicates that an object root includes an "inventory.json" // file HasInventory // HasSidecar indicates that an object root includes an "inventory.json.*" // file (the inventory sidecar). HasSidecar // HasExtensions indicates that an object root includes a directory named // "extensions" HasExtensions //HasLogs indicates that an object root includes a directory named "logs" HasLogs )
const ( // package version Version = "0.7.0" Spec1_0 = Spec("1.0") Spec1_1 = Spec("1.1") )
Variables ¶
var ( ErrNamasteNotExist = fmt.Errorf("missing NAMASTE declaration: %w", fs.ErrNotExist) ErrNamasteContents = errors.New("invalid NAMASTE declaration contents") ErrNamasteMultiple = errors.New("multiple NAMASTE declarations found") )
var ( ErrOCFLNotImplemented = errors.New("unimplemented or missing version of the OCFL specification") ErrObjectNamasteExists = fmt.Errorf("found existing OCFL object declaration: %w", fs.ErrExist) ErrObjectNamasteNotExist = fmt.Errorf("the OCFL object declaration does not exist: %w", ErrNamasteNotExist) ErrObjRootStructure = errors.New("object includes invalid files or directories") )
var ( ErrSpecInvalid = errors.New("invalid OCFL spec version") ErrSpecNotFound = errors.New("OCFL spec file not found") )
var ( ErrVNumInvalid = errors.New(`invalid version`) ErrVNumPadding = errors.New(`inconsistent version padding in version sequence`) ErrVNumMissing = errors.New(`missing version in version sequence`) ErrVerEmpty = errors.New("no versions found") // Some functions in this package use the zero value VNum to indicate the // most recent, "head" version. Head = VNum{} )
var ErrFileType = errors.New("invalid file type for an OCFL context")
var ( // Error: invalid contents of inventory sidecar file ErrInventorySidecarContents = errors.New("invalid contents of inventory sidecar file") )
var ErrLayoutUndefined = errors.New("storage root's layout is undefined")
var ErrMapMakerExists = errors.New("path and digest exist")
ErrMapMakerExists is returned when calling Add with a path and digest that are already present in the MapMaker
var ErrNotFile = errors.New("not a file")
Functions ¶
func Copy ¶ added in v0.0.23
Copy copies src in srcFS to dst in dstFS. If srcFS and dstFS are the same refererence and it implements CopyFS, then Copy uses the fs's Copy() method.
func ReadSidecarDigest ¶ added in v0.1.0
ReadSidecarDigest reads the digest from an inventory.json sidecar file
func ValidateInventoryBytes ¶ added in v0.7.0
func ValidateInventoryBytes(byts []byte) (Inventory, *Validation)
ValidateInventoryBytes parses and fully validates the byts as contents of an inventory.json file. This is mostly used for testing.
func ValidateInventorySidecar ¶ added in v0.3.0
ValidateInventorySidecar reads the inventory sidecar with inv's digest algorithm (e.g., inventory.json.sha512) in directory dir and return an error if the sidecar content is not formatted correctly or if the inv's digest doesn't match the value found in the sidecar.
func ValidateNamaste ¶ added in v0.1.0
ValidateNamaste validates a namaste declaration
func WriteDeclaration ¶
Types ¶
type Commit ¶ added in v0.1.0
type Commit struct { ID string // required for new objects in storage roots without a layout. Stage *Stage // required Message string // required User User // required // advanced options Created time.Time // time.Now is used, if not set Spec Spec // OCFL specification version for the new object version NewHEAD int // enforces new object version number AllowUnchanged bool ContentPathFunc RemapFunc Logger *slog.Logger }
Commit represents an update to object.
type CommitError ¶ added in v0.1.0
type CommitError struct { Err error // The wrapped error // Dirty indicates the object may be incomplete or invalid as a result of // the error. Dirty bool }
Commit error wraps an error from a commit.
func (CommitError) Error ¶ added in v0.1.0
func (c CommitError) Error() string
func (CommitError) Unwrap ¶ added in v0.1.0
func (c CommitError) Unwrap() error
type ContentSource ¶ added in v0.0.23
type ContentSource interface { // GetContent returns an FS and path to a file in FS for a file with the given digest. // If no content is associated with the digest, fsys is nil and path is an empty string. GetContent(digest string) (fsys FS, path string) }
ContentSource is used to access content with a given digest when creating and upadting objects.
type CopyFS ¶
type CopyFS interface { WriteFS // Copy creates or updates the file at dst with the contents of src. If dst // exists, it should be overwritten Copy(ctx context.Context, dst string, src string) error }
CopyFS is a storage backend that supports copying files.
type DigestMap ¶
DigestMap maps digests to file paths.
func (DigestMap) Digests ¶
Digests returns a slice of the digest values in the DigestMap. Digest strings are not normalized; they may be uppercase, lowercase, or mixed.
func (DigestMap) EachPath ¶
EachPath calls fn for each path in the Map. If fn returns false, iteration stops and EachPath returns false.
func (DigestMap) Eq ¶
Eq returns true if m and the other have the same content: they have the same (normalized) digests corresponding to the same set of paths. If either map has a digest conflict (same digest appears twice with different case), Eq returns false.
func (DigestMap) GetDigest ¶
GetDigest returns the digest for path p or an empty string if the digest is not present.
func (DigestMap) HasDigestCase ¶ added in v0.0.23
HasDigestCase returns two booleans indicating whether m's digests use lowercase and uppercase characters.
func (DigestMap) Merge ¶
Merge returns a new DigestMap constructed by normalizing and merging m1 and m2. If a paths has different digests in m1 and m2, an error returned unless replace is true, in which case the value from m2 is used.
func (DigestMap) Normalize ¶
Normalize returns a normalized copy on m (with lowercase digests). An error is returned if m has a digest conflict.
func (DigestMap) PathMap ¶
PathMap returns the DigestMap's contents as a map with path names for keys and digests for values. PathMap doesn't check if the same path appears twice in the DigestMap.
func (DigestMap) PathMapValid ¶
PathMapValid is like PathMap, except it returns an error if it encounters invalid path names or if the same path appears multiple times.
type FS ¶
type FS interface { OpenFile(ctx context.Context, name string) (fs.File, error) ReadDir(ctx context.Context, name string) ([]fs.DirEntry, error) }
FS is a minimal, read-only storage layer abstraction. It is similar to the standard library's io/fs.FS, except it uses contexts and OpenFile is not required to gracefully handle directories.
type FileDigests ¶ added in v0.5.0
type FileDigests struct { FileRef Algorithm digest.Algorithm // primary digest algorithm (sha512 or sha256) Digests digest.Set // computed digest of file contents. Must include entry for the primary algorithm }
FileDigests is a FileRef plus digest values of the file contents.
func (FileDigests) Validate ¶ added in v0.5.0
func (pd FileDigests) Validate(ctx context.Context, reg digest.AlgorithmRegistry) error
Validate confirms the digest values in pd using alogirthm definitions from reg. If the digests values do not match, the resulting error is a *digest.DigestError.
type FileDigestsErrSeq ¶ added in v0.5.0
type FileDigestsErrSeq iter.Seq2[*FileDigests, error]
FileDigestsErrSeq is an iterator that yields results and errors from a digesting file contents.
func (FileDigestsErrSeq) Stage ¶ added in v0.5.0
func (digests FileDigestsErrSeq) Stage() (*Stage, error)
Stage returns a new stage from the *[FileDigest]s in digests. An error is returned if digests yields an error or if the yielded *FileDigests are inconsisent (see FileDigestsSeq.Stage).
func (FileDigestsErrSeq) UntilErr ¶ added in v0.5.0
func (dfs FileDigestsErrSeq) UntilErr() (FileDigestsSeq, func() error)
UntilErr returns an iterator of *FileDigests from dfs that terminates on the first non-nil error in dfs. The terminating error is returned by errFn
type FileDigestsSeq ¶ added in v0.5.0
type FileDigestsSeq iter.Seq[*FileDigests]
FileDigestSeq is a
func (FileDigestsSeq) Stage ¶ added in v0.5.0
func (digests FileDigestsSeq) Stage() (*Stage, error)
Stage builds a stage from values in digests. The stage's state uses the Path from each value in digests. The values in digests must have the same FS, primary digest algorithm, and base path, otherwise an error is returned.
func (FileDigestsSeq) ValidateBatch ¶ added in v0.5.0
func (files FileDigestsSeq) ValidateBatch(ctx context.Context, reg digest.AlgorithmRegistry, numgos int) iter.Seq[error]
ValidateBatch concurrently validates sequence of FileDigests using numgos go routines. It returns an iterator of non-nill error values for any files that fail validation. If validation fails because a files content has changed, the yielded error is a *digest.DigestError.
type FileErrSeq ¶ added in v0.5.0
FileErrSeq is an iterator that yields *FileRef values or errors occuring while accessing a file.
func (FileErrSeq) IgnoreErr ¶ added in v0.5.0
func (fileErrs FileErrSeq) IgnoreErr() FileSeq
IgnoreErr returns an iterator of *[FileRef]s in seq that are not associated with an error.
func (FileErrSeq) UntilErr ¶ added in v0.5.0
func (fileErrs FileErrSeq) UntilErr() (FileSeq, func() error)
UntilErr returns a new iterator yielding *FileRef values from seq that terminates on the first non-nil error in seq. The terminating error is returned by errFn.
type FileRef ¶ added in v0.5.0
type FileRef struct { FS FS // The FS where the file is stored. BaseDir string // parent directory relative to an FS. Path string // file path relative to BaseDir Info fs.FileInfo // file info from StatFile (may be nil) }
FileRef includes everything needed to access a file, including a reference to the FS where the file is stored. It may include file metadata from calling StatFile().
func (FileRef) FullPathDir ¶ added in v0.5.0
FullPathDir returns the full path of the directory where the file is stored.
func (FileRef) Namaste ¶ added in v0.5.0
Namastes parses the file's name as a Namaste declaration and returns the result. If the file is not a namaste declaration, the zero-value is returned.
func (*FileRef) Open ¶ added in v0.5.0
Open return an fs.File for reading the contents of the file at f.
func (*FileRef) OpenObject ¶ added in v0.5.0
OpenObject opens f's directory as an *Object. If the the directory is not an existing object, an error is returned.
type FileSeq ¶ added in v0.1.0
FileSeq is an iterator that yields *FileRef values.
func FilesSub ¶ added in v0.5.0
Files returns a FileSeq for iterating over the named files, relative to the directory dir in fsys.
func WalkFiles ¶ added in v0.5.0
WalkFiles returns a FileSeq for iterating over the files in dir and its subdirectories. If an error occurs while reading FS, iteration terminates. The terminating error is returned by errFn
func (FileSeq) Digest ¶ added in v0.5.0
func (files FileSeq) Digest(ctx context.Context, alg digest.Algorithm, fixityAlgs ...digest.Algorithm) FileDigestsErrSeq
Digest concurrently computes digests for each file in files. It is the same as DigestBatch with numgos set to runtime.NumCPU(). The resulting iterator yields digest results or an error if the file could not be digestsed.
func (FileSeq) DigestBatch ¶ added in v0.5.0
func (files FileSeq) DigestBatch(ctx context.Context, numgos int, alg digest.Algorithm, fixityAlgs ...digest.Algorithm) FileDigestsErrSeq
DigestBatch concurrently computes digests for each file in files. The resulting iterator yields digest results or an error if the file could not be digestsed. If numgos is < 1, the value from runtime.GOMAXPROCS(0) is used.
func (FileSeq) Filter ¶ added in v0.5.0
Filter returns a new FileSeq that yields values in files that satisfy the filter condition.
func (FileSeq) IgnoreHidden ¶ added in v0.5.0
IgnoreHidden returns a new FileSeq that does not included hidden files (files with a path element that begins with '.'). It only considers a FileRef's Path value, not its BaseDir.
func (FileSeq) OpenObjects ¶ added in v0.5.0
func (files FileSeq) OpenObjects(ctx context.Context, opts ...ObjectOption) iter.Seq2[*Object, error]
OpenObjects returns an iterator with results from calling OpenObject() on each *FileRef in files. Unlike FileSeq.OpenObjectsBatch, objects are opened sequentially, in the same goroutine as the caller.
func (FileSeq) OpenObjectsBatch ¶ added in v0.5.0
func (files FileSeq) OpenObjectsBatch(ctx context.Context, numgos int, opts ...ObjectOption) iter.Seq2[*Object, error]
OpenObjectsBatch returns an iterator with results from calling OpenObjects() on each *FileRef in files. Unlike FileSeq.OpenObjects, objects are opened in separate goroutines and may not be yielded in the same order as the input.
type FileWalker ¶ added in v0.5.0
type FileWalker interface { FS // WalkFiles returns a function iterator that yields all files in // dir and its subdirectories WalkFiles(ctx context.Context, dir string) (FileSeq, func() error) }
FileWalker is an FS with an optimized implementation of WalkFiles
type FixitySource ¶ added in v0.0.23
type FixitySource interface { // GetFixity returns a DigestSet with alternate digests for the content with // the digest derived using the stage's primary digest algorithm. GetFixity(digest string) digest.Set }
FixitySource is used to access alternate digests for content with a given digest (sha512 or sha256) when creating or updating objects.
type Inventory ¶ added in v0.7.0
type InventoryType ¶ added in v0.7.0
type InventoryType struct {
Spec
}
InventoryType represents an inventory type string for example: https://ocfl.io/1.0/spec/#inventory
func (InventoryType) MarshalText ¶ added in v0.7.0
func (invT InventoryType) MarshalText() ([]byte, error)
func (InventoryType) String ¶ added in v0.7.0
func (inv InventoryType) String() string
func (*InventoryType) UnmarshalText ¶ added in v0.7.0
func (invT *InventoryType) UnmarshalText(t []byte) error
type MapDigestConflictErr ¶
type MapDigestConflictErr struct {
Digest string
}
MapDigestConflictErr indicates same digest found multiple times in the digest map (i.e., with different cases)
func (*MapDigestConflictErr) Error ¶
func (d *MapDigestConflictErr) Error() string
type MapPathConflictErr ¶
type MapPathConflictErr struct {
Path string
}
MapPathConflictErr indicates a path appears more than once in the digest map. It's also used in cases where the path as used as a directory in one instance and a file in another.
func (*MapPathConflictErr) Error ¶
func (p *MapPathConflictErr) Error() string
type MapPathInvalidErr ¶
type MapPathInvalidErr struct {
Path string
}
MapPathInvalidErr indicates an invalid path in a Map.
func (*MapPathInvalidErr) Error ¶
func (p *MapPathInvalidErr) Error() string
type Namaste ¶ added in v0.0.24
Namaste represents a NAMASTE declaration
func FindNamaste ¶ added in v0.0.24
FindNamaste returns the NAMASTE declaration from a fs.DirEntry slice. An error is returned if the number of declarations is not one.
func ParseNamaste ¶ added in v0.0.24
func (Namaste) Body ¶ added in v0.0.24
Body returns the expected file contents of the namaste declaration
type Object ¶ added in v0.1.0
type Object struct {
// contains filtered or unexported fields
}
Object represents and OCFL Object, typically contained in a Root.
func NewObject ¶ added in v0.1.0
NewObject returns an *Object for managing the OCFL object at path in fsys. The object doesn't need to exist when NewObject is called.
func (*Object) Commit ¶ added in v0.1.0
Commit creates a new object version based on values in commit.
func (Object) ExtensionNames ¶ added in v0.1.0
ExtensionNames returns the names of directories in the object's extensions directory. The ObjectRoot's State is initialized if it is nil. If the object root does not include an object declaration, an error is returned. If object root does not include an extensions directory both return values are nil.
func (*Object) Inventory ¶ added in v0.1.0
Inventory returns the object's Inventory if it exists. If the object doesn't exist, it returns nil.
func (*Object) OpenVersion ¶ added in v0.1.0
OpenVersion returns an ObjectVersionFS for the version with the given index (1...HEAD). If i is 0, the most recent version is used.
func (*Object) Root ¶ added in v0.7.0
Root returns the object's Root, if known. It is nil unless the *Object was created using Root.NewObject
type ObjectOption ¶ added in v0.1.0
type ObjectOption func(*Object)
ObjectOptions are used to configure the behavior of NewObject()
func ObjectMustExist ¶ added in v0.5.0
func ObjectMustExist() ObjectOption
ObjectMustExists requires the object to exist
type ObjectState ¶
type ObjectState struct { Spec Spec // the OCFL spec from the object's NAMASTE declaration file VersionDirs VNums // version directories found in the object directory SidecarAlg string // digest algorithm used by the inventory sidecar file Invalid []string // non-conforming directory entries in the object root (max of 8) Flags objectStateFlag // boolean attributes of the object root }
ObjectState provides details of an OCFL object root based on the names of files and directories in the object's root. ParseObjectDir is typically used to create a new ObjectState from a slice of fs.DirEntry values.
func ParseObjectDir ¶ added in v0.1.0
func ParseObjectDir(entries []fs.DirEntry) *ObjectState
ParseObjectDir returns a new ObjectState based on contents of an object root directory.
func (ObjectState) Empty ¶ added in v0.1.0
func (state ObjectState) Empty() bool
Empty returns true if the object root directory is empty
func (ObjectState) HasExtensions ¶ added in v0.1.0
func (state ObjectState) HasExtensions() bool
HasExtensions returns true if state's HasExtensions flag is set
func (ObjectState) HasInventory ¶ added in v0.1.0
func (state ObjectState) HasInventory() bool
HasInventory returns true if state's HasInventory flag is set
func (ObjectState) HasLogs ¶ added in v0.3.1
func (state ObjectState) HasLogs() bool
HasLogs returns true if state's HasLogs flag is set
func (ObjectState) HasNamaste ¶ added in v0.1.0
func (state ObjectState) HasNamaste() bool
HasNamaste returns true if state's HasNamaste flag is set
func (ObjectState) HasSidecar ¶ added in v0.1.0
func (state ObjectState) HasSidecar() bool
HasSidecar returns true if state's HasSidecar flag is set
func (ObjectState) HasVersionDir ¶ added in v0.1.0
func (state ObjectState) HasVersionDir(v VNum) bool
HasVersionDir returns true if the state's VersionDirs includes v
func (ObjectState) Namaste ¶ added in v0.6.0
func (state ObjectState) Namaste() Namaste
Namaste returns state's Namaste value, which may be a zero value.
type ObjectValidation ¶ added in v0.1.0
type ObjectValidation struct { Validation // contains filtered or unexported fields }
ObjectValidation is used to configure and track results from an object validation process.
func ValidateObject ¶ added in v0.3.0
func ValidateObject(ctx context.Context, fsys FS, dir string, opts ...ObjectValidationOption) *ObjectValidation
ValidateObject fully validates the OCFL Object at dir in fsys
func (*ObjectValidation) Add ¶ added in v0.1.0
func (v *ObjectValidation) Add(v2 *Validation)
Add adds and logs all fatal errors and warning from the validation
func (*ObjectValidation) AddFatal ¶ added in v0.1.0
func (v *ObjectValidation) AddFatal(errs ...error)
AddFatal adds fatal errors to the validation
func (*ObjectValidation) AddWarn ¶ added in v0.1.0
func (v *ObjectValidation) AddWarn(errs ...error)
AddWarn adds warning errors to the object validation and logs the errors using the object validations logger, if set.
func (*ObjectValidation) DigestConcurrency ¶ added in v0.4.0
func (v *ObjectValidation) DigestConcurrency() int
DigestConcurrency returns the configured number of go routines used to read and digest contents during validation. The default value is runtime.NumCPU().
func (*ObjectValidation) Logger ¶ added in v0.1.0
func (v *ObjectValidation) Logger() *slog.Logger
Logger returns the validation's logger, which is nil by default.
func (*ObjectValidation) PrefixAdd ¶ added in v0.1.0
func (v *ObjectValidation) PrefixAdd(prefix string, v2 *Validation)
PrefixAdd adds and logs all fatal errors and warning from the valiation, prepending each error with the prefix.
func (*ObjectValidation) SkipDigests ¶ added in v0.1.0
func (v *ObjectValidation) SkipDigests() bool
SkipDigests returns true if the validation is configured to skip digest checks. It is false by default.
func (*ObjectValidation) ValidationAlgorithms ¶ added in v0.4.0
func (v *ObjectValidation) ValidationAlgorithms() digest.AlgorithmRegistry
ValidationAlgorithms returns the registry of digest algoriths the object validation is configured to use. The default value is digest.DefaultRegistry
type ObjectValidationOption ¶ added in v0.1.0
type ObjectValidationOption func(*ObjectValidation)
func ValidationAlgorithms ¶ added in v0.4.0
func ValidationAlgorithms(reg digest.AlgorithmRegistry) ObjectValidationOption
ValidationAlgorithms sets registry of available digest algorithms for fixity validation.
func ValidationDigestConcurrency ¶ added in v0.4.0
func ValidationDigestConcurrency(num int) ObjectValidationOption
ValidationDigestConcurrency is used to set the number of go routines used to read and digest contents during validation.
func ValidationLogger ¶ added in v0.1.0
func ValidationLogger(logger *slog.Logger) ObjectValidationOption
ValidationLogger sets the *slog.Logger that should be used for logging validation errors and warnings.
func ValidationSkipDigest ¶ added in v0.1.0
func ValidationSkipDigest() ObjectValidationOption
type ObjectVersion ¶ added in v0.1.0
type ObjectVersionFS ¶ added in v0.1.0
type ObjectVersionFS struct {
// contains filtered or unexported fields
}
func (*ObjectVersionFS) Close ¶ added in v0.1.0
func (vfs *ObjectVersionFS) Close() error
func (*ObjectVersionFS) Created ¶ added in v0.1.0
func (vfs *ObjectVersionFS) Created() time.Time
func (*ObjectVersionFS) DigestAlgorithm ¶ added in v0.1.0
func (vfs *ObjectVersionFS) DigestAlgorithm() digest.Algorithm
func (*ObjectVersionFS) GetContent ¶ added in v0.1.0
func (vfs *ObjectVersionFS) GetContent(digest string) (FS, string)
func (*ObjectVersionFS) Message ¶ added in v0.1.0
func (vfs *ObjectVersionFS) Message() string
func (*ObjectVersionFS) Num ¶ added in v0.1.0
func (vfs *ObjectVersionFS) Num() int
func (*ObjectVersionFS) Open ¶ added in v0.1.0
func (vfs *ObjectVersionFS) Open(name string) (fs.File, error)
func (*ObjectVersionFS) Stage ¶ added in v0.1.0
func (vfs *ObjectVersionFS) Stage() *Stage
func (*ObjectVersionFS) State ¶ added in v0.1.0
func (vfs *ObjectVersionFS) State() DigestMap
func (*ObjectVersionFS) User ¶ added in v0.1.0
func (vfs *ObjectVersionFS) User() *User
type PathMap ¶ added in v0.0.23
PathMap maps filenames to digest strings.
func (PathMap) DigestMap ¶ added in v0.0.23
DigestMap returns a new DigestMap using the pathnames and digests in pm. The resulting DigestMap may be invalid if pm includes invalid paths or digests.
func (PathMap) DigestMapValid ¶ added in v0.0.23
DigestMap returns a new DigestMap using the pathnames and digests in pm. If the resulting DigestMap is invalid, an error is returned.
type Root ¶ added in v0.1.0
type Root struct {
// contains filtered or unexported fields
}
Root represents an OCFL Storage Root.
func NewRoot ¶ added in v0.1.0
NewRoot returns a new *Root for working with the OCFL storage root at directory dir in fsys. It can be used to initialize new storage roots if the InitRoot option is used, fsys is an ocfl.WriteFS, and dir is a non-existing or empty directory.
func (*Root) Description ¶ added in v0.1.0
Description returns the description string from the storage roots `ocfl_layout.json` file, which may be empty.
func (*Root) LayoutName ¶ added in v0.1.0
LayoutName returns the name of the root's layout extension or an empty string if the root has no layout.
func (*Root) NewObject ¶ added in v0.1.0
NewObject returns an *Object for managing the OCFL object with the given ID in the root. If the object does not exist, the returned *Object can be used to create it. If the Root has not storage layout for resovling object IDs, the returned error is ErrLayoutUndefined.
func (*Root) NewObjectDir ¶ added in v0.3.0
NewObjectDir returns an *Object for managing the OCFL object at path dir in root. If the object does not exist, the returned *Object can be used to create it.
func (*Root) ObjectDeclarations ¶ added in v0.6.0
ObjectDeclarations returns an iterator that yields all OCFL object declaration files in r. If an error occurs during iteration, it is returned by the error function.
func (*Root) Objects ¶ added in v0.1.0
Objects returns an iterator that yields objects or an error for every object declaration file in the root.
func (*Root) ObjectsBatch ¶ added in v0.6.0
func (r *Root) ObjectsBatch(ctx context.Context, numgos int, opts ...ObjectOption) iter.Seq2[*Object, error]
ObjectsBatch returns an iterator that uses FileSeq.OpenObjectsBatch to open objects in the root in numgos separate goroutines, yielding the results
func (*Root) ResolveID ¶ added in v0.3.0
ResolveID resolves the object id to a path relative to the root. If the root has no layout, the returned error is ErrLayoutUndefined.
func (*Root) ValidateObject ¶ added in v0.3.0
func (r *Root) ValidateObject(ctx context.Context, id string, opts ...ObjectValidationOption) *ObjectValidation
ValidateObject validates the object with the given id. If the id cannot be resolved, the error is reported as a fatal error in the returned *ObjectValidation.
func (*Root) ValidateObjectDir ¶ added in v0.3.0
func (r *Root) ValidateObjectDir(ctx context.Context, dir string, opts ...ObjectValidationOption) *ObjectValidation
ValidateObjectDir validates the object at a path relative to the root.
type RootOption ¶ added in v0.1.0
type RootOption func(*Root)
RootOption is used to configure the behavior of NewRoot()
type Spec ¶
type Spec string
Spec represent an OCFL specification number
func (Spec) Cmp ¶
Cmp compares Spec v1 to another v2. - If v1 is less than v2, returns -1. - If v1 is the same as v2, returns 0 - If v1 is greater than v2, returns 1 - any valid spec is greater than an invalid spec. - if both specs are invlid, Cmp panics.
func (Spec) InventoryType ¶ added in v0.7.0
func (s Spec) InventoryType() InventoryType
InventoryType returns n as an InventoryType
type Stage ¶
type Stage struct { // State is a DigestMap representing the new object version state. State DigestMap // DigestAlgorithm is the primary digest algorithm (sha512 or sha256) used by the stage // state. DigestAlgorithm digest.Algorithm // ContentSource is used to access new content needed to construct // an object. It may be nil ContentSource // FixitySource is used to access fixity information for new // content. It may be nil FixitySource }
Stage is used to create/update objects.
func StageBytes ¶ added in v0.0.23
func StageBytes(content map[string][]byte, alg digest.Algorithm, fixity ...digest.Algorithm) (*Stage, error)
StageBytes builds a stage from a map of filenames to file contents
func StageDir ¶ added in v0.0.23
func StageDir(ctx context.Context, fsys FS, dir string, alg digest.Algorithm, fixity ...digest.Algorithm) (*Stage, error)
StageDir builds a stage based on the contents of the directory dir in FS. Files in dir and its subdirectories are digested with the given digest algorithms and added to the stage. Hidden files are ignored. The alg argument must be sha512 or sha256.
func (Stage) HasContent ¶ added in v0.0.23
HasContent returns true if the stage's content source provides an FS and path for the digest
type VNum ¶
type VNum struct {
// contains filtered or unexported fields
}
VNum represents an OCFL object version number (e.g., "v1", "v02"). A VNum has a sequence number (1,2,3...) and a padding number, which defaults to zero. The padding is the maximum number of numeric digits the version number can include (a padding of 0 is no maximum). The padding value constrains the maximum valid sequence number.
func MustParseVNum ¶
MustParseVNum parses str as a VNUm and returns a new VNum. It panics if str cannot be parsed as a VNum.
func V ¶
V returns a new Vnum. The first argument is a sequence number. An optional second argument can be used to set the padding. Additional arguments are ignored. Without any arguments, V() returns a zero value VNum.
func (VNum) MarshalText ¶
func (VNum) Next ¶
Next returns the next ocfl.VNum after v with the same padding. A non-nil error is returned if padding > 0 and next would overflow the padding
func (VNum) Prev ¶
Prev returns the previous version before v, with the same padding. An error is returned if v.Num() == 1
func (*VNum) UnmarshalText ¶
type VNums ¶
type VNums []VNum
VNums is a slice of VNum elements
type Validation ¶ added in v0.1.0
type Validation struct {
// contains filtered or unexported fields
}
Validation represents multiple fatal errors and warning errors.
func (*Validation) Add ¶ added in v0.1.0
func (v *Validation) Add(v2 *Validation)
Add adds all fatal errors and warnings from another validation to v.
func (*Validation) AddFatal ¶ added in v0.1.0
func (v *Validation) AddFatal(errs ...error)
AddFatal adds fatal errors to the validation
func (*Validation) AddWarn ¶ added in v0.1.0
func (v *Validation) AddWarn(errs ...error)
AddWarn adds warning errors to the validation
func (*Validation) Err ¶ added in v0.1.0
func (v *Validation) Err() error
Err returns an error wrapping all the validation's fatal errors, or nil if there are no fatal errors.
func (*Validation) Errors ¶ added in v0.1.0
func (v *Validation) Errors() []error
Errors returns a slice of all the fatal errors.q
func (*Validation) WarnErr ¶ added in v0.1.0
func (v *Validation) WarnErr() error
WarnErr returns an error wrapping all the validation's warning errors, or nil if there are none.
func (*Validation) WarnErrors ¶ added in v0.1.0
func (v *Validation) WarnErrors() []error
WarnErrors returns a slice of all the warning errors.
type ValidationError ¶ added in v0.1.0
type ValidationError struct { validation.ValidationCode Err error }
ValidationError is an error that includes a reference to a validation error code from the OCFL spec.
func (*ValidationError) Error ¶ added in v0.1.0
func (ver *ValidationError) Error() string
func (*ValidationError) Unwrap ¶ added in v0.1.0
func (ver *ValidationError) Unwrap() error
type WriteFS ¶
type WriteFS interface { FS Write(ctx context.Context, name string, buffer io.Reader) (int64, error) // Remove the file with path name Remove(ctx context.Context, name string) error // Remove the directory with path name and all its contents. If the path // does not exist, return nil. RemoveAll(ctx context.Context, name string) error }
WriteFS is a storage backend that supports write and remove operations.