Documentation ¶
Overview ¶
Package bagit implements the enough of the BagIt specification to save and read the BagIt files used by Bendo. It creates zip files which do not use compression. It only supports MD5 and SHA256 checksums for the manifest file.
Specific items not implemented from the BagIt specification are fetch files and holely bags. It also doesn't preserve the order of the tags nor multiple occurrences of tags in the bag-info.txt file.
This package allows for reading a bag, verifying a bag, and creating new bags. It does not provide any services for updating a bag. Checksums are generated for each file when a bag is created. After that, checksums are only calculated when a bag is explicitly verified. In particular, checksums are not calculated when reading content from a bag.
The interface is designed to somewhat mirror the archive/zip interface.
The BagIt spec can be found at https://tools.ietf.org/html/draft-kunze-bagit-11.
Index ¶
Constants ¶
const (
// Version is the version of the BagIt specification this package implements.
Version = "0.97"
)
Variables ¶
var ( ErrExtraFile = errors.New("bagit: extra file") ErrMissingFile = errors.New("bagit: missing file") ErrChecksum = errors.New("bagit: checksum mismatch") )
Possible verification errors.
var ( // ErrNotFound means a stream inside a zip file with the given name // could not be found. ErrNotFound = errors.New("stream not found") )
Functions ¶
This section is empty.
Types ¶
type Bag ¶
type Bag struct {
// contains filtered or unexported fields
}
Bag represents a single BagIt file.
type BagError ¶
BagError is used to hold a validation error and the file in the bag which has the error.
type Checksum ¶
Checksum contains all the checksums we know about for a given file. Some entries may be empty. At least one entry should be present.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader allows for reading an existing Bag file (in ZIP format).
A Reader does not validate checksums or load tags until asked to do so. Use Verify() to hash and verify all the manifests. Call Tags() to load the tag files "bagit.txt" and "bag-info.txt". Other tag files are ignored. Since tags are stored in a map, the order of the tags is not preserved.
func NewReader ¶
NewReader creates a bag reader which wraps r. It expects a ZIP datastream, and uses size to locate the zip manifest block, which is at the end.
Closing a reader does not close the wrapped ReaderAt.
func (*Reader) Checksum ¶
Checksum returns a pointer to the Checksum struct of the given filername culled from the manifests map. It assumes that the request file resides in the data directory of the bag, and so prepends "data/" to the filename provided. If no entry exists for the given file, it returns nil
func (*Reader) Files ¶
Files returns a list of the payload files inside this bag (as opposed to the tag and manifest files). The initial "data/" prefix is removed from the file names.
The result is recalculated each time the function is called. For large bags generating the result could take a while.
func (*Reader) Open ¶
func (r *Reader) Open(name string) (io.ReadCloser, error)
Open returns a reader for the file having the given name. Note, that inside the bag, the file is searched for from the path "<bag name>/data/<name>".
func (*Reader) Tags ¶
Tags returns a map giving all of the tags stored in this bag. The keys are the tag names, and the values are the value of the tag. Since tags are returned as a map, the order of the tags in the tag files is not preserved. Also, if a tag should occur more than one time, only the last occurrence is returned.
The tag files "bagit.txt" and "bag-info.txt" are read. Other tag files are ignored.
func (*Reader) Verify ¶
Verify computes the checksum of each file in this bag, and checks it against the manifest files. Both payload ("data/") and tag files are checked. The file list is read from manifest files for MD5, SHA1, SHA256, and SHA512 hashes, although only MD5 and SHA256 hashes are actually computed and verified. Files missing an entry in a manifest file, or manifest entires missing a corresponding file will cause a verification error. Tag files which are missing a manifest entry are the only exception to the verification error.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer allows for writing a new bag file. When it is closed, all the relevant tag files and manifests will be written out.
func NewWriter ¶
NewWriter creates a new bag writer which will serialize itself to the provided io.Writer. Use name to set the directory name the bag will unserialize into, as required by the spec.
func (*Writer) Checksum ¶
Checksum returns the checksums for what has been written so far to the last io.Writer returned by Create().
func (*Writer) Close ¶
Close this Writer and serialize all necessary bookkeeping files. It does not close the original io.Writer provided to NewWriter().