Constructor
new BaseWriter(name, writeFn)
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
The name of the subclass that derives from this class. That is, the name of your own implementation. This name is used for logging and debugging. |
writeFn |
function |
The function that writes each file into the archive, directory, or serialized format you are creating. This function should take two params, (data, done), where data is any JavaScript object and done is a callback to be called when the file has finished being written. See TarWriter or FileSystemWriter for examples of the writeFn and how subclasses can be implement. |
Members
_queue :async.queue
Asynchronous queue for writing files one at a time onto the file system. The final step of any subclass's add() function will be to push data into this queue. See the add() implementations in TarWriter and FileSystemWriter for examples.
directories
This is a map of directory stats. Key is relDestPath, value is fs.Stats object. For example, key will be "/data/subdir". Value will be the stats of the original directory being bagged. This allows us to preserve directory attributes such as uid, gid, mode, and mtime when creating tar files.
filesAdded :number
The total number of files added to the write queue.
filesWritten :number
The total number of files that have been written into the tar file.
name :string
The name of the module. This is required for logging and debugging purposes.
Methods
(static) description() → {PluginDefinition}
Returns a PluginDefinition object describing this plugin.
add(bagItFile, cryptoHashes)
Writes a file into the directory, tar archive, or whatever format the underlying writer supports. This method is asynchronous, emitting events 'fileAdded' when it's done writing a file.
Files will be written in the order they were added. You'll get errors if bagItFile.absSourcePath does not exist or is not readable.
Parameters:
Name | Type | Description |
---|---|---|
bagItFile |
BagItFile |
The BagItFile object describing the file to be added into the output directory. |
cryptoHashes |
Array.<crypto.Hash> |
An array of Node.js crypto.Hash objects used to calculate checksums of the files being written onto the file system. All digests are calculated during the write, so adding multiple hashes will not lead to multiple end-to-end reads of the input stream. You can omit this parameter if you don't care to calculate checksums. If present, the digests will be written into the bagItFile.checksums object. For example, if cryptoHashes includes md5 and sha256 Hash objects, bagItFile.checksums will come out looking like this: |
Example
bagItFile.checksums = {
'md5': '1234567890',
'sha256': '0987654321'
}
The add() method of your derived class should call this before it
continues with your own custom processing. See the add() implementations
in TarWriter and FileSystemWriter for examples.
init()
Subclasses should implement their own init methods if they require some initialization. Otherwise, they can omit this. In the BaseWriter, init() is a noop.
onFileWritten()
Call this after a file is written, to keep an accurate count of how many files have been written. See TarWriter or FileSystemWriter for examples.
percentComplete() → {number}
Returns the percent complete of the total write operations. This will be a number between 0 and 100. E.g. 42.833.