Use the Node fs
API in Chrome Apps
This module is used by chromiumify
This library can be used directly with your browserify builds with targeting Chrome Packaged Apps.
$ npm install chrome-fs --save
$ browserify -r chrome-fs:fs index.js -o bundle.js
This list is based on the node.js documentation https://nodejs.org/api/fs.html Sync apis won't be supported they are listed here https://github.com/No9/chrome-fs/wiki/API-Mapping
- fs.rename(oldPath, newPath, callback)
- fs.ftruncate(fd, len, callback)
- fs.truncate(path, len, callback)
- fs.chown(path, uid, gid, callback)
- fs.fchown(fd, uid, gid, callback)
- fs.lchown(path, uid, gid, callback)
- fs.chmod(path, mode, callback)
- fs.fchmod(fd, mode, callback)
- fs.lchmod(path, mode, callback)
- fs.stat(path, callback)
- fs.lstat(path, callback)
- fs.fstat(fd, callback)
- fs.link(srcpath, dstpath, callback)
- fs.symlink(srcpath, dstpath[, type], callback)
- fs.readlink(path, callback)
- fs.realpath(path[, cache], callback)
- fs.unlink(path, callback)
- fs.rmdir(path, callback)
- fs.mkdir(path[, mode], callback)
- fs.readdir(path, callback)
- fs.close(fd, callback)
- fs.open(path, flags[, mode], callback)
- fs.utimes(path, atime, mtime, callback)
- fs.futimes(fd, atime, mtime, callback)
- fs.write(fd, buffer, offset, length[, position], callback)
- fs.write(fd, data[, position[, encoding]], callback)
- fs.read(fd, buffer, offset, length, position, callback)
- fs.readFile(filename[, options], callback)
- fs.writeFile(filename, data[, options], callback)
- fs.appendFile(filename, data[, options], callback)
- fs.watchFile(filename[, options], listener)
- fs.unwatchFile(filename[, listener])
- fs.watch(filename[, options][, listener])
- fs.exists(path, callback)
- fs.access(path[, mode], callback)
- fs.createReadStream(path[, options])
- fs.createWriteStream(path[, options])
- fs.Stats
- Stat Time Values
- fs.ReadStream
- Event: 'open'
- fs.WriteStream
- Event: 'open'
- file.bytesWritten
- fs.FSWatcher
- watcher.close()
- Event: 'change'
- Event: 'error'
$ npm test
This will load the folder test/chrome-app
as an unpacked extension in chrome.
Test currently designed for Chrome on Windows and Linux Canary on Mac other variants accepted
It is recommended that the following permissions are added to your chrome packaged app for this module.
"permissions": [
"unlimitedStorage"
]
Chrome Packaged Apps don't have the notion of current working directory CWD
.
So relative paths are not escapted they are trimmed to be relative from root
i.e.
../../direct1/file1
Will resolve to /direct1/file1
.
Will resolve to /
Chrome Packaged Apps allow you to see and edit the filesystem from the dev tools so the chown, fchown, chmod, fmod
calls are there for compatibility only.
Any chown call will not be reflected in stat
Best effort has been made to support stat
but the Chrome File System is not a complete implementation.
Files have size
and last modified
but directories have no size and default to the start of epoc for last modified.
Currently only UTF-8 is supported
There seems to be an issue around saving files in chomefs
anton whalley @no9