- Source
Methods
(inner) ListDir(path, itemType) → {Array.<string>}
ListDir lists all files and directories within a path depending on the itemType provided. itemType can be any one of ['file','dir','all']
Parameters:
Name | Type | Description |
---|---|---|
path | string | The path to list files and directories from. |
itemType | string | The type of items to list. Can be 'file', 'dir', or 'all'. |
- Source
Throws:
- - The error encountered during listing.
- Type
- error
Returns:
- The list of files and directories.
- Type:
- Array.<string>
Example
let m = require('nuclei/fs');
let items = m.ListDir('/tmp', 'all');
(inner) ReadFile(path) → {Uint8Array}
ReadFile reads file contents within permitted paths
Parameters:
Name | Type | Description |
---|---|---|
path | string | The path to the file to read. |
- Source
Throws:
- - The error encountered during reading.
- Type
- error
Returns:
- The contents of the file.
- Type:
- Uint8Array
Example
let m = require('nuclei/fs');
let content = m.ReadFile('/tmp/myfile.txt');
(inner) ReadFileAsString(path) → {string}
ReadFileAsString reads file contents within permitted paths and returns content as string
Parameters:
Name | Type | Description |
---|---|---|
path | string | The path to the file to read. |
- Source
Throws:
- - The error encountered during reading.
- Type
- error
Returns:
- The contents of the file as a string.
- Type:
- string
Example
let m = require('nuclei/fs');
let content = m.ReadFileAsString('/tmp/myfile.txt');
(inner) ReadFilesFromDir(dir) → {Array.<string>}
ReadFilesFromDir reads all files from a directory and returns a array with file contents of all files
Parameters:
Name | Type | Description |
---|---|---|
dir | string | The directory to read files from. |
- Source
Throws:
- - The error encountered during reading.
- Type
- error
Returns:
- The contents of all files in the directory.
- Type:
- Array.<string>
Example
let m = require('nuclei/fs');
let contentArray = m.ReadFilesFromDir('/tmp');