gocfl

module
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

README

GOCFL - Go OCFL Library

gocfl is a high-performance Go library for the Oxford Common Filesystem Layout (OCFL). It focuses on the creation, update, validation, and extraction of OCFL Storage Roots and Objects, with a strong emphasis on extensibility, I/O efficiency, and technical metadata indexing.

Note: This repository contains the gocfl library. For the command-line interface, please refer to the gocfl-cli repository.

For additional extensions, please refer to the gocfl-extensions repository.

Features

  • OCFL Support: Full support for OCFL v1.0 and v1.1, with experimental support for v2.0.
  • Storage Backends:
    • Local Filesystem
    • S3 Cloud Storage (via MinIO Client SDK)
    • Serialization into ZIP Containers (with optional AES Encryption)
  • High Performance:
    • Optimized I/O: Files are read and written as few times as possible.
    • Concurrent checksum generation and processing.
  • Extensibility: Implements a flexible extension hook system (7 different hooks) for both Storage Root and Object extensions.
  • Advanced Capabilities:
    • Technical metadata extraction and indexing.
    • File format migration.
    • Thumbnail generation.
    • METS/PREMIS generation.

Installation

go get github.com/ocfl-archive/gocfl/v3

Basic Usage

The library provides convenient functions in the ocfl package for common tasks.

Initializing and Loading a Storage Root
import (
    "context"
    "github.com/ocfl-archive/gocfl/v3/pkg/ocfl"
    "github.com/ocfl-archive/gocfl/v3/pkg/ocfl/version"
    "github.com/ocfl-archive/gocfl/v3/pkg/ocfllogger"
    "github.com/je4/utils/v2/pkg/checksum"
)

ctx := context.Background()
logger := ocfllogger.NewNopLogger()

// Initialize a new storage root (needs an appendfs.FS)
sr, err := ocfl.InitStorageRoot(ctx, fsys, nil, version.Version1_1, checksum.DigestSHA512, nil, logger)

// Load an existing storage root (needs an fs.FS)
sr, err := ocfl.LoadStorageRoot(ctx, fsys, nil, nil, logger)
if err != nil {
    // handle error
}
// sr should be closed if it implements io.Closer
if closer, ok := sr.(io.Closer); ok {
    defer closer.Close()
}
Working with Objects
// Load an object from a filesystem
obj, err := ocfl.LoadObject(ctx, objFsys, 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()
}

// Add files to an object
writer, err := obj.StartUpdate("initial commit", "user", "user@example.com", false)
if err != nil {
    // handle error
}
defer writer.Close()
err = writer.AddFolder(sourceFS, true, "")
err = writer.Close()
Validation and Extraction
import (
    "github.com/ocfl-archive/gocfl/v3/pkg/ocfl"
    "github.com/ocfl-archive/gocfl/v3/pkg/ocfl/inventory"
)

// Validate an object
err := ocfl.ValidateObject(ctx, objFsys, logger)

// Extract an object
err := ocfl.Extract(ctx, objectFS, destFS, "object_path", inventory.NewVersionNumber(), true, "", logger)

Examples

The examples directory contains runnable Go programs for common tasks:

Documentation

License

GOCFL is licensed under the Apache License, Version 2.0. See LICENSE for details.

Directories

Path Synopsis
examples
create command
object_add command
object_extract command
object_metadata command
object_upd command
object_validate command
pkg
extensions/ext_NNNN_gocfl_extension_manager
Package ext_NNNN_gocfl_extension_manager implements the OCFL "NNNN-gocfl-extension-manager" extension.
Package ext_NNNN_gocfl_extension_manager implements the OCFL "NNNN-gocfl-extension-manager" extension.
extensions/ext_initial
Package ext_initial implements the OCFL "initial" extension.
Package ext_initial implements the OCFL "initial" extension.
ocfl
Package ocfl provides high-level functions for interacting with OCFL objects.
Package ocfl provides high-level functions for interacting with OCFL objects.
ocfl/extension
Package extension provides the basic interfaces and structures for OCFL extensions.
Package extension provides the basic interfaces and structures for OCFL extensions.
ocfl/factory
Package factory provides unified factory interfaces for creating OCFL objects and storage roots.
Package factory provides unified factory interfaces for creating OCFL objects and storage roots.
ocfl/inventory
Package inventory defines the structures and interfaces for the OCFL (Oxford Common File Layout) Inventory.
Package inventory defines the structures and interfaces for the OCFL (Oxford Common File Layout) Inventory.
ocfl/object
Package object contains the interfaces and implementations for OCFL objects.
Package object contains the interfaces and implementations for OCFL objects.
ocfl/storageroot
Package storageroot contains the interfaces and abstractions for managing OCFL (Oxford Common File Layout) storage roots.
Package storageroot contains the interfaces and abstractions for managing OCFL (Oxford Common File Layout) storage roots.
ocfl/validation
Package validation provides structures and functions for handling OCFL validation errors and warnings.
Package validation provides structures and functions for handling OCFL validation errors and warnings.
ocfl/version
Package version defines the supported OCFL versions and provides utilities for version comparison and specification access.
Package version defines the supported OCFL versions and provides utilities for version comparison and specification access.
ocfllogger/ocflloggerimpl
Package ocfllogger provides a logging interface for OCFL operations that integrates with the OCFL validation system.
Package ocfllogger provides a logging interface for OCFL operations that integrates with the OCFL validation system.

Jump to

Keyboard shortcuts

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