@sugarcoated/royal-disk

1.0.0 • Public • Published

Node FS has a bunch of wrappers all over the internet. Here's mine.

API Reference

.name(path)

Derives the name of a file from a path.

  • path is expected as a String representing the path to a file.

    Disk.name('./myFile.txt'); // myFile
    

.ext(path)

Derives the extension from a file using Path#extname. Returns the extension as a String.

  • path is expected as a String representing the path to the file.

    Disk.ext('/myFile.txt'); // .txt
    

.file(path, extension)

Derive the file name in a path.

  • path is expected as a String, representing the path to the file.

  • extension is expected as a String, representing the extension of the file.

    Disk.file('/myFile', '.txt'); // myFile.txt
    

.directory(path)

Derives the directory a file is located in. Returns the directory as a String.

  • path is expected as a String, representing the path to the file.

    Disk.directory('/myFolder/myFile.txt'); // myFolder
    

.readFile(path, [encoding])

Reads a file. Returns a Promise that resolves with the file contents as a String.

  • path is expected as a String, representing the path to the file.

  • encoding is an optional parameter, expected as a String, representing the encoding of the file to read. If one is not specified, this defaults to utf8.

    Disk.readFile('/myFile.txt');
    

.readFiles(path, [recursive])

Reads files within a directory, optionally recursively. Returns a Promise that resolves with a Collection containing the contents of the files as Strings, or further Collections containing further file contents as Strings. The returned Collection will only contain further Collections should the recursive parameter be passed as true, as each contained Collection represents a directory that was read, and will be mapped under the directory's name in the base Collection.

  • path is expected as a String, representing the path to the file.

  • recursive is expected as a Boolean, representing whether or not to recursively path through the directory. When recursive is true, each contained directory will be mapped as a Collection of that directory's file's contents.

    Disk.readFiles('/myFolder'); 
    

.appendFile(path, content)

Appends content to a file. Returns Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String, representing the path to the file.

  • content is expected as a String, representing the content to append to the file.

    Disk.appendFile('/myFile.txt'); // .txt
    

.renameFile(path, name)

Renames a file. Returns a Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String, representing the path to the file.

  • name is expected as a String, representing the new name of the file.

    Disk.appendFile('/myFile.txt');
    

.writeFile(path, [contents])

Writes/creates a file. Returns a Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String, representing the path to the new file.

  • contents is an optional parameter, expected as a String, representing the contents of the new file.

    Disk.writeFile('/myFile.txt'); 
    

.deleteFile(path)

Deletes a file. Returns with a Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String, representing the path to the file to delete.

    Disk.deleteFile('/myFile.txt'); 
    

.tryDirectory(path)

Attempts to access a directory. Returns a Promise that resolves with a Boolean representing whether access was granted.

  • path is expected as a String, representing the path to the directory.

    Disk.tryDirectory('/myFolder/'); 
    

.readDirectory(path)

Read the listing of a directory. Returns a Promise that resolves with an Array.<String>, each String being the name of a file or [further] directory within the directory that was read.

  • path is expected as a String, representing the path to the directory to read.

    Disk.readDirectory('/myFolder/'); 
    

.writeDirectory(path)

Creates a directory. Returns a Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String representing the path to the new directory.

    Disk.writeDirectory('/myFolder/'); 
    

.deleteDirectory(path)

Deletes a directory. Returns a Promise that resolves with a Boolean representing whether or not the operation was a success, and rejects with an UnhandledPromiseRejection containing the Error thrown.

  • path is expected as a String, representing the path to the directory to delete.

    Disk.deleteDirectory('/myFolder/'); 
    

Readme

Keywords

Package Sidebar

Install

npm i @sugarcoated/royal-disk

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • crowes