go_bagit

package module
v0.3.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 18 Imported by: 0

README

go-bagit

Early Go implementation of the bagit specification

Unsupported features

  • Windows support
  • creation of bags with multiple algorithm manifests
  • fetch.txt / holey bags
  • tag files other than bagit.txt and bag-info.txt

Building From Source

go build -o go-bagit main/main.go

Supported Algorithms

  • md5
  • sha1
  • sha256
  • sha512

Usage:

go-bagit [command] [flags]

Available Commands:

help        Help about any command
validate    validate a bag
create      create a bag
modify      modify a bag

Validate Command

Usage

go-bagit validate [flags]

Flags
--bag string        location of the bag to be validated, Mandatory
-h, --help          help for validate
--fast              test whether the bag directory has the expected payload specified in the checksum manifests without performing checksum validation to detect corruption
--completeness-only only test whether the bag directory has the number of files and total size specified in Payload-Oxum without performing checksum validation to detect corruption

Create Command

Usage

go-bagit create [flags]

Flags
--algorithm string   the algorithm used for checksums (default "md5")
-h, --help           help for create
--input-dir string   the directory to be bagged
--processes int      Use multiple processes to calculate checksums faster (default 1)

Modify Command

Usage

go-bagit modify [flags]

Flags
--add-to-bag    add a file to tag manifest
--bag string    bag to be validated
--file string   location of a file
-h, --help      help for modify

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StandardTags = GetStandardTags()

Functions

func CreateManifest

func CreateManifest(manifestName string, bagLoc string, algorithm string, numProcesses int) error

func CreateTagManifest

func CreateTagManifest(inputDir string, algorithm string, numProcesses int) error

func FindDirInBag

func FindDirInBag(bagLocation string, matcher *regexp.Regexp) (string, error)

func FindDirsInBag

func FindDirsInBag(bagLocation string, matcher *regexp.Regexp) ([]string, error)

func FindFileInBag

func FindFileInBag(bagLocation string, matcher *regexp.Regexp) (string, error)

func FindFilesInBag

func FindFilesInBag(bagLocation string, matcher *regexp.Regexp) ([]string, error)

func GenerateChecksum

func GenerateChecksum(f *os.File, algorithm string) (string, error)

func GetDirsInBag

func GetDirsInBag(bagLocation string) ([]string, error)

func GetFilesInBag

func GetFilesInBag(bagLocation string) ([]string, error)

func GetOxum

func GetOxum(bagLocation string) (string, error)

func GetSoftwareAgent

func GetSoftwareAgent() string

func Logger

func Logger() *stdlog.Logger

Logger returns the current logger.

func ReadManifestMap

func ReadManifestMap(path string) (map[string]string, error)

func ValidateChecksum

func ValidateChecksum(f *os.File, algorithm string, checksum string) error

func ValidateManifest

func ValidateManifest(manifestLocation string, complete bool) (map[string]string, []error)

func ValidateOxum

func ValidateOxum(bagLocation string, oxum string) error

func WithLogger

func WithLogger(logger *stdlog.Logger)

WithLogger replaces the logger.

Types

type Bag

type Bag struct {
	Path         string
	Name         string
	AbsPath      string
	Payload      Payload
	BagInfo      TagSet
	BagIt        TagSet
	Manifests    ManifestRefs
	TagManifests ManifestRefs
}

func CreateBag

func CreateBag(inputDir string, algorithm string, numProcesses int) (Bag, error)

func GetExistingBag

func GetExistingBag(path string) (Bag, error)

func (Bag) AddFileToBagRoot

func (b Bag) AddFileToBagRoot(file string) error

Adds a file to the bag root and registers it in the tagmanifest file

func (Bag) GetAbsolutePath

func (b Bag) GetAbsolutePath() (string, error)

func (Bag) ListPayloadFiles

func (b Bag) ListPayloadFiles()

func (Bag) String

func (b Bag) String() string

func (Bag) ValidateBag

func (b Bag) ValidateBag(fast bool, complete bool) error

type BagInfo

type BagInfo TagSet

type Bagit

type Bagit TagSet

type Manifest

type Manifest struct {
	Bag       string
	Filename  string
	EntryMap  map[string]string
	Algorithm string
}

func NewManifest

func NewManifest(bag string, filename string) (Manifest, error)

func (Manifest) Serialize

func (manifest Manifest) Serialize() error

func (Manifest) UpdateManifest

func (manifest Manifest) UpdateManifest(filename string) error

type ManifestRefs

type ManifestRefs map[string]os.FileInfo

func GetManifests

func GetManifests(bagLocation string) (ManifestRefs, error)

func GetTagManifests

func GetTagManifests(bagLocation string) (ManifestRefs, error)

type Oxum

type Oxum struct {
	Size  int64
	Count int
}

func CalculateOxum

func CalculateOxum(bagLocation string) (Oxum, error)

func ParseOxumString

func ParseOxumString(oxum string) (Oxum, error)

func (Oxum) String

func (o Oxum) String() string

type Payload

type Payload map[string]os.FileInfo

func (Payload) FindAllInPayload

func (p Payload) FindAllInPayload(matcher *regexp.Regexp) []PayloadMatch

func (Payload) FindDirsInPayload

func (p Payload) FindDirsInPayload(matcher *regexp.Regexp) []PayloadMatch

func (Payload) FindFilesInPayload

func (p Payload) FindFilesInPayload(matcher *regexp.Regexp) []PayloadMatch

func (Payload) GetDirInPayload

func (p Payload) GetDirInPayload(dirName string) (PayloadMatch, error)

func (Payload) GetFileInPayload

func (p Payload) GetFileInPayload(filename string) (PayloadMatch, error)

type PayloadMatch

type PayloadMatch struct {
	Path     string
	FileInfo os.FileInfo
}

type StandardTagSet

type StandardTagSet struct {
	BagSoftwareAgent          string
	SourceOrganization        string
	OrganizationAddress       string
	ContactName               string
	ContactPhone              string
	ContactEmail              string
	ExternalDescription       string
	ExternalIdentifier        string
	BagSize                   string
	BaggingDate               string
	PayloadOxum               string
	BagCount                  string
	BagGroupIdentifier        string
	InternalSenderIdentifier  string
	InternalSenderDescription string
	BagItVersion              string
	TagFileCharacterEncoding  string
}

func GetStandardTags

func GetStandardTags() StandardTagSet

type TagSet

type TagSet struct {
	Filename string
	Path     string
	Tags     map[string]string
}

func CreateBagInfo

func CreateBagInfo() TagSet

func CreateBagit

func CreateBagit() TagSet

func NewTagSet

func NewTagSet(filename string, bagLocation string) (TagSet, error)

func (TagSet) AddTags

func (tagset TagSet) AddTags(newTags map[string]string)

func (TagSet) GetTagSetAsByteSlice

func (tagSet TagSet) GetTagSetAsByteSlice() []byte

func (TagSet) HasTag

func (tagSet TagSet) HasTag(key string) bool

func (TagSet) UpdateTagFile

func (tagSet TagSet) UpdateTagFile(key string, value string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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