Constructor
new Bagger(job)
Parameters:
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. |
- Source:
Example
// 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.
});
bagger.create();
Members
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.
- Source:
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.
- Source:
job :Job
The Job object contains information about what the bagger is supposed to bag, and according to what profile.
- Source:
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.
- Source:
Methods
(async) _addPayloadFiles()
This adds payload files to the bag.
- Source:
(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.
- Source:
validatePackagingOperation() → {boolean}
This ensures the packaging operation is valid before the bagger tries to run it.
- Source:
Events
error :string
Emits a string describing an error encountered during the bagging process. Processing may continue after some types of errors.
- Source:
fileAdded :BagItFile
Emits a BagItFile object describing a file that was just written into the bag.
- Source:
finish
Emits an empty event indicating the bagger has completed its work. Check bagger.job.packageOp.result for errors.
- Source: