metadata

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package metadata contains facilities for working with OCFL object metadata. At the moment, it is mostly a 1:1 reflection inventory.json files.

One notable exception is the File type, which consolidates information derivable from the Inventory via joins, e.g. the physical paths, logical paths, and fixity for individual files within versions. A convenience method will generate File metadata when desired.

It may be necessary at some point to develop additional abstractions on OCFL metadata when considering alternate source such as databases, which are not structured like an inventory.json file

Index

Constants

View Source
const InventoryFile = "inventory.json"

InventoryFile contains the name of OCFL inventory files

View Source
const InventoryType = "https://ocfl.io/1.0/spec/#inventory"

InventoryType contains the expected "type" value of an OCFL object

Variables

This section is empty.

Functions

func Parse

func Parse(r io.Reader, i *Inventory) error

Parse parses a byte stream into OCFL inventory metadata

Types

type Digest

type Digest string

Digest is a lowercase hex string representing a digest, as defined by inventory.json in the OCFL spec

type DigestAlgorithm

type DigestAlgorithm string

DigestAlgorithm is identifier for an ocfl-approved digest algorithm, as defined by inventory.json in the OCFL spec

type File

type File struct {
	Version      *Version
	Inventory    *Inventory
	LogicalPath  string
	PhysicalPath string
	Fixity       map[DigestAlgorithm]Digest
}

File describes individual files within an OCFL object. It is constructed from the contents if an OCFL inventory, but is not directly defined by it.

type Fixity

type Fixity map[DigestAlgorithm]Manifest

Fixity is a map of digest algorithms to digests to paths, as defined by inventory.json in the OCFL spec

type Inventory

type Inventory struct {
	ID              string             `json:"id"`
	Type            string             `json:"type"`
	DigestAlgorithm DigestAlgorithm    `json:"digestAlgorithm"`
	Head            string             `json:"head"`
	Manifest        Manifest           `json:"manifest"`
	Versions        map[string]Version `json:"versions"`
	Fixity          Fixity             `json:"fixity"`
	// contains filtered or unexported fields
}

Inventory defines the contents of an OCFL object, as defined by inventory.json in the OCFL spec

func NewInventory

func NewInventory(id string) *Inventory

NewInventory creates a new, empty inventory with reasonable defaults: sha512 digest algorithm (can be changed by callee if need be), with an empty "v1" version. The manifest and v1's state are initialized with empty maps.

func (*Inventory) DeleteFile added in v0.2.0

func (i *Inventory) DeleteFile(logicalPath string) error

func (*Inventory) Files

func (i *Inventory) Files(version string) ([]File, error)

Files consolidates metadata for each logical file in a version

We want a physical path for every logical file in a version. However, there may be none (inconsistent manifest), or several (allowed by OCFL). This function returns the "newest" one corresponding to the given version. That is to say, if the manifest lists [v1/content/foo.txt, v2/content/foo.txt, v3/content/foo.txt] as having the same hash, and the given version is v2, then it'll return v2/foo.txt

func (*Inventory) PutFile

func (i *Inventory) PutFile(logicalPath, relativePhysicalPath string, digest Digest) error

PutFile adds a logical file to the OCFL manifest and HEAD version state, overwriting any existing entries if present.

func (*Inventory) Serialize

func (i *Inventory) Serialize(w io.Writer) error

Serialize writes the contents of the inventory to json

func (*Inventory) Validate

func (i *Inventory) Validate() error

Validate verifies whether inventory metadata is internally consistent and allowable by the OCFL spec A positive result (no error returned) means only that a given manifest reflects a plausible internal state. It does not imply that the files referenced by the manifest actually exist, or match their claimed checksums, etc.

Internally consistent

Internally consistent means:

All required values are present.

All entities Manifest are referenced in the state of some version (i.e. there are no unused entities present in the manifest).

All State entries have a corresponding Manifest entry (i.e. State cannot reference content that is not in the manifest).

A single physical file path has at most one digest for each allowable OCFL digest type. (i.e. the path doesn't have conflicting digests in the manifest or fixity sections)

A single logical file path within a version has exactly one digest (i.e. a path doesn't appear twice within the state of a given version, with different digests).

Head points to a version defined in the inventory, and that version is the highest.

Digest values match the length and composition implied by their algorithm.

Version numbers increase monotonically, and have the same zero padding convention

type Manifest

type Manifest map[Digest][]string

Manifest is a mapping of digests to physical file paths, as defined by inventory.json in the OCFL spec

type User

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

User is an OCFL user, as defined by inventory.json

type Version

type Version struct {
	Created time.Time `json:"created"`
	Message string    `json:"message"`
	User    User      `json:"user"`
	State   Manifest  `json:"state"`
	Type    string    `json:"type"`
}

Version contains ocfl version metadata, as defined by inventory.json in the OCFL spec

type VersionID

type VersionID string

VersionID contains a version ID representation as consistent with the OCFL spec. It starts with v, may be zero padded, etc.

func (VersionID) Increment

func (v VersionID) Increment() (VersionID, error)

Increment increments an OCFL version, respecting padding if a given version ID is padded

func (VersionID) Int

func (v VersionID) Int() (int, error)

Int returns the integer value of an OCFL version

func (VersionID) Valid

func (v VersionID) Valid() bool

Valid determines whether the given version ID complies with the OCFL rules for naming version IDs.

Jump to

Keyboard shortcuts

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