I was trying to implement mkDir() today, and I figured out that most of the File API is somehow very hard to understand, especially the static methods that can be used like File.readSync(path).
After discussing some things with @paraboul I'd suggest that we need to move some methods from File to the FS object, so that static methods are in one place and not confusing anymore:
Changes to File
Changes to fs
So here's some code how it would look like:
const _fs = global.fs;
const _File = global.File;
if (_fs.isDir('/tmp/whatever') === false) {
_fs.createDir('/tmp/whatever', err => !err && console.log('created directory'));
// alternative api
let result = _fs.createDirSync('/tmp/whatever');
}
if (_fs.isFile('/tmp/whatever/foo.txt') === true) {
_fs.remove('/tmp/whatever/foo.txt', err => !err && console.log('removed file'));
// alternative api
let result = _fs.removeSync('/tmp/whatever/foo.txt');
}
PS: I would love to implement this as my first pull request, as it seems that static methods are easier to implement and the relevant method signatures are already in the codebase.
I was trying to implement
mkDir()today, and I figured out that most of the File API is somehow very hard to understand, especially the static methods that can be used likeFile.readSync(path).After discussing some things with @paraboul I'd suggest that we need to move some methods from File to the FS object, so that static methods are in one place and not confusing anymore:
Changes to File
File.prototype.rm()File.prototype.rmrf()File.prototype.isDir()File.prototype.listFiles()becausefs.readDir()already has identical featuresetChanges to fs
fs.remove(path, (err) => {})(Boolean) fs.removeSync(path)fs.createDir(path, (err) => {})(Boolean) fs.createDirSync(path, options)(Array) fs.readDirSync(path)(Boolean) fs.isDir(path)(Boolean) fs.isFile(path)So here's some code how it would look like:
PS: I would love to implement this as my first pull request, as it seems that static methods are easier to implement and the relevant method signatures are already in the codebase.