Modern filesystem library
npm install saxonModern filesystem library.
- Paths are relative to the working directory (if not absolute)
- Paths starting with ~/ are resolved relative to os.homedir()
- Error codes are exposed to the user (eg: fs.NOT_REAL)
- Functions available in both APIs behave identically
š§ Under construction
``js`
const fs = require('saxon');
- stat(name) Get the stats of a fileread(name, enc)
- Read an entire file into memoryreader(name, opts)
- Create a readable streamfollow(name, recursive)
- Resolve a symlinkisFile(name)
- isDir(name)
- mkdir(name)
- Create a directorywrite(name, content)
- Create or update a filewriter(name, opts)
- Create a writable stream
The read function takes a path or file descriptor as its first argument."utf8"
The data encoding defaults to .null
Pass a string as the second argument to customize the encoding.
For a buffer object, you must pass as the encoding.
The follow function does not throw when the given path is not a symlink.true
Pass as the second argument to automatically follow a chain of symlinks until a file or directory is found.false
Pass a function as the second argument to be called for every resolved path. Your function must return a boolean, where forces the result to be the previous path.LINK_LIMIT
It throws a error if the real path cannot be resolved within 10 reads.NOT_REAL
It throws a error if a resolved path does not exist.
The mkdir function recursively creates any missing parent directories.PATH_EXISTS
It throws a error if the path (or one of its parents) already exists and isn't a directory.
The writer function creates a WriteStream object.
Pass a number as the first argument to use a file descriptor.
`js`
const fs = require('saxon/sync');
- stat(name) Get the stats of a filelstat(name)
- read(name, enc)
- Read an entire file into memoryreadJson(name)
- readPerms(name)
- Get file permissions in string form (eg: "0777")list(name)
- Get the array of paths in a directoryfollow(name, recursive)
- Resolve a symlinkexists(name)
- isFile(name)
- isDir(name)
- isLink(name)
- Return true if given name is a symlinktouch(name)
- Create a file or update its mtimechmod(name, mode)
- Change the permissions of a filelink(name, target)
- Create a symlinkwrite(name, content)
- Create or update a filemkdir(name)
- Create a directoryrename(src, dest)
- copy(src, dest)
- Copy a file or directoryremove(name, recursive)
- Destroy a path
The stat function follows symlinks to their real path.
The list function throws a NOT_REAL error if the given path does not exist.NOT_DIR
It throws a error if the given path is not a directory.
The copy function throws a NOT_REAL error if the given src path does not exist.src
When the path is a file and the dest path is a directory, the src path isdest
copied into the directory. When both are directories, the src directory isdest
merged into the directory, rather than replacing it entirely. Symlinks are
preserved, but their target paths are never changed.
The remove function unlinks a file, symlink, or empty directory.true` as the second argument to unlink non-empty directories.
Pass