ocfl

package module
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

README

An OCFL implementation for Go

godocs

This is an implementation of the Oxford Common File Layout (OCFL) for Go. The API is under heavy development and will have constant breaking changes.

What is OCFL?

This Oxford Common File Layout (OCFL) specification describes an application-independent approach to the storage of digital information in a structured, transparent, and predictable manner. It is designed to promote long-term object management best practices within digital repositories. (https://ocfl.io/)

Functionality

Here is a high-level overview of what's working and what's not:

  • Both file system and cloud storage backends (via gocloud)
  • Storage root creation and validation
  • Object creation and validation
  • Flexible API for 'staging' object changes between versions.
  • Support for OCFL v1.0 and v1.1
  • Reasonable test coverage
  • Ability to purge objects from a storage root
  • Consistent, informative error/log messages
  • Well-documented API
  • Stable API

Development

Requires go >= 1.20.

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

View Source
const (
	DeclObject = "ocfl_object" // type string for OCFL Object declaration
	DeclStore  = "ocfl"        // type string for OCFL Storage Root declaration
)
View Source
const (
	OBJECTSTATE_DEFAULT_FILEMODE fs.FileMode = 0440
	OBJECTSTATE_DEFAULT_DIRMODE              = 0550 | fs.ModeDir
)
View Source
const (
	// package version
	Version       = "0.0.17"
	ExtensionsDir = "extensions"
)

Variables

View Source
var (
	ErrDeclNotExist = fmt.Errorf("missing declaration: %w", fs.ErrNotExist)
	ErrDeclInvalid  = errors.New("invalid NAMASTE declaration contents")
	ErrDeclMultiple = errors.New("multiple NAMASTE declarations found")
)
View Source
var (
	Spec1_0 = Spec{1, 0}
	Spec1_1 = Spec{1, 1}
)
View Source
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")
)
View Source
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{}
)
View Source
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

View Source
var ErrNotFile = errors.New("not a file")
View Source
var (
	ErrObjectExists = errors.New("OCFL object declaration already exists")
)
View Source
var ErrSpecInvalid = errors.New("invalid OCFL spec version")
View Source
var ErrSpecNotFound = errors.New("OCFL spec file not found")

Functions

func AlgRegistry added in v0.0.11

func AlgRegistry() *digest.Registry

AlgRegistry returns the global digest algorithm registry

func Files added in v0.0.15

func Files(ctx context.Context, fsys FS, pth PathSelector, fn func(name string) error) error

Files walks the directory tree under root, calling fn

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 ParseSpec added in v0.0.8

func ParseSpec(v string, n *Spec) error

func ParseVNum added in v0.0.8

func ParseVNum(v string, vn *VNum) error

ParseVNum parses string as an a VNum and sets the value referenced by vn.

func ReadDeclaration added in v0.0.16

func ReadDeclaration(ctx context.Context, fsys FS, filePath string) error

ReadDeclaration validates a namaste declaration

func WriteDeclaration added in v0.0.8

func WriteDeclaration(ctx context.Context, root WriteFS, dir string, d Declaration) error

func WriteSpecFile added in v0.0.11

func WriteSpecFile(ctx context.Context, fsys WriteFS, dir string, n Spec) (string, error)

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

type Declaration struct {
	Type    string
	Version Spec
}

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

func (DigestErr) Error added in v0.0.17

func (e DigestErr) Error() string

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

func NewDigestMap(digests map[string][]string) (DigestMap, error)

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

func (m DigestMap) DigestPaths(dig string) []string

DigestPaths returns the slice of paths associated with digest dig

func (DigestMap) Digests added in v0.0.17

func (m DigestMap) Digests() []string

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

func (m DigestMap) EachDigest(fn func(digest string, paths []string) bool) bool

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

func (m DigestMap) EachPath(fn func(pth, digest string) bool) bool

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

func (m DigestMap) Eq(other DigestMap) bool

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

func (m DigestMap) GetDigest(p string) string

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

func (m DigestMap) HasDigest(dig string) bool

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

func (m DigestMap) HasLowercaseDigest() bool

HasLowercaseDigest returns true if m includes a digest value with lowercase characters.

func (DigestMap) HasUppercaseDigest added in v0.0.17

func (m DigestMap) HasUppercaseDigest() bool

HasUpperCaseDigest returns true if m includes digest values with uppercase characters.

func (DigestMap) LenDigests added in v0.0.17

func (m DigestMap) LenDigests() int

LenDigests returns the number of digests in the DigestMap

func (DigestMap) LenPaths added in v0.0.17

func (m DigestMap) LenPaths() int

Lenpaths returns the number of paths in the DigestMap

func (DigestMap) MarshalJSON added in v0.0.17

func (m DigestMap) MarshalJSON() ([]byte, error)

func (DigestMap) Merge added in v0.0.17

func (m1 DigestMap) Merge(m2 DigestMap, replace bool) (merged DigestMap, err error)

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

func (m DigestMap) Normalize() (norm DigestMap, err error)

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

func (m DigestMap) PathMap() map[string]string

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

func (m DigestMap) PathMapValid() (map[string]string, error)

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

func (m DigestMap) Paths() []string

Paths returns a sorted slice of all path names in the DigestMap.

func (DigestMap) Remap added in v0.0.17

func (m DigestMap) Remap(fns ...RemapFunc) (DigestMap, error)

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

func (m *DigestMap) UnmarshalJSON(b []byte) error

func (DigestMap) Valid added in v0.0.17

func (m DigestMap) Valid() error

Valid returns a non-nil error if m is invalid.

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.

func DirFS added in v0.0.9

func DirFS(dir string) FS

DirFS is shorthand for NewFS(os.DirFS(dir))

func NewFS added in v0.0.8

func NewFS(fsys fs.FS) FS

NewFS wraps an io/fs.FS as an ocfl.FS

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 (invT InvType) MarshalText() ([]byte, error)

func (InvType) String added in v0.0.8

func (inv InvType) String() string

func (*InvType) UnmarshalText added in v0.0.8

func (invT *InvType) UnmarshalText(t []byte) error

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

func GetObjectRoot(ctx context.Context, fsys FS, dir string) (*ObjectRoot, error)

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

func InitObjectRoot(ctx context.Context, fsys WriteFS, dir string, spec Spec) (*ObjectRoot, error)

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

func (*ObjectStateFS) OpenFile added in v0.0.16

func (state *ObjectStateFS) OpenFile(ctx context.Context, name string) (fs.File, error)

OpenFile is used to access files in the Objects State by their logical paths

func (*ObjectStateFS) ReadDir added in v0.0.16

func (state *ObjectStateFS) ReadDir(ctx context.Context, dirPath string) ([]fs.DirEntry, error)

OpenDir is used to access directories in the Objects State by their logical paths

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

type RemapFunc func(digest string, oldPaths []string) (newPaths []string)

RemapFunc is a function used to transform a DigestMap

func Remove added in v0.0.17

func Remove(name string) RemapFunc

Remove returns a RemapFunc that removes name.

func Rename added in v0.0.17

func Rename(from, to string) RemapFunc

Rename returns a RemapFunc that renames from to to.

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 MustParseSpec(v string) Spec

func (Spec) AsInvType added in v0.0.8

func (n Spec) AsInvType() InvType

AsInvType returns n as an InventoryType

func (Spec) Cmp added in v0.0.8

func (v1 Spec) Cmp(v2 Spec) int

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) Empty added in v0.0.8

func (n Spec) Empty() bool

func (Spec) MarshalText added in v0.0.8

func (num Spec) MarshalText() ([]byte, error)

func (Spec) String added in v0.0.8

func (n Spec) String() string

func (*Spec) UnmarshalText added in v0.0.8

func (num *Spec) UnmarshalText(text []byte) error

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

func NewStage(alg digest.Alg) *Stage

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

func (stage *Stage) AddFS(ctx context.Context, fsys FS, root string, fixity ...digest.Alg) error

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

func (stage *Stage) AddPath(ctx context.Context, name string, fixity ...digest.Alg) error

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

func (stage Stage) GetContent(dig string) []string

GetContent returns the staged content paths for the given digest.

func (Stage) GetFixity added in v0.0.15

func (stage Stage) GetFixity(dig string) digest.Set

GetFixity returns altnerate digest values for the content with the primary digest value dig

func (Stage) Manifest added in v0.0.11

func (stage Stage) Manifest() (DigestMap, error)

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

func (stage *Stage) SetFS(fsys FS, dir string)

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

func (stage *Stage) UnsafeAddPath(name string, digests digest.Set) error

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

func (stage *Stage) UnsafeAddPathAs(content string, logical string, digests digest.Set) error

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.

func (*Stage) UnsafeSetManifestFixty added in v0.0.15

func (stage *Stage) UnsafeSetManifestFixty(manifest DigestMap, fixity map[string]DigestMap) error

UnsafeSetManifestFixty replaces the stage's existing content paths and fixity values to match manifest and fixity.

type User added in v0.0.16

type User struct {
	Name    string `json:"name"`
	Address string `json:"address,omitempty"`
}

User is a generic user information struct

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

func MustParseVNum(str string) VNum

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

func V(ns ...int) VNum

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) AsHead added in v0.0.13

func (v VNum) AsHead() VNums

AsHead returns a VNums with v as the head.

func (VNum) First added in v0.0.9

func (v VNum) First() bool

First returns true if v is a version 1.

func (VNum) IsZero added in v0.0.13

func (v VNum) IsZero() bool

IsZero returns if v is the zero value

func (VNum) MarshalText added in v0.0.8

func (v VNum) MarshalText() ([]byte, error)

func (VNum) Next added in v0.0.8

func (v VNum) Next() (VNum, error)

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) Num added in v0.0.8

func (v VNum) Num() int

Num returns v's number as an int

func (VNum) Padding added in v0.0.8

func (v VNum) Padding() int

Padding returns v's padding number.

func (VNum) Prev added in v0.0.8

func (v VNum) Prev() (VNum, error)

Prev returns the previous version before v, with the same padding. An error is returned if v.Num() == 1

func (VNum) String added in v0.0.8

func (v VNum) String() string

String returns string representation of v

func (*VNum) UnmarshalText added in v0.0.8

func (v *VNum) UnmarshalText(text []byte) error

func (VNum) Valid added in v0.0.8

func (v VNum) Valid() error

Valid returns an error if v is invalid

type VNums added in v0.0.13

type VNums []VNum

VNums is a slice of VNum elements

func (VNums) Head added in v0.0.13

func (vs VNums) Head() VNum

Head returns the last VNum in vs.

func (VNums) Len added in v0.0.13

func (vs VNums) Len() int

Len implements sort.Interface on VNums

func (VNums) Less added in v0.0.13

func (vs VNums) Less(i, j int) bool

Less implements sort.Interface on VNums

func (VNums) Padding added in v0.0.13

func (vs VNums) Padding() int

Padding returns the padding for the VNums in vs

func (VNums) Swap added in v0.0.13

func (vs VNums) Swap(i, j int)

Swap implements sort.Interface on VNums

func (VNums) Valid added in v0.0.13

func (vs VNums) Valid() error

Valid returns a non-nill error if VNums is empty, is not a continuous sequence (1,2,3...), has inconsistent padding or padding overflow.

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.

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

Jump to

Keyboard shortcuts

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