wilton/fs
File I/O and file-system operations.
More...
Functions | |
| Undefined | appendFile (String path, String|Array data, Object|Undefined options, Function|Undefined callback) |
| Append data to a file, creating the file if it does not yet exist. | |
| Undefined | copyDirectory (String oldPath, String newPath, Function|Undefined callback) |
| Copy a directory. | |
| Undefined | copyFile (String oldPath, String newPath, Function|Undefined callback) |
| Copy a file. | |
| Boolean | exists (String path, Function|Undefined callback) |
| Test whether or not the given path exists by checking with the file system. | |
| Undefined | insertFile (String sourcePath, String destPath, Number offset, Function|Undefined callback) |
| Writes the contents from one file to another. | |
| Boolean | isDirectory (String path, Function|Undefined callback) |
| Check whether path is a directory. | |
| Boolean | isFile (String path, Function|Undefined callback) |
| Check whether path is an ordinary file. | |
| Undefined | mkdir (String path, Undefined mode, Function|Undefined callback) |
| Create a directory. | |
| Array | readdir (String path, Undefined options, Function|Undefined callback) |
| List the contents of a directory. | |
| String | readFile (String path, Object|Undefined options, Function|Undefined callback) |
| Read the entire contents of a file. | |
| Array | readLines (String path, Function|Undefined callback) |
| Reads all lines from a file. | |
| String | realpath (String path, Undefined options, Function|Undefined callback) |
| Convert relative path into absolute one. | |
| Undefined | rename (String oldPath, String newPath, Function|Undefined callback) |
| Rename (move) file or directory. | |
| Undefined | resizeFile (String path, Number size, Function|Undefined callback) |
| Resizes file. | |
| Undefined | rmdir (String path, Function|Undefined callback) |
| Delete directory. | |
| Object | stat (String path, Function|Undefined callback) |
| Read file or directory status. | |
| Undefined | symlink (String dest, String link, Function|Undefined callback) |
| Create a symbolic link. | |
| Undefined | unlink (String path, Function|Undefined callback) |
| Delete file. | |
| Undefined | writeFile (String path, String|Array data, Object|Undefined options, Function|Undefined callback) |
| Write specified data to a file, overwriting a file if it exists. | |
This module implements a synchronous-only subset of fs module from Node.js.
It provides wrappers around standard posix functions.
Every function in this module has an alias with a Sync postfix (to match Node.js convention), example: readFile() is the same as readFileSync.
Usage example:
| Undefined fs::appendFile | ( | String | path, |
| String|Array | data, | ||
| Object|Undefined | options, | ||
| Function|Undefined | callback | ||
| ) |
Appends data to a file, creating the file if it does not yet exist.
| path | String path to file |
| data | String|Array data to write, can be a string or an array of strings; options.delimiter string is appended after every array element except the last one |
| options | Object|Undefined configuration object, can be omitted, see possible options below |
| callback | Function|Undefined callback to receive result or error |
UndefinedOptions
Boolean|Undefined whether data is specified in hexadecimal encoding and needs to be converted to binary before appending it to file; false by defaultString|Undefined string that is appended after every array element except the last one, default value: \n | Undefined fs::copyDirectory | ( | String | oldPath, |
| String | newPath, | ||
| Function|Undefined | callback | ||
| ) |
Copies specified directory recursively.
| oldPath | String existing path |
| newPath | String desired path |
| callback | Function|Undefined callback to receive result or error |
Undefined | Undefined fs::copyFile | ( | String | oldPath, |
| String | newPath, | ||
| Function|Undefined | callback | ||
| ) |
Copies specified file.
| oldPath | String existing path |
| newPath | String desired path |
| callback | Function|Undefined callback to receive result or error |
Undefined | Boolean fs::exists | ( | String | path, |
| Function|Undefined | callback | ||
| ) |
Tests whether or not the given path exists by checking with the file system.
| path | String path to file or directory |
| callback | Function|Undefined callback to receive result or error |
Boolean true if specified path exists, false otherwise | Undefined fs::insertFile | ( | String | sourcePath, |
| String | destPath, | ||
| Number | offset, | ||
| Function|Undefined | callback | ||
| ) |
Writes the contents of the specified source file to destination file, starts from offset.
| sourcePath | String path to source file |
| destPath | String path to destination file |
| offset | Number offset from destination file write position |
| callback | Function|Undefined callback to receive result or error |
Undefined | Boolean fs::isDirectory | ( | String | path, |
| Function|Undefined | callback | ||
| ) |
Checks whether specified path is a directory. Uses stat(...).isDirectory.
| path | String |
| callback | Function|Undefined callback to receive result or error |
Boolean true if specified path is a directory, false otherwise | Boolean fs::isFile | ( | String | path, |
| Function|Undefined | callback | ||
| ) |
Checks whether specified path is an ordinary file. Uses stat(...).isFile.
| path | String |
| callback | Function|Undefined callback to receive result or error |
Boolean true if specified path is an ordinary file, false otherwise | Undefined fs::mkdir | ( | String | path, |
| Undefined | mode, | ||
| Function|Undefined | callback | ||
| ) |
Creates a directory.
| path | String path to directory |
| mode | Undefined placeholder parameter, added for compatibility with Node API |
| callback | Function|Undefined callback to receive result or error |
Undefined | Array fs::readdir | ( | String | path, |
| Undefined | options, | ||
| Function|Undefined | callback | ||
| ) |
Lists the contents of a directory.
| path | String path to directory |
| options | Undefined placeholder parameter, added for compatibility with Node API |
| callback | Function|Undefined callback to receive result or error |
Array list of files and directories inside the specified directory | String fs::readFile | ( | String | path, |
| Object|Undefined | options, | ||
| Function|Undefined | callback | ||
| ) |
Reads the entire contents of a file.
| path | String path to file |
| options | Object|Undefined configuration object, can be omitted, see possible options below |
| callback | Function|Undefined callback to receive result or error |
String file contentsOptions
Boolean|Undefined whether data read from file needs to be converted to hexadecimal encoding before returning it to caller; false by default | Array fs::readLines | ( | String | path, |
| Function|Undefined | callback | ||
| ) |
Reads the entire contents of a text file and return them as an array of lines.
Empty strings are ignored.
| path | String path to file |
| callback | Function|Undefined callback to receive result or error |
Array file contents as an array of lines | String fs::realpath | ( | String | path, |
| Undefined | options, | ||
| Function|Undefined | callback | ||
| ) |
Converts relative path into absolute one calling FS.
| path | String relative path |
| options | Undefined placeholder parameter, added for compatibility with Node API |
| callback | Function|Undefined callback to receive result or error |
String absolute path | Undefined fs::rename | ( | String | oldPath, |
| String | newPath, | ||
| Function|Undefined | callback | ||
| ) |
Renames (moves) file or directory.
| oldPath | String existing path |
| newPath | String desired path |
| callback | Function|Undefined callback to receive result or error |
Undefined | Undefined fs::resizeFile | ( | String | path, |
| Number | size, | ||
| Function|Undefined | callback | ||
| ) |
Resizes existing file or creates file with specified size
| path | String path to file |
| size | Number offset from current target file write position |
| callback | Function|Undefined callback to receive result or error |
Undefined | Undefined fs::rmdir | ( | String | path, |
| Function|Undefined | callback | ||
| ) |
Deletes directory recursively.
| path | String path to directory |
| callback | Function|Undefined callback to receive result or error |
Undefined | Object fs::stat | ( | String | path, |
| Function|Undefined | callback | ||
| ) |
Reads file or directory status.
| path | String |
| callback | Function|Undefined callback to receive result or error |
Object with the following fields:Number file size in bytes, 0 for directoryBoolean whether it is a fileBoolean whether it is a directory | Undefined fs::symlink | ( | String | dest, |
| String | link, | ||
| Function|Undefined | callback | ||
| ) |
Creates a symbolic link to file or directory.
| dest | String destination path |
| link | String path to link to create |
| callback | Function|Undefined callback to receive result or error |
Undefined | Undefined fs::unlink | ( | String | path, |
| Function|Undefined | callback | ||
| ) |
Deletes file.
| path | String path to file |
| callback | Function|Undefined callback to receive result or error |
Undefined | Undefined fs::writeFile | ( | String | path, |
| String|Array | data, | ||
| Object|Undefined | options, | ||
| Function|Undefined | callback | ||
| ) |
Writess pecified data to a file, overwriting a file if it exists.
| path | String path to file |
| data | String|Array data to write, can be a string or an array of strings; options.delimiter string is appended after every array element except the last one |
| options | Object|Undefined configuration object, can be omitted, see possible options below |
| callback | Function|Undefined callback to receive result or error |
UndefinedOptions
Boolean|Undefined whether data is specified in hexadecimal encoding and needs to be converted to binary before writing it to file; false by defaultString|Undefined string that is appended after every array element except the last one, default value: \n
1.8.1.2