1.0.0 • Published 4 years ago

rauricoste-file v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Sumary

This project aims to simplify access to files in nodejs. It uses Promises whenever possible. It has been buit upon fs.

It is supposed to work on Windows (you can use / and they will be replaced by \\ if you are a Windows user).

Install

Through npm :

npm install --save rauricoste-file

Usage

Builders

  • new File(path) : create a File object corresponding to the the path. path can be relative or asbolute.

Exemple : new File("src/File.js")

  • parent() : returns a File object representing the parent file of the current file or null if there is no parent file.

  • child(path) : returns a File that has a relative path to the current File.

  • getRelativeFile(parentFile: File) : returns a File that is a relative file regarding parentFile.

Manipulation

  • moveTo(otherFile: File) : move current file to another File. Returns a Promise.

  • copy(destination file: File) : copy the file to the destination path. Returns a Promise.

  • delete() : deletes the file. returns a Promise.

  • deleteChildren() : deletes all this file's direct children. Returns a Promise.

  • mkdir() : creates current file as a directory. Returns a Promise.

  • mkdirs() : creates all this file's parents as directories and this file as a directory. Returns a Promise.

Read / Write

  • read(encoding = "utf-8") : returns a Promise containing the content of the file as a String read with provided encoding. Default encoding is utf-8.

  • write(string or buffer) : replace the file content with the data. Default encoding is utf-8. Returns a Promise.

  • append(string or buffer) : add data at the end of this file. Returns a Promise.

  • writeAtPosition(index: integer, string or buffer) : writes data at position index in the file. Previous data at this position will be erased. Returns a Promise.

  • readAtPosition(start: integer, size: integer) : returns a Promise containing data starting at position start, of size size.

Navigation

  • list() : returns a Promise containing the list of the children files (directory and simple files)

  • listMatch(RegExp) : returns a Promise containing the list of the children files whose name matches the RegExp

  • crawl(testFunction: File => boolean (optionnal)) : returns a Promise that contains all descendant files (children, grand-children, ...) of the current file. Returning files and traversed directories must match testFunction which is a function that receives a File and must return a boolean. If testFunction is not provided, all files are returned.

Informations

  • exists() : returns a Promise containing a boolean that is true if the file exists.

  • name() : returns a String that is the name of the file. The file does not have to exist.

  • isFile() : returns true the .name() of the file contains a .

1.0.0

4 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

7 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago