Bagger creates a bag based on a BagItProfile.


new Bagger(job)

Name Type Description
job Job

A job object that includes a PackageOperation describing a number of files to be packaged and a BagItProfile describing how to package them.

Since bagging is basically a streaming operation, streaming data into a specified format, this class implements a subset of the Node.js stream events. The 'error' and 'finish' events are the primary ones to listen to.

// Assuming you have already created a Job object
var bagger = new Bagger(job);
bagger.on('error', function(err) {
   // Check the contents of job.packageOperation.result.errors
   // for details of what went wrong.
bagger.on('fileAdded', function(bagItFile, percentComplete) {
   // Do something with the BagItFile, such as displaying
   // a message saying it's been written into the bag.
   // Don't alter the bagItFile object since it's still
   // in use by the bagger. percentComplete is a number
   // between 0 and 100 indicating what percentage of the
   // total write job is complete.
bagger.on('finish', function() {
    // Do whatever you want when the bag is complete.
    // If needed, you can inspect the contents of the bagger.bagItFiles
    // array. Manifests and tag files in the bagItFiles array
    // will include the file contents. Payload files will not.


bagItFiles :BagItFile

This is a list of BagItFile objects that were packed into the bag. This includes payload files, manifests, tag files and tag manifests.


formatWriter :object

The formatWriter is a plugin used to write the bag onto disk. For example, a bag being written into a directory on the file system will use the FileSystemWriter plugin. A bag being written to a tar file will use the TarWriter plugin, etc.

The bagger chooses the formatWriter at runtime, based on heuristics such as the file extension of the output file.


job :Job

The Job object contains information about what the bagger is supposed to bag, and according to what profile.


tmpFiles :Array.<string>

This is a list of absolute paths to temporary tag files and manifests. These go into the system temp directory during bagging, and the bagger deletes them when it's done.



(async) _addPayloadFiles()

This adds payload files to the bag.


(async) create()

This creates the bag based in the BagItProfile and other info specified in the Job object. See the documentation for the Bagger class for an example of how to use this method.


validatePackagingOperation() → {boolean}

This ensures the packaging operation is valid before the bagger tries to run it.



error :string

Emits a string describing an error encountered during the bagging process. Processing may continue after some types of errors.


fileAdded :BagItFile

Emits a BagItFile object describing a file that was just written into the bag.



Emits an empty event indicating the bagger has completed its work. Check bagger.job.packageOp.result for errors.