object

package
v3.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

OCFL Object Package

The pkg/ocfl/object package provides the core interfaces for managing OCFL (Oxford Common File Layout) objects. It handles high-level orchestration for operations such as initialization, loading, updating, extraction, and validation.

Key Features

  • Abstraction: Decouples object operations from specific OCFL versions and storage implementations.
  • Modularity: Operations are divided into specialized modules:
  • Extension Support: A robust Extension System for customizing behavior.
  • Factory Integration: Works with the OCFL Factory to instantiate the appropriate version-specific implementations.

Documentation

See the Object Documentation Overview for technical details and architecture diagrams.

Usage Overview

High-level operations are typically performed via the ocfl package.

import (
    "github.com/ocfl-archive/gocfl/v3/pkg/ocfl"
)

// Load an object (recommended)
obj, err := ocfl.LoadObject(ctx, sourceFS, nil, logger)
if err != nil {
    // handle error
}
// obj should be closed if it implements io.Closer
if closer, ok := obj.(io.Closer); ok {
    defer closer.Close()
}

// Access metadata via the Extractor
extractor := obj.GetExtractor()
defer extractor.Close()
metadata, err := extractor.GetMetadata()

For advanced scenarios, interact directly with specialized modules. See Function Modules for more information.

Documentation

Overview

Package object contains the interfaces and implementations for OCFL objects.

Package object contains the interfaces and abstractions for managing OCFL (Oxford Common File Layout) objects.

Unlike the inventory package, which focuses on data structures and JSON representation, the object package handles the high-level orchestration of object operations like initialization, loading, updating, extraction, and validation.

Index

Constants

View Source
const (
	// ExtensionStorageRootPathName is the name of the StorageRootPath extension.
	ExtensionStorageRootPathName = "StorageRootPath"
	// ExtensionObjectContentPathName is the name of the ObjectContentPath extension.
	ExtensionObjectContentPathName = "ObjectContentPath"
	// ExtensionObjectExtractPathName is the name of the ObjectExtractPath extension.
	ExtensionObjectExtractPathName = "ObjectExtractPath"
	// ExtensionObjectExternalPathName is the name of the ObjectExternalPath extension.
	ExtensionObjectExternalPathName = "ObjectExternalPath"
	// ExtensionContentChangeName is the name of the ContentChange extension.
	ExtensionContentChangeName = "ContentChange"
	// ExtensionObjectChangeName is the name of the ObjectChange extension.
	ExtensionObjectChangeName = "ObjectChange"
	// ExtensionFixityDigestName is the name of the FixityDigest extension.
	ExtensionFixityDigestName = "FixityDigest"
	// ExtensionMetadataName is the name of the Metadata extension.
	ExtensionMetadataName = "Metadata"
	// ExtensionAreaName is the name of the Area extension.
	ExtensionAreaName = "Area"
	// ExtensionStreamName is the name of the Stream extension.
	ExtensionStreamName = "Stream"
	// ExtensionNewVersionName is the name of the NewVersion extension.
	ExtensionNewVersionName = "NewVersion"
	// ExtensionVersionDoneName is the name of the VersionDone extension.
	ExtensionVersionDoneName = "VersionDone"
	// ExtensionInitialName is the name of the Initial extension.
	ExtensionInitialName = "Initial"
)

Variables

View Source
var ExtensionObjectExtractPathWrongAreaError = errors.New("invalid area")

ExtensionObjectExtractPathWrongAreaError is returned when an invalid area is provided to an ObjectExtractPath extension.

View Source
var StatInfoString = map[string]StatInfo{
	"ObjectFolders":          StatObjectFolders,
	"Extension":              StatExtension,
	"ExtensionConfigs":       StatExtensionConfigs,
	"Objects":                StatObjects,
	"ObjectVersions":         StatObjectVersions,
	"ObjectVersionState":     StatObjectVersionState,
	"ObjectManifest":         StatObjectManifest,
	"ObjectExtension":        StatObjectExtension,
	"ObjectExtensionConfigs": StatObjectExtensionConfigs,
}

StatInfoString maps string representations to StatInfo values.

Functions

This section is empty.

Types

type ConfigName added in v3.0.3

type ConfigName string

ConfigName represents the name of a configuration parameter for the object factory.

const (
	// ObjectName is the configuration name for the object instance.
	ObjectName ConfigName = "object"
	// ValidatorName is the configuration name for the validator instance.
	ValidatorName ConfigName = "validator"
	// LoaderName is the configuration name for the loader instance.
	LoaderName ConfigName = "loader"
	// InitializerName is the configuration name for the initializer instance.
	InitializerName ConfigName = "initializer"
	// ExtractorName is the configuration name for the extractor instance.
	ExtractorName ConfigName = "extractor"
	// VersionWriterName is the configuration name for the version writer instance.
	VersionWriterName ConfigName = "versionwriter"
	// VersionFSMapName is the configuration name for the version FS map instance.
	VersionFSMapName ConfigName = "versionfsmap"
)

type ExtensionArea

type ExtensionArea interface {
	extension.Extension
	// GetAreaPath returns the path for a given area.
	GetAreaPath(area string) (string, error)
}

ExtensionArea is an interface for extensions that can provide area paths.

type ExtensionContentChange

type ExtensionContentChange interface {
	extension.Extension
	// AddFileBefore is called before a file is added to an object.
	AddFileBefore(object VersionWriter, sourceFS fs.FS, source string, dest string, area string, isDir bool) error
	// UpdateFileBefore is called before a file is updated in an object.
	UpdateFileBefore(object VersionWriter, sourceFS fs.FS, source, dest, area string, isDir bool) error
	// DeleteFileBefore is called before a file is deleted from an object.
	DeleteFileBefore(versionWriter VersionWriter, dest string, area string) error
	// AddFileAfter is called after a file is added to an object.
	AddFileAfter(versionWriter VersionWriter, sourceFS fs.FS, source []string, internalPath, digest, area string, isDir bool) error
	// UpdateFileAfter is called after a file is updated in an object.
	UpdateFileAfter(object VersionWriter, sourceFS fs.FS, source, area string, isDir bool) error
	// DeleteFileAfter is called after a file is deleted from an object.
	DeleteFileAfter(object VersionWriter, dest string, area string) error
}

ExtensionContentChange is an interface for extensions that are notified of content changes.

type ExtensionFixityDigest

type ExtensionFixityDigest interface {
	extension.Extension
	// GetFixityDigests returns the fixity digests provided by the extension.
	GetFixityDigests() []checksum.DigestAlgorithm
}

ExtensionFixityDigest is an interface for extensions that provide fixity digests.

type ExtensionMetadata

type ExtensionMetadata interface {
	extension.Extension
	// GetMetadata returns the metadata for an object.
	GetMetadata(sourceFS fs.FS, obj Object) (map[string]any, error)
}

ExtensionMetadata is an interface for extensions that provide object metadata.

type ExtensionNewVersion

type ExtensionNewVersion interface {
	extension.Extension
	// NeedNewVersion returns true if a new version is needed. Called at the end of version Close().
	NeedNewVersion(object VersionWriter) (bool, error)
	// DoNewVersion performs actions for the automatically created new version.
	DoNewVersion(object VersionWriter) error
}

ExtensionNewVersion is an interface for extensions that can determine if a new version is needed (e.g. for automatic metadata) and perform actions for this new version.

type ExtensionObjectChange

type ExtensionObjectChange interface {
	extension.Extension
	// UpdateObjectBefore is called before an object is updated.
	UpdateObjectBefore(object VersionWriter) error
	// UpdateObjectAfter is called after an object is updated.
	UpdateObjectAfter(object VersionWriter) error
}

ExtensionObjectChange is an interface for extensions that are notified of object changes.

type ExtensionObjectContentPath

type ExtensionObjectContentPath interface {
	extension.Extension
	// BuildObjectManifestPath builds an object manifest path from an original path and an area.
	BuildObjectManifestPath(originalPath string, area string) (string, error)
}

ExtensionObjectContentPath is an interface for extensions that can build object manifest paths.

type ExtensionObjectExtractPath

type ExtensionObjectExtractPath interface {
	extension.Extension
	// BuildObjectExtractPath builds an object extract path from an original path and an area.
	BuildObjectExtractPath(originalPath string, area string) (string, error)
}

ExtensionObjectExtractPath is an interface for extensions that can build object extract paths.

type ExtensionObjectStatePath

type ExtensionObjectStatePath interface {
	extension.Extension
	// BuildObjectStatePath builds an object state path from an original path and an area.
	BuildObjectStatePath(originalPath string, area string) (string, error)
}

ExtensionObjectStatePath is an interface for extensions that can build object state paths.

type ExtensionStream

type ExtensionStream interface {
	extension.Extension
	// StreamObject streams an object's content.
	// All registered StreamObject hooks are called in parallel, as the data stream is split using io.MultiWriter.
	StreamObject(object VersionWriter, reader io.Reader, stateFiles []string, dest string) error
}

ExtensionStream is an interface for extensions that can stream objects.

type ExtensionVersionDone

type ExtensionVersionDone interface {
	extension.Extension
	// VersionDone is called when a version is done.
	VersionDone(object Object) error
}

ExtensionVersionDone is an interface for extensions that are notified when a version is done.

type Extractor

type Extractor interface {
	io.Closer
	// Extract extracts a specific version of the object.
	Extract(version *inventory.VersionNumber, withManifest bool, area string) error
	// WithObject sets the object to extract from.
	WithObject(o Object) Extractor
	// WithDestFS sets the destination filesystem for extraction.
	WithDestFS(destFS appendfs.FS) Extractor
	// GetExtensionFileReader returns a reader for a file within an extension.
	GetExtensionFileReader(extensionName string, path string) (io.ReadCloser, int64, string, error)
	// GetFileReader returns a reader for a file in the object.
	GetFileReader(name string) (io.ReadCloser, int64, string, error)
	// GetMetadata returns the metadata of the object.
	GetMetadata() (*inventory.Metadata, error)
}

Extractor is the interface for extracting content from an OCFL object.

type Factory

type Factory interface {
	// NewObject creates a new Object instance.
	NewObject(ctx context.Context) Object
	// NewLoader creates a new Loader instance.
	NewLoader(ctx context.Context) Loader
	// NewInitializer creates a new Initializer instance.
	NewInitializer(ctx context.Context) Initializer
	// NewValidator creates a new Validator instance.
	NewValidator(ctx context.Context) Validator
	// NewExtractor creates a new Extractor instance.
	NewExtractor(ctx context.Context) Extractor
	// NewVersionWriter creates a new VersionWriter instance.
	NewVersionWriter(ctx context.Context) VersionWriter
	// NewVersionFSMap creates a new VersionFSMap instance.
	NewVersionFSMap(ctx context.Context) VersionFSMap
}

Factory is the interface for creating object components.

This interface is also implemented by the Unified Factory in pkg/ocfl/factory/factory.go. It's recommended to use the Unified Factory instead of calling this interface directly.

type Initializer

type Initializer interface {
	io.Closer
	// Init initializes the object with the given ID and algorithms.
	Init(id string, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm) error
	// WithObject sets the object to be initialized.
	WithObject(o Object) Initializer
}

Initializer is the interface for creating a new OCFL object.

type Loader

type Loader interface {
	io.Closer
	// Load reads the object's inventory and state.
	Load() error
	// WithObject sets the object to be loaded.
	WithObject(o Object) Loader
	// GetFS returns the underlying filesystem.
	GetFS() fs.FS
	// SetExtensionFactory sets the factory for extension management.
	SetExtensionFactory(factory extension.Factory[ExtensionManager]) Loader
}

Loader is the interface for loading an existing OCFL object.

type NamesStruct

type NamesStruct struct {
	ExternalPaths []string // Paths outside the OCFL object.
	InternalPath  string   // Path within the OCFL object version state.
	ManifestPath  string   // Path within the OCFL object content directory.
}

NamesStruct contains different path representations of a file.

type Object

type Object interface {
	io.Closer
	// GetExtractor returns an Extractor for this object.
	GetExtractor() Extractor
	// GetInitializer returns an Initializer for this object.
	GetInitializer() Initializer
	// GetLoader returns a Loader for this object.
	GetLoader() Loader
	// WithInventory sets the inventory for the object.
	WithInventory(inv inventory.Inventory) Object
	// WithExtensionManager sets the extension manager for the object.
	WithExtensionManager(manager ExtensionManager) Object
	// WithReadFS sets the read-only filesystem for the object.
	WithReadFS(fsys fs.FS) Object
	// WithWriteFS sets the writable filesystem for the object.
	WithWriteFS(fsys appendfs.FS) Object
	// GetReadFS returns the read-only filesystem.
	GetReadFS() fs.FS
	// GetWriteFS returns the writable filesystem.
	GetWriteFS() appendfs.FS
	// StartUpdate begins a new version update.
	StartUpdate(msg string, UserName string, UserAddress string, echo bool) (VersionWriter, error)
	// GetID returns the object ID.
	GetID() string
	// GetInventory returns the current inventory.
	GetInventory() inventory.Inventory
	// Stat writes statistical information about the object.
	Stat(w io.Writer, statInfo []StatInfo) error
	// GetExtensionManager returns the extension manager.
	GetExtensionManager() ExtensionManager
	// GetOCFLVersion returns the OCFL version of the object.
	GetOCFLVersion() version.OCFLVersion
	// GetValidator returns a Validator for this object.
	GetValidator() Validator
}

Object is the main interface representing an OCFL object.

type StatInfo

type StatInfo int64

StatInfo is a type for statistical information about an OCFL object.

const (
	StatObjectFolders          StatInfo = iota // Count of folders in the object.
	StatExtension                              // Extension information.
	StatExtensionConfigs                       // Extension configuration information.
	StatObjects                                // Count of objects.
	StatObjectVersions                         // Count of object versions.
	StatObjectVersionState                     // State of object versions.
	StatObjectManifest                         // Object manifest information.
	StatObjectExtension                        // Object extension information.
	StatObjectExtensionConfigs                 // Object extension configuration information.
)

type Validator added in v3.0.5

type Validator interface {
	io.Closer
	// Check performs the validation of the object.
	Validate() error
	// WithObject sets the object to be checked.
	WithObject(obj Object) Validator
}

Validator is the interface for validating an OCFL object.

type VersionFSMap added in v3.0.5

type VersionFSMap interface {
	WithBaseFS(baseFS fs.FS) VersionFSMap
	GetVersionFS(version *inventory.VersionNumber) (fs.FS, error)
	Close() error
}

type VersionWriter

type VersionWriter interface {
	io.Closer
	// AddFolder adds all files from a folder to the version.
	AddFolder(sourceFS fs.FS, checkDuplicate bool, area string) error
	// AddFile adds a single file from a filesystem to the version.
	AddFile(sourceFS fs.FS, path string, checkDuplicate bool, area string, noExtensionHook bool, isDir bool) error
	// AddData adds data from a byte slice as a file to the version.
	AddData(data []byte, path string, checkDuplicate bool, area string, noExtensionHook bool, isDir bool) error
	// AddReader adds data from an io.ReadCloser to the version.
	AddReader(r io.ReadCloser, files []string, area string, noExtensionHook bool, isDir bool) (string, error)
	// DeleteFile removes a file from the version state.
	DeleteFile(virtualFilename string, digest string) error
	// RenameFile changes the path of a file in the version state.
	RenameFile(virtualFilenameSource, virtualFilenameDest string, digest string) error
	// GetID returns the object ID.
	GetID() string
	// GetFS returns the underlying appendfs.FS.
	GetFS() appendfs.FS
	// BeginArea starts a new area (e.g. for extensions).
	BeginArea(area string)
	// EndArea ends the current area.
	EndArea() error
	// BuildNames constructs a NamesStruct for a list of files.
	BuildNames(files []string, area string) (*NamesStruct, error)
	// WithObject sets the object for the VersionWriter.
	WithObject(obj Object) VersionWriter
	// WithEcho sets whether to echo operations.
	WithEcho(echo bool) VersionWriter
	// Init initializes the VersionWriter with user information.
	Init(msg string, name string, address string) error
	// GetObject returns the associated Object.
	GetObject() Object
}

VersionWriter is the interface for adding or modifying files in an OCFL object version.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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