file-steward v1.0.16
File Steward
Easier file management interface for nodejs.
Quick Start
npm i file-steward -S
Usage
const FileSteward = require("file-steward");
/* The constructor must be given an absolute path as the root directory to manage. */
const steward = new FileSteward(require("path").resolve(__dirname, "resource"));
Each created steward will strictly manage file operations in the root directory and only in the root directory.
Methods
createDirSync(path, options)
- path \<string>
- options \<object>
- recursive \<boolean> default: true
- return \<undefined>
Create a directory synchronously (if the directory already exists, nothing will be done).
createDir(path, options)
- path \<string>
- options \<object>
- recursive \<boolean> default: true
- return \<promise> Promise { undefined }
Create a directory asynchronously (if the directory already exists, nothing will be done).
createFileSync(path, data, options)
- path \<string>
- data \<string> | \<buffer>
- options \<object>
- cover \<boolean> default: true
- return \<undefined>
Create a file synchronously.
createFile(path, data, options)
- path \<string>
- data \<string> | \<buffer> | \<fs.ReadStream>
- options \<object>
- cover \<boolean> default: true
- return \<promise> Promise { undefined }
Create a file asynchronously (supports receiving a fs.ReadStream as the data).
copySync(srcPath, destPath)
- srcPath \<string>
- destPath \<string>
- return \<undefined>
Copy a file/directory from it's source path to the destination path synchronously.
copy(srcPath, destPath, options)
- srcPath \<string>
- destPath \<string>
- options \<object>
- stream \<boolean> default: true
- return \<promise> Promise { undefined }
Copy a file/directory from it's source path to the destination path asynchronously (supports stream mode).
removeSync(path, options)
- path \<string>
- options \<object>
- force \<boolean> default: true
- return \<undefined>
Remove the file/directory synchronously.
remove(path, options)
- path \<string>
- options \<object>
- force \<boolean> default: true
- return \<promise> Promise { undefined }
Remove the file/directory asynchronously.
cutSync(srcPath, destPath)
- srcPath \<string>
- destPath \<string>
- return \<undefined>
Cut a file/directory from it's source path to the destination path synchronously.
cut(srcPath, destPath, options)
- srcPath \<string>
- destPath \<string>
- options \<object>
- stream \<boolean> default: true
- return \<promise> Promise { undefined }
Cut a file/directory from it's source path to the destination path asynchronously (supports stream mode).
renameSync(oldPath, newPath)
- oldPath \<string>
- newPath \<string>
- return \<undefined>
Rename a file/directory synchronously.
rename(oldPath, newPath)
- oldPath \<string>
- newPath \<string>
- return \<promise> Promise { undefined }
Rename a file/directory asynchronously.
bulkSync(list)
- list \<object[]>
- op \<integer> (refer from FileSteward.OP)
- , type \<integer> (refer from FileSteward.TYPE)
- , path \<string>
- , data \<string> | \<buffer>
- , srcPath \<string>
- , destPath \<string>
- , oldPath \<string>
- , newPath \<string>
- , options \<object> specific attributes are determined by "op"
- return \<undefined>
Bulk operations in order synchronously.
example:
steward.bulkSync([
{ op: FileSteward.OP.CREATE, type: FileSteward.TYPE.DIRECTORY, path: "texts" },
{ op: FileSteward.OP.CREATE, type: FileSteward.TYPE.FILE, path: "texts/hello.txt", data: "Hello world!" },
{ op: FileSteward.OP.COPY, srcPath: "texts/hello.txt", destPath: "texts/hello_copy.txt" },
{ op: FileSteward.OP.RENAME, oldPath: "texts/hello_copy.txt", newPath: "texts/hello_backup.txt" },
]);
bulk(list)
- list \<object[]>
- op \<integer> (refer from FileSteward.OP)
- , type \<integer> (refer from FileSteward.TYPE)
- , path \<string>
- , data \<string> | \<buffer>
- , srcPath \<string>
- , destPath \<string>
- , oldPath \<string>
- , newPath \<string>
- , options \<object> specific attributes are determined by "op"
- return \<promise> Promise { undefined }
Bulk operations in order asynchronously.
check(path, options)
- path \<string>
- options \<object>
- relative \<boolean> default: true
- children \<boolean> default: false
- recursive \<boolean> default: false
- return \<promise> Promise { object }
- path \<string>
- type \<integer> (refer from FileSteward.TYPE)
- stat \<fs.Stats>
Get the information of the file/directory asynchronously.
isIncludeSync(path)
- path \<string>
- return \<boolean>
Whether the path is in the steward's jurisdiction.
isExistSync(path)
- path \<string>
- return \<boolean>
Whether the file/directory pointed by the path exists in the jurisdiction.
Static Constants
FileSteward.TYPE
- BLOCK_DEVICE 0
- CHARACTER_DEVICE 1
- DIRECTORY 2
- FIFO 3
- FILE 4
- SOCKET 5
- SYMBOLIC_LINK 6
FileSteward.OP
- CREATE 0
- COPY 1
- REMOVE 2
- CUT 3
- RENAME 4
License
File Steward is MIT licensed.