UNPKG

3.29 kBMarkdownView Raw
1# saxon v0.2.7
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- `lstat(name)`
51- `read(name, enc)` Read an entire file into memory
52- `readJson(name)`
53- `readPerms(name)` Get file permissions in string form (eg: `"0777"`)
54- `list(name)` Get the array of paths in a directory
55- `follow(name, recursive)` Resolve a symlink
56- `exists(name)`
57- `isFile(name)`
58- `isDir(name)`
59- `isLink(name)` Return true if given name is a symlink
60- `touch(name)` Create a file or update its mtime
61- `chmod(name, mode)` Change the permissions of a file
62- `link(name, target)` Create a symlink
63- `write(name, content)` Create or update a file
64- `mkdir(name)` Create a directory
65- `rename(src, dest)`
66- `copy(src, dest)` Copy a file or directory
67- `remove(name, recursive)` Destroy a path
68
69The `stat` function follows symlinks to their real path.
70
71The `list` function throws a `NOT_REAL` error if the given path does not exist.
72It throws a `NOT_DIR` error if the given path is not a directory.
73
74The `copy` function throws a `NOT_REAL` error if the given `src` path does not exist.
75When the `src` path is a file and the `dest` path is a directory, the `src` path is
76copied into the `dest` directory. When both are directories, the `src` directory is
77merged into the `dest` directory, rather than replacing it entirely. Symlinks are
78preserved, but their target paths are never changed.
79
80The `remove` function unlinks a file, symlink, or empty directory.
81Pass `true` as the second argument to unlink non-empty directories.