1.0.16 • Published 3 years ago

file-steward v1.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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)

Create a directory synchronously (if the directory already exists, nothing will be done).

createDir(path, options)

Create a directory asynchronously (if the directory already exists, nothing will be done).

createFileSync(path, data, options)

Create a file synchronously.

createFile(path, data, options)

Create a file asynchronously (supports receiving a fs.ReadStream as the data).

copySync(srcPath, destPath)

Copy a file/directory from it's source path to the destination path synchronously.

copy(srcPath, destPath, options)

Copy a file/directory from it's source path to the destination path asynchronously (supports stream mode).

removeSync(path, options)

Remove the file/directory synchronously.

remove(path, options)

Remove the file/directory asynchronously.

cutSync(srcPath, destPath)

Cut a file/directory from it's source path to the destination path synchronously.

cut(srcPath, destPath, options)

Cut a file/directory from it's source path to the destination path asynchronously (supports stream mode).

renameSync(oldPath, newPath)

Rename a file/directory synchronously.

rename(oldPath, newPath)

Rename a file/directory asynchronously.

bulkSync(list)

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)

Bulk operations in order asynchronously.

check(path, options)

Get the information of the file/directory asynchronously.

isIncludeSync(path)

Whether the path is in the steward's jurisdiction.

isExistSync(path)

Whether the file/directory pointed by the path exists in the jurisdiction.

Static Constants

FileSteward.TYPE

  • BLOCK_DEVICE0
  • CHARACTER_DEVICE1
  • DIRECTORY2
  • FIFO3
  • FILE4
  • SOCKET5
  • SYMBOLIC_LINK6

FileSteward.OP

  • CREATE0
  • COPY1
  • REMOVE2
  • CUT3
  • RENAME4

License

File Steward is MIT licensed.

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago