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 AlgRegistry() *digest.Registry
- func Files(ctx context.Context, fsys FS, pth PathSelector, fn func(name string) error) error
- func ObjectRoots(ctx context.Context, fsys FS, sel PathSelector, fn func(*ObjectRoot) error) error
- func ParseDeclaration(name string, dec *Declaration) error
- func ParseSpec(v string, n *Spec) error
- func ParseVNum(v string, vn *VNum) error
- func ReadDeclaration(ctx context.Context, fsys FS, filePath string) error
- func WriteDeclaration(ctx context.Context, root WriteFS, dir string, d Declaration) error
- func WriteSpecFile(ctx context.Context, fsys WriteFS, dir string, n Spec) (string, error)
- type CopyFS
- type Declaration
- type DigestErr
- type DigestMap
- func (m DigestMap) DigestPaths(dig string) []string
- func (m DigestMap) Digests() []string
- func (m DigestMap) EachDigest(fn func(digest string, paths []string) bool) bool
- 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) HasDigest(dig string) bool
- func (m DigestMap) HasLowercaseDigest() bool
- func (m DigestMap) HasUppercaseDigest() bool
- func (m DigestMap) LenDigests() int
- func (m DigestMap) LenPaths() int
- func (m DigestMap) MarshalJSON() ([]byte, error)
- func (m1 DigestMap) Merge(m2 DigestMap, replace bool) (merged DigestMap, err error)
- func (m DigestMap) Normalize() (norm DigestMap, err error)
- func (m DigestMap) PathMap() map[string]string
- func (m DigestMap) PathMapValid() (map[string]string, error)
- func (m DigestMap) Paths() []string
- func (m DigestMap) Remap(fns ...RemapFunc) (DigestMap, error)
- func (m *DigestMap) UnmarshalJSON(b []byte) error
- func (m DigestMap) Valid() error
- type FS
- type FileIterator
- type InvType
- type MapDigestConflictErr
- type MapPathConflictErr
- type MapPathInvalidErr
- type ObjectRoot
- type ObjectRootFlag
- type ObjectRootIterator
- type ObjectState
- type ObjectStateFS
- type PathSelector
- type RemapFunc
- type Spec
- type Stage
- func (stage *Stage) AddFS(ctx context.Context, fsys FS, root string, fixity ...digest.Alg) error
- func (stage *Stage) AddPath(ctx context.Context, name string, fixity ...digest.Alg) error
- func (stage Stage) GetContent(dig string) []string
- func (stage Stage) GetFixity(dig string) digest.Set
- func (stage Stage) Manifest() (DigestMap, error)
- func (stage *Stage) SetFS(fsys FS, dir string)
- func (stage *Stage) UnsafeAddPath(name string, digests digest.Set) error
- func (stage *Stage) UnsafeAddPathAs(content string, logical string, digests digest.Set) error
- func (stage *Stage) UnsafeSetManifestFixty(manifest DigestMap, fixity map[string]DigestMap) error
- type User
- type VNum
- func (v VNum) AsHead() VNums
- func (v VNum) First() bool
- func (v VNum) IsZero() bool
- 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 WriteFS
Constants ¶
const ( DeclObject = "ocfl_object" // type string for OCFL Object declaration DeclStore = "ocfl" // type string for OCFL Storage Root declaration )
const ( OBJECTSTATE_DEFAULT_FILEMODE fs.FileMode = 0440 OBJECTSTATE_DEFAULT_DIRMODE = 0550 | fs.ModeDir )
const ( // package version Version = "0.0.17" ExtensionsDir = "extensions" )
Variables ¶
var ( ErrDeclNotExist = fmt.Errorf("missing declaration: %w", fs.ErrNotExist) ErrDeclInvalid = errors.New("invalid NAMASTE declaration contents") ErrDeclMultiple = errors.New("multiple NAMASTE declarations found") )
var ( Spec1_0 = Spec{1, 0} Spec1_1 = Spec{1, 1} )
var ( ErrStageNoFS = errors.New("stage's FS is not set") ErrStageNoAlg = errors.New("stage's digest algorithm is not set") ErrExists = errors.New("the path exists and cannot be replaced") ErrCopyPath = errors.New("source or destination path is parent of the other") )
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 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")
var (
ErrObjectExists = errors.New("OCFL object declaration already exists")
)
var ErrSpecInvalid = errors.New("invalid OCFL spec version")
var ErrSpecNotFound = errors.New("OCFL spec file not found")
Functions ¶
func AlgRegistry ¶ added in v0.0.11
AlgRegistry returns the global digest algorithm registry
func ObjectRoots ¶ added in v0.0.15
func ObjectRoots(ctx context.Context, fsys FS, sel PathSelector, fn func(*ObjectRoot) error) error
ObjectRoots searches root and its subdirectories for OCFL object declarations and calls fn for each object root it finds. The *ObjectRoot passed to fn is confirmed to have an object declaration, but no other validation checks are made.
func ParseDeclaration ¶ added in v0.0.8
func ParseDeclaration(name string, dec *Declaration) error
func ParseVNum ¶ added in v0.0.8
ParseVNum parses string as an a VNum and sets the value referenced by vn.
func ReadDeclaration ¶ added in v0.0.16
ReadDeclaration validates a namaste declaration
func WriteDeclaration ¶ added in v0.0.8
Types ¶
type CopyFS ¶ added in v0.0.15
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 Declaration ¶ added in v0.0.8
Declaration represents a NAMASTE Declaration
func FindDeclaration ¶ added in v0.0.8
func FindDeclaration(items []fs.DirEntry) (Declaration, error)
FindDeclaration returns the declaration from a fs.DirEntry slice. An error is returned if the number of declarations is not one.
func (Declaration) Contents ¶ added in v0.0.8
func (d Declaration) Contents() string
Contents returns the file contents of the declaration or an empty string if d is empty
func (Declaration) Name ¶ added in v0.0.8
func (d Declaration) Name() string
Name returns the filename for d (0=TYPE_VERSION) or an empty string if d is empty
type DigestErr ¶ added in v0.0.17
type DigestErr struct {
Name string // Content path
AlgID string // Digest algorithm
Got string // Calculated digest
Expected string // Expected digest
}
DigestErr is returned when content's digest conflicts with an expected value
type DigestMap ¶ added in v0.0.17
type DigestMap struct {
// contains filtered or unexported fields
}
DigestMap is a data structure for digest/path mapping used in OCFL inventory manifests, version states, and fixity. DigestMaps are immutable.
func NewDigestMap ¶ added in v0.0.17
NewDigestMap returns a NewDigestMap. The validity of the digests values is not checked, so the resulting DigestMap may be invalid.
func (DigestMap) DigestPaths ¶ added in v0.0.17
DigestPaths returns the slice of paths associated with digest dig
func (DigestMap) Digests ¶ added in v0.0.17
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) EachDigest ¶ added in v0.0.17
Each calls fn for each digest ßin m. If fn returns false, iteration stops and EachPath returns false.
func (DigestMap) EachPath ¶ added in v0.0.17
EachPath calls fn for each path in the Map. If fn returns false, iteration stops and EachPath returns false.
func (DigestMap) Eq ¶ added in v0.0.17
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 ¶ added in v0.0.17
GetDigest returns the digest for path p or an empty string if the digest is not present.ß
func (DigestMap) HasDigest ¶ added in v0.0.17
HasDigest returns true if d is present in the DigestMap. The digest is not normalized, so uppercase and lowercase versions of the same digest will not count as equivalent.
func (DigestMap) HasLowercaseDigest ¶ added in v0.0.17
HasLowercaseDigest returns true if m includes a digest value with lowercase characters.
func (DigestMap) HasUppercaseDigest ¶ added in v0.0.17
HasUpperCaseDigest returns true if m includes digest values with uppercase characters.
func (DigestMap) LenDigests ¶ added in v0.0.17
LenDigests returns the number of digests in the DigestMap
func (DigestMap) MarshalJSON ¶ added in v0.0.17
func (DigestMap) Merge ¶ added in v0.0.17
Merge returns a new DigestMap constructed by normalizing and merging m1 and m2. If a paths has different digests in m1 and m2, the value from m2 is used if replace is true, otherwise the value from m1 is kept.
func (DigestMap) Normalize ¶ added in v0.0.17
Normalize returns a normalized version on m (with lowercase digests). An error is returned if m has a digest conflict.
func (DigestMap) PathMap ¶ added in v0.0.17
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 ¶ added in v0.0.17
PathMapValid is like PathMap, except it retuns an error if it encounters invalid path names or if the same path appears multiple times.
func (DigestMap) Paths ¶ added in v0.0.17
Paths returns a sorted slice of all path names in the DigestMap.
func (DigestMap) Remap ¶ added in v0.0.17
Remap builds a new DigestMap from m by applying one or more transorfmation functions. The transformation function is called for each digest in m and returns a new slice of path names to associate with the digest. If the returned slices is empty, the digest will not be included in the resulting DigestMap. If the transformation functions result in an invalid DigestMap, an error is returned.
func (*DigestMap) UnmarshalJSON ¶ added in v0.0.17
type FS ¶ added in v0.0.8
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 FileIterator ¶ added in v0.0.16
type FileIterator interface {
FS
// Files calls a function for each filename satisfying the path selector.
// The function should only be called for "regular" files (never for
// directories or symlinks).
Files(context.Context, PathSelector, func(name string) error) error
}
FileIterator is used to iterate over regular files in an FS
type InvType ¶ added in v0.0.8
type InvType struct {
Spec
}
InvType represents an inventory type string for example: https://ocfl.io/1.0/spec/#inventory
func (InvType) MarshalText ¶ added in v0.0.8
func (*InvType) UnmarshalText ¶ added in v0.0.8
type MapDigestConflictErr ¶ added in v0.0.17
type MapDigestConflictErr struct {
Digest string
}
MapDigestConflictErr indicates same digest found multiple times in the digest map (i.e., with different cases)
func (*MapDigestConflictErr) Error ¶ added in v0.0.17
func (d *MapDigestConflictErr) Error() string
type MapPathConflictErr ¶ added in v0.0.17
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 ¶ added in v0.0.17
func (p *MapPathConflictErr) Error() string
type MapPathInvalidErr ¶ added in v0.0.17
type MapPathInvalidErr struct {
Path string
}
MapPathInvalidErr indicates an invalid path in a Map.
func (*MapPathInvalidErr) Error ¶ added in v0.0.17
func (p *MapPathInvalidErr) Error() string
type ObjectRoot ¶ added in v0.0.15
type ObjectRoot struct {
FS FS // the FS where the object is stored
Path string // object path in FS
Spec Spec // the OCFL spec from the object's NAMASTE declaration
VersionDirs VNums // versions directories found in the object directory
Algorithm string // digest algorithm declared by the inventory sidecar
NonConform []string // non-conforming entries found in the object root (max=8)
Flags ObjectRootFlag
}
ObjectRoot represents an existing OCFL object root directory. Instances are typically created with functions like GetObjectRoot().
func GetObjectRoot ¶ added in v0.0.15
GetObjectRoot reads the contents of directory dir in fsys, confirms that an OCFL Object declaration is present, and returns a new ObjectRoot reference based on the directory contents. If the directory cannot be ready or a declaration is not found, ErrObjectNotFound is returned. Note, the object declaration is not read or fully validated. The returned ObjectRoot will have the FoundDeclaration flag set, but other flags expected for a complete object root may not be set (e.g., if the inventory is missing).
func InitObjectRoot ¶ added in v0.0.15
InitObjectRoot creates an OCFL object declaration file in the directory dir if one does not exist and the directory's contents do not include any non-conforming entries. If the directory does not exist, it is created along with all parent directories. If a declaration file exists, a fully initialized ObjectRoot is returned (same as GetObjectRoot) along with ErrObjectExists. In the latter case, the returned ObjectRoot's Spec value may not match the spec argument. If the directory includes any files or directories that do not conform to an OCFL object, an error is returned.
func NewObjectRoot ¶ added in v0.0.15
func NewObjectRoot(fsys FS, dir string, entries []fs.DirEntry) *ObjectRoot
NewObjectRoot constructs an ObjectRoot for the directory dir in fsys using the given fs.DirEntry slice as dir's contents. The returned ObjectRoot may be invalid.
func (ObjectRoot) HasDeclaration ¶ added in v0.0.15
func (obj ObjectRoot) HasDeclaration() bool
HasDeclaration returns true if the object's FoundDeclaration flag is set
func (ObjectRoot) HasInventory ¶ added in v0.0.15
func (obj ObjectRoot) HasInventory() bool
HasInventory returns true if the object's FoundInventory flag is set
func (ObjectRoot) HasSidecar ¶ added in v0.0.15
func (obj ObjectRoot) HasSidecar() bool
HasSidecar returns true if the object's FoundSidecar flag is set
func (ObjectRoot) HasVersionDir ¶ added in v0.0.15
func (obj ObjectRoot) HasVersionDir(dir VNum) bool
func (ObjectRoot) ValidateDeclaration ¶ added in v0.0.15
func (obj ObjectRoot) ValidateDeclaration(ctx context.Context) error
ValidateDeclaration reads and validates the contents of the OCFL object declaration in the object root.
type ObjectRootFlag ¶ added in v0.0.15
type ObjectRootFlag int
const ( // FoundDeclaration indicates that an ObjectRoot has been initialized // and an object declaration file is confirmed to exist in the object's root // directory FoundDeclaration ObjectRootFlag = 1 << iota // FoundInventory indicates that an ObjectRoot includes an "inventory.json" // file FoundInventory // FoundSidecar indicates that an ObjectRoot includes an "inventory.json.*" // file (the inventory sidecar). FoundSidecar // FoundExtensions indicates that an ObjectRoot includes a directory // named "extensions" FoundExtensions )
type ObjectRootIterator ¶ added in v0.0.15
type ObjectRootIterator interface {
// ObjectRoots searches root and its subdirectories for OCFL object declarations
// and calls fn for each object root it finds. The *ObjectRoot passed to fn is
// confirmed to have an object declaration, but no other validation checks are
// made.
ObjectRoots(ctx context.Context, sel PathSelector, fn func(obj *ObjectRoot) error) error
}
ObjectRootIterator is used to iterate over object roots
type ObjectState ¶ added in v0.0.15
type ObjectState struct {
DigestMap // digests / logical paths
Manifest DigestMap // digests / content paths
Alg digest.Alg // algorith used for digests
User *User // user who created object state
Created time.Time // object state created at
Message string // message associated with object state
VNum VNum // number for the object version for the state
Spec Spec // OCFL spec for the object version for the state
}
ObjectState encapsulates a set of logical content (i.e., an object version state) and its mapping to specific content paths in Manifest.
type ObjectStateFS ¶ added in v0.0.16
type ObjectStateFS struct {
ObjectState
// OpenContentFile opens a content file using the path from the object state
// manifest.
OpenContentFile func(ctx context.Context, name string) (fs.File, error)
// contains filtered or unexported fields
}
ObjectStateFS implements FS for the logical contents of the ObjectState
type PathSelector ¶ added in v0.0.15
type PathSelector struct {
// Dir is a parent directory for all paths that satisfy the selector. All
// paths in the selection match Dir or have Dir as a parent (prefix). If Dir
// is not a well-formed path (see fs.ValidPath), then no path names will
// satisfy the path selector. There is one exception: The empty string is
// converted to "." by consumers of the selector using Path().
Dir string
// SkipDirFn is used to skip directories during an iteration process. If the
// function returns true for a given path, the directory's contents will be
// skipped. The string parameter is always a directory name relative to an
// FS.
SkipDirFn func(dir string) bool
}
PathSelector is used to configure iterators that walk an FS. See FileIterator and ObjectRootIterator.
func Dir ¶ added in v0.0.15
func Dir(name string) PathSelector
Dir is a convenient way to construct a PathSelector for a given directory.
func (PathSelector) Path ¶ added in v0.0.15
func (ps PathSelector) Path() string
Path returns name as a valid path or an empty string if name is not a valid path
func (PathSelector) SkipDir ¶ added in v0.0.15
func (ps PathSelector) SkipDir(name string) bool
SkipDir returns true if dir should be skipped during an interation process that uses the path selector
type RemapFunc ¶ added in v0.0.17
RemapFunc is a function used to transform a DigestMap
type Spec ¶ added in v0.0.8
type Spec [2]int
Spec represent an OCFL specification number
func MustParseSpec ¶ added in v0.0.8
func (Spec) Cmp ¶ added in v0.0.8
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
func (Spec) MarshalText ¶ added in v0.0.8
func (*Spec) UnmarshalText ¶ added in v0.0.8
type Stage ¶ added in v0.0.11
type Stage struct {
State DigestMap // StageState
FS // FS for adding new content to the stage
Root string // base directory for all content
Alg digest.Alg // Primary digest algorith (sha512 or sha256)
// Number of go routines to use for concurrent digest during AddFS
Concurrency int
// contains filtered or unexported fields
}
Stage is used to construct, add content to, and manipulate an object state prior to commit. At minimum a stage includes a digest algorithm (sha512 or sha256) and a logical, which may be exported with the State method. A stage also tracks an internal manifest of new content added to the stage.
func NewStage ¶ added in v0.0.11
NewStage creates a new stage with the given digest algorithm, which should be either sha512 or sha256. If the stage will be used to update an object, the algorithm should match the object's. The new stage has an empty state and manifest and no backing FS. To add new content to the stage use AddFS or SetFS.
func (*Stage) AddFS ¶ added in v0.0.15
AddFS calls SetFS with the given FS and root directory and adds all files in the directory to the stage. Files in the root directory are digested using the stage's digest algorithm and optional fixity algorithms. Each file is added to the stage using UnsafeAddPath with file's path relative to the root directory and the calculated digest.
func (*Stage) AddPath ¶ added in v0.0.15
AddPath digests the file identified with name and adds the path to the stage. The path name and the associated digest are added to both the stage state and its manifest. The file is digested using the stage's primary digest algorith and any additional algorithms given by 'fixity'.
func (Stage) GetContent ¶ added in v0.0.15
GetContent returns the staged content paths for the given digest.
func (Stage) GetFixity ¶ added in v0.0.15
GetFixity returns altnerate digest values for the content with the primary digest value dig
func (Stage) Manifest ¶ added in v0.0.11
Manifest returns a DigestMap with content paths for digests in the stage state (if present in the stage manifest). Because manifest paths are not checked when they are added to the stage, it's possible for the manifest to be invalid, which is why this method can return an error.
func (*Stage) SetFS ¶ added in v0.0.15
SetFS sets the stage FS and root directory and clears any previously added content entries. It does not affect the stage's state.
func (*Stage) UnsafeAddPath ¶ added in v0.0.15
UnsafeAddPath adds name to the stage as both a logical path and a content path and associates name with the digests in the digest.Set. digests must include an entry with the stage's default digest algorithm. It is unsafe because neither the digest or the existence of the file are confirmed.
func (*Stage) UnsafeAddPathAs ¶ added in v0.0.15
UnsafeAddPathAs adds a logical path to the stage and the content path to the stage manifest. It is unsafe because neither the digest or the existence of the file are confirmed. If the content path is empty, the manifest is not updated; similarly, if the logical path is empty, the stage state is not updated. This allows for selectively adding entries to either the stage manifest or the stage state.
type VNum ¶ added in v0.0.8
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 value constraints the maximum valid sequence number.
func MustParseVNum ¶ added in v0.0.8
MustParseVNum parses str as a VNUm and returns a new VNum. It panics if str cannot be parsed as a VNum.
func V ¶ added in v0.0.8
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 ¶ added in v0.0.8
func (VNum) Next ¶ added in v0.0.8
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 ¶ added in v0.0.8
Prev returns the previous version before v, with the same padding. An error is returned if v.Num() == 1
func (*VNum) UnmarshalText ¶ added in v0.0.8
type VNums ¶ added in v0.0.13
type VNums []VNum
VNums is a slice of VNum elements
type WriteFS ¶ added in v0.0.8
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.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
backend
|
|
|
examples
|
|
|
commit
command
|
|
|
listobjects
command
|
|
|
validate
command
|
|
|
internal
|
|
|
pathtree
Package pathree provides Node[T] and generic functions used for storing arbitrary values in a hierarchical data structure following filesystem naming conventions.
|
Package pathree provides Node[T] and generic functions used for storing arbitrary values in a hierarchical data structure following filesystem naming conventions. |
|
Package [ocflv1] provides an implementation of OCFL v1.0 and v1.1.
|
Package [ocflv1] provides an implementation of OCFL v1.0 and v1.1. |
|
codes/generate
command
|
|