candyfs v0.0.27
š A fast, error-less, object-oriented, and extended version of node's built-in fs
package.
Installing
Simply use the npm i
command to install CandyFS.
npm i candyfs
Usage
Create a new File
instance by require
ing the module and instantiating a variable.
var File = require('candyfs')
var myFile = new File()
Why object oriented?
Object oriented filesystems can potentially be a lot more efficient than functional filesystems, as you don't need to store the path, and call a bunch of different functions using the path variable you stored. You know what? maybe it would be easier to tell you by an example.
fs
var fs = require('fs');
var path = 'src/test.txt';
fs.writeFileSync(path, 'This is a test!');
fs.renameSync(path, 'src/test1.txt');
var stats = fs.lstatSync(path);
var isDir = stats.isDirectory();
if(isDir) {
console.log('It\'s a directory!')
}
candyfs
var File = require("candyfs");
var file = new File("src/test.txt");
file.contents = 'This is a test!';
file.moveTo('src/test1.txt');
if(file.isDirectory) {
console.log('It\'s a directory!');
}
In reality, it comes down to personal preference, but candyfs is more efficient for projects where you are editing the same file alot.
API Documentation
File
Constructors
File(path: string)
: instantiates a new file with the path path
.
Methods
copyTo(path: string): void
: Copies this file to the specified path.
moveTo(path: string): void
: Moves this file to the specified path.
mkdirs(): void
: Creates any parent directories that don't exist.
delete(): void
: Deletes this file from the filesystem.
watch(callback: function): void
: Watches for changes for this file.
static readDir(path: string): File[]
: Reads a directory of files and returns a list of files that are in the directory.
Returns undefined if the directory doesn't exist.
Properties
contents: string
:
get: Returns the contents of this file, and will return undefined if this file doesn't exist, or this file is actually a directory.
set:
Writes the contents of this file to the file at this file's path.
If this file's parent directories don't exist, it will create them.
[ get, set ]
path: string
: The path this file is at.
[ get ]
exists: boolean
: Whether this file exists.
[ get ]
size: int
: The size of this file in bytes. Returns 0 if the file doesn't exist.
[ get ]
sizeKilobytes: int
: The size of this file in kilobytes. Returns 0 if the file doesn't exist.
[ get ]
sizeMegabytes: int
: The size of this file in megabytes. Returns 0 if the file doesn't exist.
[ get ]
sizeGigabytes: int
: The size of this file in gigabytes. Returns 0 if the file doesn't exist.
[ get ]
isDirectory: boolean
: Returns true if this file is actually a directory, and false if it isn't.
[ get ]
extension: string
: Returns the file extension of this file.
Returns an empty string if the file is actually a directory.
[ get ]
createdDate: Date
: Returns the date this file was created.
[ get ]
createdMS: int
: Returns the millisecond this file was created.
[ get ]
modifiedDate: Date
: Returns the last millisecond this file was modified.
[ get ]
modifiedMS: int
: Returns the last date this file was modified.
[ get ]
Missing any features?
Make sure to open an issue or a pull request on the CandyFS github repo hereš
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago