BagIt FS-like Implementation
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
lib
test
.gitignore
.travis.yml
LICENSE.md
README.md
cli.js
index.js
package-lock.json
package.json

README.md

bagit-fs

node fs implementation for the bagit spec.

npm travis standard

Install

npm install bagit-fs

Usage

var BagIt = require('bagit-fs')

var bag = BagIt('/put/my/bag/here', 'sha256', {'Contact-Name': 'Joe Hand'})

// write files to bag's data folder
fs.createReadStream('readme.md').pipe(bag.createWriteStream('/readme.md'))

// ... LATER after all files are written
bag.finalize(function () {
  console.log('finalized')
})

See example/index.js for an example usage with mirror-folder.

API

var bag = BagIt(dest, algorithm, [bagInfo])

  • dest is the destination directory for the bag
  • algorithm is a string specifying which checksum algorithms to use. Default is sha256.
  • bagInfo is a object with data to be written to bag-info.txt, e.g. bagInfo = {'Contact-Name': 'Joe Hand'}. See below for details on bag-info.txt.

bag.finalize(cb)

Finalize the bag, writing bag-info.txt and bagit.txt. Date and size are automatically written to the info. This should only be called when the bag is complete.

Using Finalized Bags

bag.readFile(name, [opts], cb)

Read a file from a completed bag. File is verified with checksum in manifest unless opts.verify === false.

bag.readManifest(callback(err, entries))

Get all entries in the manifest.

bag.getManifestEntry(name, callback(err, entry))

Get specific entry {checksum: <hash>, name: data/file.txt} in the manifest.

fs API

Several of the node fs functions are implemented allowing you to create or read from bags like the fs. Most of these just wrap the fs calls to act on the bag's data folder.

  • bag.createWriteStream(name, opts, cb) - writes file to bagDir/data and the checksum hash to the manifest.
  • bag.mkdir(name, opts, cb) - make a dir in the data/ folder.
  • bag.createReadStream(name, opts, cb) - file is not verified with manifest (yet).
  • bag.mkdir(name, cb)
  • bag.stat(name, cb)
  • bag.lstat(name, cb)
  • bag.readdir(name, cb)
  • bag.unlink(name, cb)
  • bag.rmdir(name, cb)

BagIt Spec Support

bagit-fs is a fully compliant implementation of the specification but there are some optional parts not yet implemented.

TODO:

Bag Info

bag-info spec

The "bag-info.txt" file is a tag file that contains metadata elements describing the bag and the payload. The metadata elements contained in the "bag-info.txt" file are intended primarily for human readability. All metadata elements are optional and MAY be repeated.

Bagging-Date and Bag-Size are written automatically on bag.finalize().

Here is an example "bag-info.txt" file:

Source-Organization: Spengler University
Organization-Address: 1400 Elm St., Cupertino, California, 95014
Contact-Name: Edna Janssen
Contact-Phone: +1 408-555-1212
Contact-Email: ej@spengler.edu
External-Description: Uncompressed greyscale TIFF images from the
    Yoshimuri papers colle...
Bagging-Date: 2008-01-15
External-Identifier: spengler_yoshimuri_001
Bag-Size: 260 GB
Payload-Oxum: 279164409832.1198
Bag-Group-Identifier: spengler_yoshimuri
Bag-Count: 1 of 15
Internal-Sender-Identifier: /storage/images/yoshimuri
Internal-Sender-Description: Uncompressed greyscale TIFFs created
    from microfilm and are...

License

MIT