1.0.16 • Published 2 years ago

file-steward v1.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
2 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

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago