UNPKG

2.75 kBMarkdownView Raw
1# saxon v0.1.13
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- `list(name)` Get the array of paths in a directory
52- `follow(name, recursive)` Resolve a symlink
53- `exists(name)`
54- `isFile(name)`
55- `isDir(name)`
56- `isLink(name)` Return true if given name is a symlink
57- `touch(name)` Create a file or update its mtime
58- `chmod(name, mode)` Change the permissions of a file
59- `link(name, target)` Create a symlink
60- `write(name, content)` Create or update a file
61- `mkdir(name)` Create a directory
62- `rename(src, dest)`
63- `remove(name, recursive)` Destroy a path
64
65The `stat` function follows symlinks to their real path.
66
67The `list` function throws a `NOT_REAL` error if the given path does not exist.
68It throws a `NOT_DIR` error if the given path is not a directory.
69
70The `remove` function unlinks a file, symlink, or empty directory.
71Pass `true` as the second argument to unlink non-empty directories.