dom-filesystem
v1.0.8
Published
Use the DOM as filesystem, you give you access to Node.js fs API such as: fs.readFileSync, fs.watch etc.
Downloads
11
Readme
Dom Filesystem
Use the Node.js filesystem API inside the browser, but not storing it inside LocalStorage
, it stores it inside the DOM.
So if you press ctrl+s
and save the .html file, the changes will persist in the file, so you can create HTML quines with this library without chancing the way you use your Node.js app, but simply changing libraries.
I made this mostly for making Digital Gardens
On: https://github.com/ilse-langnar/notebook and other projects where a quine is desirable.
How to use
const fs = require("dom-filesystem")(document)
// Sync
fs.writeFileSync( "/hello-world.txt", "Hello, World" )
let hello_world = fs.readFileSync( "/hello-world.txt" )
console.log( "hello_world -> ", hello_world )
// Async
fs.writeFile( "/hello-world.txt", "Hello, World", err => {
if( err ) throw new Error( `Could not write file. ${err}` )
let hello_world = fs.readFile( "/hello-world.txt", ( err2, data ) => {
if( err2 ) throw new Error( `Could not read file: ${err2}` )
console.log( "data -> ", data )
})
})
TODO
[ ] fs.rename(oldPath, newPath, callback); // Asynchronous rename. No arguments other than a possible exception are given to the completion callback.Asynchronous ftruncate. No arguments other than a possible exception are given to the completion callback.
[ ] fs.renameSync(oldPath, newPath); // Synchronous rename.
[ ] fs.ftruncate(fd, len, callback); // Asynchronous ftruncate. No arguments other than a possible exception are given to the completion callback.
[ ] fs.ftruncateSync(fd, len); // Synchronous ftruncate.
[ ] fs.truncate(path, len, callback); // Asynchronous truncate. No arguments other than a possible exception are given to the completion callback.
[ ] fs.truncateSync(path, len); // Synchronous truncate.
[ ] fs.chown(path, uid, gid, callback); // Asynchronous chown. No arguments other than a possible exception are given to the completion callback.
[ ] fs.chownSync(path, uid, gid); // Synchronous chown.
[ ] fs.fchown(fd, uid, gid, callback); // Asynchronous fchown. No arguments other than a possible exception are given to the completion callback.
[ ] fs.fchownSync(fd, uid, gid); // Synchronous fchown.
[ ] fs.lchown(path, uid, gid, callback); // Asynchronous lchown. No arguments other than a possible exception are given to the completion callback.
[ ] fs.lchownSync(path, uid, gid); // Synchronous lchown.
[ ] fs.chmod(path, mode, callback); // Asynchronous chmod. No arguments other than a possible exception are given to the completion callback.
[ ] fs.chmodSync(path, mode); // Synchronous chmod.
[ ] fs.fchmod(fd, mode, callback); // Asynchronous fchmod. No arguments other than a possible exception are given to the completion callback.
[ ] fs.fchmodSync(fd, mode); // Synchronous fchmod.
[ ] fs.lchmod(path, mode, callback); // Asynchronous lchmod. No arguments other than a possible exception are given to the completion callback.
[ ] fs.lchmodSync(path, mode); // Synchronous lchmod.
[ ] fs.stat(path, callback); // Asynchronous stat. The callback gets two arguments (err, stats) where stats is a fs.Stats object.
[ ] fs.statSync(path); // Synchronous stat. Returns an instance of fs.Stats.
[ ] fs.lstat(path, callback); // Asynchronous lstat. The callback gets two arguments (err, stats) where stats is a fs.Stats object. lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to.
[ ] fs.lstatSync(path); // Synchronous lstat. Returns an instance of fs.Stats.
[ ] fs.fstat(fd, callback); // Asynchronous fstat. The callback gets two arguments (err, stats) where stats is a fs.Stats object. fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor fd.
[ ] fs.fstatSync(fd); // Synchronous fstat. Returns an instance of fs.Stats.
[ ] fs.link(srcpath, dstpath, callback); // Asynchronous link. No arguments other than a possible exception are given to the completion callback.
[ ] fs.linkSync(srcpath, dstpath); // Synchronous link.
[ ] fs.symlink(srcpath, dstpath, [type], callback); // Asynchronous symlink. No arguments other than a possible exception are given to the completion callback. The type argument can be set to 'dir', 'file', or 'junction' (default is 'file') and is only available on Windows (ignored on other platforms)
[ ] fs.symlinkSync(srcpath, dstpath, [type]); // Synchronous symlink.
[ ] fs.readlink(path, callback); // Asynchronous readlink. The callback gets two arguments (err, linkString).
[ ] fs.readlinkSync(path); // Synchronous readlink. Returns the symbolic link's string value.
[ ] fs.unlink(path, callback); // Asynchronous unlink. No arguments other than a possible exception are given to the completion callback.
[ ] fs.unlinkSync(path); // Synchronous unlink.
[ ] fs.realpath(path, [cache], callback); // Asynchronous realpath. The callback gets two arguments (err, resolvedPath).
[ ] fs.realpathSync(path, [cache]); // Synchronous realpath. Returns the resolved path.
[ ] fs.rmdir(path, callback); // Asynchronous rmdir. No arguments other than a possible exception are given to the completion callback.
[ ] fs.rmdirSync(path); // Synchronous rmdir.
[ ] fs.mkdir(path, [mode], callback); // Asynchronous mkdir. No arguments other than a possible exception are given to the completion callback. mode defaults to 0777.
[ ] fs.mkdirSync(path, [mode]); // Synchronous mkdir.
[ ] fs.readdir(path, callback); // Asynchronous readdir. Reads the contents of a directory. The callback gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'.
[ ] fs.readdirSync(path); // Synchronous readdir. Returns an array of filenames excluding '.' and '..'.
[ ] fs.close(fd, callback); // Asynchronous close. No arguments other than a possible exception are given to the completion callback.
[ ] fs.closeSync(fd); // Synchronous close.
[ ] fs.open(path, flags, [mode], callback); // Asynchronous file open.
[ ] fs.openSync(path, flags, [mode]); // Synchronous version of fs.open().
[ ] fs.utimes(path, atime, mtime, callback); // Change file timestamps of the file referenced by the supplied path.
[ ] fs.utimesSync(path, atime, mtime); // Synchronous version of fs.utimes().
[ ] fs.futimes(fd, atime, mtime, callback); // Change the file timestamps of a file referenced by the supplied file descriptor.
[ ] fs.futimesSync(fd, atime, mtime); // Synchronous version of fs.futimes().
[ ] fs.fsync(fd, callback); // Asynchronous fsync. No arguments other than a possible exception are given to the completion callback.
[ ] fs.fsyncSync(fd); // Synchronous fsync.
[ ] fs.write(fd, buffer, offset, length, position, callback); // Write buffer to the file specified by fd.
[ ] fs.writeSync(fd, buffer, offset, length, position); // Synchronous version of fs.write(). Returns the number of bytes written.
[ ] fs.read(fd, buffer, offset, length, position, callback); // Read data from the file specified by fd.
[ ] fs.readSync(fd, buffer, offset, length, position); // Synchronous version of fs.read. Returns the number of bytesRead.
[ ] fs.readFile(filename, [options], callback); // Asynchronously reads the entire contents of a file.
[x] fs.readFileSync(filename, [options]); // Synchronous version of fs.readFile. Returns the contents of the filename. If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.
[ ] fs.writeFile(filename, data, [options], callback); // Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer.
[x] fs.writeFileSync(filename, data, [options]); // The synchronous version of fs.writeFile.
[ ] fs.appendFile(filename, data, [options], callback); // Asynchronously append data to a file, creating the file if it not yet exists. data can be a string or a buffer.
[ ] fs.appendFileSync(filename, data, [options]); // The synchronous version of fs.appendFile.
[ ] fs.watch(filename, [options], [listener]); // Watch for changes on filename, where filename is either a file or a directory. The returned object is a fs.FSWatcher. The listener callback gets two arguments (event, filename). event is either 'rename' or 'change', and filename is the name of the file which triggered the event.
[ ] fs.exists(path, callback); // Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false. (should not be used)
[ ] fs.existsSync(path); // Synchronous version of fs.exists. (should not be used)
[ ] // fs.Stats: objects returned from fs.stat(), fs.lstat() and fs.fstat() and their synchronous counterparts are of this type.
[ ] stats.isFile();
[ ] stats.isDirectory()
[ ] stats.isBlockDevice()
[ ] stats.isCharacterDevice()
[ ] stats.isSymbolicLink() // (only valid with fs.lstat())
[ ] stats.isFIFO()
[ ] stats.isSocket()
[ ] fs.createReadStream(path, [options]); // Returns a new ReadStream object.
[ ] fs.createWriteStream(path, [options]); // Returns a new WriteStream object.