Make calls into the file system of the calling machine.
Copies a file from one location to another.
the path of the source file
the path of the destination file. If only a path is provided then the copied file will use the source file name
optionally verify the SME checksum of the destination file matches the SME checksum of the source file, and only return true if it does
true if the copy is successful, false otherwise
if (busby.copyFile("/mnt/squared/testfile.txt", "/tmp/test.txt")) {
busby.log("File copied successfully")
}
Copies a file from one location to a remote file writer.
the path of the source file
the path of the destination file. If only a path is provided then the copied file will use the source file name
if (busby.copyAcrossBus("/mnt/squared/testfile.txt", "/tmp/test.txt", "fileWriter")) {
busby.log("File copied successfully")
}
Creates a tar file at the given location with the given source contents
the source contents path
the path where the tar file should be saved to. The directory for this file is created if it does not already exist.
true if successful, false if error
busby.file.createTar("/mnt/squared/testfile.tar", "/mnt/nas/media/contents/")
Deletes the file at the given file path. Returns true if the deletion is successful, and false otherwise.
the path of the file to be deleted
optionally delete recursively -- executes rm -rf
true if the deletion is successful, false otherwise
if (busby.file.delete("/mnt/squared/testfile.txt")) {
busby.log("File deleted successfully")
}
Checks if a file or directory exists.
the path or directory to check
True if the item exists false if not
busby.file.exists('/tmp/test.txt');
busby.file.exists('/srv/store/hd/');
Extracts a tar file to the given location
the path to the tar file
the path where the tar file should be extracted to. This folder is created if it doesn't already exist.
true if successful, false if error
busby.file.extractTar("/mnt/squared/testfile.tar", "/mnt/nas/media/testfile/")
Extracts a zip file to the given location
the path to the zip file
the path where the zip file should be extracted to. This folder is created if it doesn't already exist.
true if successful, false if error
busby.file.extractTar("/mnt/squared/testfile.tar", "/mnt/nas/media/testfile/")
Lists the contents of the directory at the given path.
the path of the directory to list
whether to recurse directories, either a boolean or how many levels to descend
The recursive directory listing
busby.file.listDirectory('/mnt/centralstore')
Makes a directory at the given path. Any parent directories that do not exist will also be made.
the path of the directory to make
true if the make directory is successful, false otherwise
if (busby.makeDirectory("/mnt/squared/test/directory")) {
busby.log("Directory made successfully")
}
Creates a temporary empty file.
Temporary file path if successful and {undefined} if not successful
const tempFile = busby.file.makeTemporaryFile({tempDirectory: '/home/squared/schedules', prefix: 'ch1', extension: 'xml'})
Runs an MD5 on a file.
the path of the source file
MD5 string or null if error
busby.file.md5("/mnt/squared/testfile.txt")
Moves a file from one location to another. This uses the linux mv command, and so will move file pointers if on the same device.
the path of the source file
the path of the destination file. If only a path is provided then the copied file will use the source file name
true if the move is successful, false otherwise
if (busby.moveFile("/mnt/squared/testfile.txt", "/tmp/test.txt)) {
busby.log("File copied successfully")
}
Reads a file from the given path.
the path of the file to read
An object that may contain an optional flag. If a flag is not provided, it defaults to'r'
.
The file contents either as a string or aBuffer
busby.file.read('/tmp/test.txt', { encoding: 'utf8'})
Reads a file from the given path.
the path of the file to read
Either the encoding for the result, or an object that contains the encoding and an optional flag.
The file contents either as a string or aBuffer
busby.file.read('/tmp/test.txt', { encoding: 'utf8'})
Reads a file from the given path.
the path of the file to read
Either the encoding for the result, or an object that contains the encoding and an optional flag.
The file contents either as a string or aBuffer
busby.file.read('/tmp/test.txt', { encoding: 'utf8'})
Reads a file from the given path.
the path of the file to read
either the encoding for the result e.g. 'utf-8', or an object that contains the encoding and an optional flag
The file contents either as a string if encoding is provided or aBuffer
if not
busby.file.read('/tmp/test.txt', { encoding: 'utf8' })
Read a file from a remote location
the path of the distant file
the path of the local file to write to
if (busby.copyAcrossBus("/mnt/squared/testfile.txt", "/tmp/test.txt", "fileWriter")) {
busby.log("File copied successfully")
}
Saves a file to the given path.
the path of the file to save
the data to be written
either the encoding of the file as a string, e.g. 'utf-8' or an object with the encoding, file mode and flag
busby.file.save('/tmp/test.txt', JSON.stringify(object), 'utf8')
Change the permissions on a file.
the file to change the permissions on
the mode to change the permissions to
busby.file.setPermission('/mnt/centralstore', 777);
Generates the start,middle,end (SME) checksum of a file
the path to the file
string
const smeChecksum = busby.file.smeCalc('/home/squared/test.mp4');