UNPKG

2.77 kBMarkdownView Raw
1# saxon v0.1.16
2
3Modern filesystem library.
4
5- Paths are relative to the working directory (if not absolute)
6- Paths starting with `~/` are resolved relative to `os.homedir()`
7- Error codes are exposed to the user (eg: `fs.NOT_REAL`)
8- Functions available in both APIs behave identically
9
10🚧 *Under construction*
11
12```js
13const fs = require('saxon');
14```
15
16- `stat(name)` Get the stats of a file
17- `read(name, enc)` Read an entire file into memory
18- `reader(name, opts)` Create a readable stream
19- `follow(name, recursive)` Resolve a symlink
20- `isFile(name)`
21- `isDir(name)`
22- `mkdir(name)` Create a directory
23- `write(name, content)` Create or update a file
24- `writer(name, opts)` Create a writable stream
25
26The `read` function takes a path or file descriptor as its first argument.
27The data encoding defaults to `"utf8"`.
28Pass a string as the second argument to customize the encoding.
29For a buffer object, you must pass `null` as the encoding.
30
31The `follow` function does *not* throw when the given path is not a symlink.
32Pass `true` as the second argument to automatically follow a chain of symlinks until a file or directory is found.
33Pass a function as the second argument to be called for every resolved path. Your function must return a boolean, where `false` forces the result to be the previous path.
34It throws a `LINK_LIMIT` error if the real path cannot be resolved within 10 reads.
35It throws a `NOT_REAL` error if a resolved path does not exist.
36
37The `mkdir` function recursively creates any missing parent directories.
38It throws a `PATH_EXISTS` error if the path (or one of its parents) already exists and isn't a directory.
39
40The `writer` function creates a `WriteStream` object.
41Pass a number as the first argument to use a file descriptor.
42
43## Blocking API
44
45```js
46const fs = require('saxon/sync');
47```
48
49- `stat(name)` Get the stats of a file
50- `read(name, enc)` Read an entire file into memory
51- `readJson(name)`
52- `list(name)` Get the array of paths in a directory
53- `follow(name, recursive)` Resolve a symlink
54- `exists(name)`
55- `isFile(name)`
56- `isDir(name)`
57- `isLink(name)` Return true if given name is a symlink
58- `touch(name)` Create a file or update its mtime
59- `chmod(name, mode)` Change the permissions of a file
60- `link(name, target)` Create a symlink
61- `write(name, content)` Create or update a file
62- `mkdir(name)` Create a directory
63- `rename(src, dest)`
64- `remove(name, recursive)` Destroy a path
65
66The `stat` function follows symlinks to their real path.
67
68The `list` function throws a `NOT_REAL` error if the given path does not exist.
69It throws a `NOT_DIR` error if the given path is not a directory.
70
71The `remove` function unlinks a file, symlink, or empty directory.
72Pass `true` as the second argument to unlink non-empty directories.