A simple promise-based wrapper for file operations that treats files as objects.
File = require 'fobject'
configFile = new File('config.json')
configFile.read().done((data) ->
console.log "contents of #{configFile.path}: #{data}"
)
The default fs module has a really ugly interface (including sync and async copies of almost every function) and doesn't make it easy to work with files that may or may not actually be written to the file-system. fobject abstracts out interaction with the file system so if you want to implement caching, or work with files without writing them to the disk, or whatever else you want: you can do so easily.
Name | Type | Argument | Default | Description |
---|---|---|---|---|
path |
String | The path to the file. This will be resolved to an absolute path, so even if you change your cwd you can still access the same file. |
||
options.base |
String |
<optional> |
./ | Used for relative pathing. This will not be resolved to an absolute path. Typically where a glob starts. |
-
Append
data
to the fileName Type Argument Default Description data
String | Buffer options.encoding
String | null <optional>
'utf8' ignored if data is a buffer
options.mode
Number <optional>
438 default is 0666 in Octal
options.flag
String <optional>
'w' - Type
- Promise
-
Get the dirname of the file
- Source:
- Type
- String
-
Get the extension of a file
- Source:
- Type
- String
-
Read from the file
Name Type Argument Default Description options.encoding
String | null <optional>
null options.flag
String <optional>
'r' - Type
- Promise
-
Rename the file
Name Type Description newPath
String The new path for the file. Will be resolved relative to File.base.
- Source:
- Type
- Promise
-
Return a Stat object for the file
- Source:
- Type
- Promise
-
Delete the file
- Source:
- Type
- Promise
-
Write
data
to the fileName Type Argument Default Description data
String | Buffer options.encoding
String | null <optional>
'utf8' ignored if data is a buffer
options.mode
Number <optional>
438 default is 0666 in Octal
options.flag
String <optional>
'w' - Type
- Promise
generated with docme