TarWriter

TarWriter

TarWriter writes files directly into a tarball. By obviating the need to copy files into a directory and then tar up the directory, this can save considerable time and disk space when tarring large bags into a tarred BagIt package.

Constructor

new TarWriter(pathToTarFile)

Creates a new TarWriter.

Parameters:
Name Type Description
pathToTarFile string

The path to the tar file you want to create. You must have write permissions on this path, and the parent directories should already exist. If a file already exists at the speficied path, it will be overwritten.

Source:

Members

bagName :string

bagName is the name of the bag, which is the tar file name minus the leading path and trailing ".tar" extension.

Source:

pathToTarFile :string

pathToTarFile is the path to the file we will write. The file's parent directories should exist before writing, and you must have write permissions on the file. If the file already exists, it will be overwritten.

Source:

Methods

(static) description() → {PluginDefinition}

Returns a PluginDefinition object describing this plugin.

Source:

add(bagItFile, cryptoHashes)

Writes a file into the tar archive. This method is asynchronous, emitting events 'fileAdded' when it's done writing a file.

Files will be written into the archive in the order they are added. Because tar file contents must be written one at a type, this class internally manages one-at-a-time write serialization.

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 tar file.

cryptoHashes Array.<crypto.Hash>

An array of Node.js crypto.Hash objects used to calculate checksums of the files being written into the tarball. 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:

Source:
Example
bagItFile.checksums = {
    'md5': '1234567890',
    'sha256': '0987654321'
}