Easier file management interface for nodejs.
npm i file-steward -S
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.
- path <string>
- options <object>
- recursive <boolean> default: true
- return <undefined>
Create a directory synchronously (if the directory already exists, nothing will be done).
- 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).
- path <string>
- data <string> | <buffer>
- options <object>
- cover <boolean> default: true
- return <undefined>
Create a file synchronously.
- 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).
- srcPath <string>
- destPath <string>
- return <undefined>
Copy a file/directory from it's source path to the destination path synchronously.
- 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).
- path <string>
- options <object>
- force <boolean> default: true
- return <undefined>
Remove the file/directory synchronously.
Remove the file/directory asynchronously.
- srcPath <string>
- destPath <string>
- return <undefined>
Cut a file/directory from it's source path to the destination path synchronously.
- 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).
- oldPath <string>
- newPath <string>
- return <undefined>
Rename a file/directory synchronously.
Rename a file/directory asynchronously.
- list <object[]>
- 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" },
]);
- list <object[]>
- return <promise> Promise { undefined }
Bulk operations in order asynchronously.
- path <string>
- options <object>
- return <promise> Promise { object }
- path <string>
- type <integer> (refer from FileSteward.TYPE)
- stat <fs.Stats>
Get the information of the file/directory asynchronously.
Whether the path is in the steward's jurisdiction.
Whether the file/directory pointed by the path exists in the jurisdiction.
- BLOCK_DEVICE 0
- CHARACTER_DEVICE 1
- DIRECTORY 2
- FIFO 3
- FILE 4
- SOCKET 5
- SYMBOLIC_LINK 6
- CREATE 0
- COPY 1
- REMOVE 2
- CUT 3
- RENAME 4
File Steward is MIT licensed.