FileSystem

Introduced in 4.0.0

Stability: 2 Stable

const FileSystem = require('kado/lib/FileSystem')

The FileSystem library provides a clean consistent overlay on top of the core file system functions. This library provides promises as a standard method of resolution.

Motivations

The core file system methods are amazing, however, they are restricted by meeting the demands of legacy software. This library is mostly a wrapper but helps to make a more consistent and existential API.

This is done by promoting the fs.promises API to primary, then merging the sync APIs and utility methods into the primary. The end result is a clean ES6+ fs module with all the core functions. This provides a more intuitive API and cleaner usage.

Class: FileSystem

This class is based on Node.js File System module, see this documentation for instructions using these methods. Otherwise, see the document for the Node.js version you are using such as: v10.x or v12.x, etc

NOTE: All methods are static.

Usage:

const fs = require('kado/lib/FileSystem')
fs.appendFile('some/file.txt', 'some data to append')
  .then(() => { console.log('ok') })
const rv = fs.exists('some/file')
console.log(rv) //false

Usage can be referenced on the corresponding Node.js documentation, linked below.

Available properties

FileSystem.Stats

This is a convenience reference to the core Stats class and is sometimes used for type checking as instanceof fs.Stats

FileSystem.Dirent

This is a convenience reference to the core Dirent class and is sometimes used for type checking as instanceof fs.Dirent

FileSystem.path

This is a convenience reference to the core path module

Available methods

FileSystem.access(path, mode)

Refer to fsPromises.access

FileSystem.accessSync(path, mode)

Refer to fs.accessSync

FileSystem.appendFile(path, data, options)

Refer to fsPromises.appendFile

FileSystem.appendFileSync(path, data, options)

Refer to fs.appendFileSync

FileSystem.chmod(path, mode)

Refer to fsPromises.chmod

FileSystem.chmodSync(path, mode)

Refer to fs.chmodSync

FileSystem.chown(path, uid, gid)

Refer to fsPromises.chown

FileSystem.chownSync(path, uid, gid)

Refer to fs.chownSync

FileSystem.closeSync(fd)

Refer to fs.closeSync

FileSystem.copyFile(src, dest, flags)

Refer to fsPromises.copyFile

FileSystem.copyFileSync(src, dest, flags)

Refer to fs.copyFileSync

FileSystem.createReadStream(path, options)

Refer to fs.createReadStream

FileSystem.createWriteStream(path, options)

Refer to fs.createWriteStream

FileSystem.exists(path)

Refer to fs.existsSync

FileSystem.fchmodSync(fd, mode)

Refer to fs.fchmodSync

FileSystem.fchownSync(fd, mode)

Refer to fs.fchownSync

FileSystem.fdatasyncSync(fd)

Refer to fs.fdatasyncSync

FileSystem.fsyncSync(fd)

Refer to fs.fsyncSync

FileSystem.ftruncateSync(fd)

Refer to fs.ftruncateSync

FileSystem.futimesSync(fd, atime, mtime)

Refer to fs.futimesSync

FileSystem.gunzipFile (path, options)

FileSystem.gzipFile (path, options)

FileSystem.lchmod(path, mode)

Refer to fsPromises.lchmod

FileSystem.lchmodSync(path, mode)

Refer to fs.lchmodSync

FileSystem.lchown(path, uid, gid)

Refer to fsPromises.lchown

FileSystem.lchownSync(path, uid, gid)

Refer to fs.lchownSync

FileSystem.link(existingPath, newPath)

Refer to fsPromises.link

FileSystem.linkSync(existingPath, newPath)

Refer to fs.linkSync

FileSystem.lstat(path, options)

Refer to fsPromises.lstat

FileSystem.lstatSync(path, options)

Refer to fs.lstatSync

FileSystem.mkdir(path, options)

Refer to fsPromises.mkdir

FileSystem.mkdirSync(path, options)

Refer to fs.mkdirSync

FileSystem.mkdtemp(prefix, options)

Refer to fsPromises.mkdtemp

FileSystem.mkdtempSync(prefix, options)

Refer to fs.mkdtempSync

FileSystem.open(path, flags, mode)

Refer to fsPromises.open

FileSystem.opendir(path, options)

Refer to fsPromises.opendir

FileSystem.opendirSync(path, options)

Refer to fs.opendirSync

FileSystem.openSync(path, flags, mode)

Refer to fs.openSync

FileSystem.readdir(path, options)

Refer to fsPromises.readdir

FileSystem.readdirSync(path, options)

Refer to fs.readdirSync

FileSystem.readFile(path, options)

Refer to fsPromises.readFile

FileSystem.readFileSync(path, options)

Refer to fs.readFileSync

FileSystem.readlink(path, options)

Refer to fsPromises.readlink

FileSystem.readlinkSync(path, options)

Refer to fs.readlinkSync

FileSystem.readSync(fd, buffer, offset, length, position)

Refer to fs.readSync

FileSystem.realpath(path, options)

Refer to fsPromises.realpath

FileSystem.realpathSync(path, options)

Refer to fs.realpathSync

FileSystem.rename(oldPath, newPath)

Refer to fsPromises.rename

FileSystem.renameSync(oldPath, newPath)

Refer to fs.renameSync

FileSystem.rmdir(path, options)

Refer to fsPromises.rmdir

FileSystem.rmdirSync(path, options)

Refer to fs.rmdirSync

FileSystem.rm(path, options)

Refer to fsPromises.rm

FileSystem.rmSync(path, options)

Refer to fs.rmSync

FileSystem.stat(path, options)

Refer to fsPromises.stat

FileSystem.statSync(path, options)

Refer to fs.statSync

FileSystem.symlink(target, path, type)

Refer to fsPromises.symlink

FileSystem.symlinkSync(target, path, type)

Refer to fs.symlinkSync

FileSystem.truncate(path, len)

Refer to fsPromises.truncate

FileSystem.truncateSync(path, len)

Refer to fs.truncateSync

FileSystem.unlink(path)

Refer to fsPromises.unlink

FileSystem.unlinkSync(path)

Refer to fs.unlinkSync

FileSystem.unwatchFile(filename, listener)

Refer to fs.unwatchFile

FileSystem.utimes(path, atime, mtime)

Refer to fsPromises.utimes

FileSystem.utimesSync(path, atime, mtime)

Refer to fs.utimesSync

FileSystem.watch(filename, options, listener)

Refer to fs.watch

FileSystem.watchFile(filename, options, listener)

Refer to fs.watchFile

FileSystem.writeFile(file, data, options)

Refer to fsPromises.writeFile

FileSystem.writeFileSync(file, data, options)

Refer to fs.writeFileSync

FileSystem.writeSync(fd, buffer, offset, length, position)

Refer to fs.writeSync

FileSystem.writeSync(fd, string, position, encoding)

Refer to fs.writeSync