pwd-fs 3.5.0 → 3.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/bitmask.d.ts +10 -0
  2. package/dist/bitmask.js +10 -0
  3. package/dist/powered-file-system/append.d.ts +10 -0
  4. package/dist/powered-file-system/append.js +10 -0
  5. package/dist/powered-file-system/chmod.d.ts +10 -0
  6. package/dist/powered-file-system/chmod.js +10 -0
  7. package/dist/powered-file-system/chown.d.ts +10 -0
  8. package/dist/powered-file-system/chown.js +10 -0
  9. package/dist/powered-file-system/copy.d.ts +10 -0
  10. package/dist/powered-file-system/copy.js +10 -0
  11. package/dist/powered-file-system/empty-dir.d.ts +10 -0
  12. package/dist/powered-file-system/empty-dir.js +10 -0
  13. package/dist/powered-file-system/mkdir.d.ts +10 -0
  14. package/dist/powered-file-system/mkdir.js +10 -0
  15. package/dist/powered-file-system/read.d.ts +10 -0
  16. package/dist/powered-file-system/read.js +10 -0
  17. package/dist/powered-file-system/readdir.d.ts +10 -0
  18. package/dist/powered-file-system/readdir.js +10 -0
  19. package/dist/powered-file-system/readlink.d.ts +10 -0
  20. package/dist/powered-file-system/readlink.js +10 -0
  21. package/dist/powered-file-system/realpath.d.ts +10 -0
  22. package/dist/powered-file-system/realpath.js +10 -0
  23. package/dist/powered-file-system/remove.d.ts +10 -0
  24. package/dist/powered-file-system/remove.js +10 -0
  25. package/dist/powered-file-system/rename.d.ts +10 -0
  26. package/dist/powered-file-system/rename.js +10 -0
  27. package/dist/powered-file-system/stat.d.ts +10 -0
  28. package/dist/powered-file-system/stat.js +10 -0
  29. package/dist/powered-file-system/symlink.d.ts +10 -0
  30. package/dist/powered-file-system/symlink.js +10 -0
  31. package/dist/powered-file-system/test.d.ts +10 -0
  32. package/dist/powered-file-system/test.js +10 -0
  33. package/dist/powered-file-system/write.d.ts +10 -0
  34. package/dist/powered-file-system/write.js +10 -0
  35. package/dist/powered-file-system.d.ts +10 -0
  36. package/dist/powered-file-system.js +10 -0
  37. package/dist/recurse-io-sync.d.ts +10 -0
  38. package/dist/recurse-io-sync.js +10 -0
  39. package/dist/recurse-io.d.ts +10 -0
  40. package/dist/recurse-io.js +10 -0
  41. package/package.json +10 -21
  42. package/readme.md +273 -426
  43. package/dist/bitmask.test.d.ts +0 -1
  44. package/dist/bitmask.test.js +0 -29
  45. package/dist/powered-file-system/append.test.d.ts +0 -1
  46. package/dist/powered-file-system/append.test.js +0 -47
  47. package/dist/powered-file-system/chmod.test.d.ts +0 -1
  48. package/dist/powered-file-system/chmod.test.js +0 -71
  49. package/dist/powered-file-system/chown.test.d.ts +0 -1
  50. package/dist/powered-file-system/chown.test.js +0 -82
  51. package/dist/powered-file-system/copy.test.d.ts +0 -1
  52. package/dist/powered-file-system/copy.test.js +0 -128
  53. package/dist/powered-file-system/empty-dir.test.d.ts +0 -1
  54. package/dist/powered-file-system/empty-dir.test.js +0 -61
  55. package/dist/powered-file-system/mkdir.test.d.ts +0 -1
  56. package/dist/powered-file-system/mkdir.test.js +0 -116
  57. package/dist/powered-file-system/read.test.d.ts +0 -1
  58. package/dist/powered-file-system/read.test.js +0 -75
  59. package/dist/powered-file-system/readdir.test.d.ts +0 -1
  60. package/dist/powered-file-system/readdir.test.js +0 -72
  61. package/dist/powered-file-system/readlink.test.d.ts +0 -1
  62. package/dist/powered-file-system/readlink.test.js +0 -44
  63. package/dist/powered-file-system/realpath.test.d.ts +0 -1
  64. package/dist/powered-file-system/realpath.test.js +0 -44
  65. package/dist/powered-file-system/remove.test.d.ts +0 -1
  66. package/dist/powered-file-system/remove.test.js +0 -78
  67. package/dist/powered-file-system/rename.test.d.ts +0 -1
  68. package/dist/powered-file-system/rename.test.js +0 -70
  69. package/dist/powered-file-system/stat.test.d.ts +0 -1
  70. package/dist/powered-file-system/stat.test.js +0 -79
  71. package/dist/powered-file-system/symlink.test.d.ts +0 -1
  72. package/dist/powered-file-system/symlink.test.js +0 -77
  73. package/dist/powered-file-system/test.test.d.ts +0 -1
  74. package/dist/powered-file-system/test.test.js +0 -76
  75. package/dist/powered-file-system/write.test.d.ts +0 -1
  76. package/dist/powered-file-system/write.test.js +0 -97
  77. package/dist/powered-file-system.test.d.ts +0 -1
  78. package/dist/powered-file-system.test.js +0 -46
  79. package/dist/suite.test.d.ts +0 -1
  80. package/dist/suite.test.js +0 -40
  81. package/dist/test-utils.d.ts +0 -18
  82. package/dist/test-utils.js +0 -72
package/readme.md CHANGED
@@ -1,591 +1,438 @@
1
- # pwd-fs
1
+ # Powered File System
2
2
 
3
- [![License](https://img.shields.io/npm/l/pwd-fs)](https://github.com/woodger/pwd-fs/blob/master/LICENSE)
4
- [![CI](https://github.com/woodger/pwd-fs/actions/workflows/ci.yml/badge.svg)](https://github.com/woodger/pwd-fs/actions/workflows/ci.yml)
3
+ [![npm version](https://img.shields.io/npm/v/pwd-fs.svg)](https://www.npmjs.com/package/pwd-fs)
4
+ [![node](https://img.shields.io/node/v/pwd-fs.svg)](https://www.npmjs.com/package/pwd-fs)
5
+ [![types](https://img.shields.io/npm/types/pwd-fs.svg)](https://www.npmjs.com/package/pwd-fs)
6
+ [![license](https://img.shields.io/npm/l/pwd-fs.svg)](LICENSE)
5
7
 
6
- `pwd-fs` is a path-aware wrapper around Node.js file system APIs.
8
+ This module extends the [Node.js®](https://nodejs.org) file system API with a declared `pwd` (working directory) and recursive execution helpers. By default, all file system operations have asynchronous forms. The API provides an alternative set of asynchronous file system methods that return `Promise` objects.
7
9
 
8
- It provides:
10
+ ## Getting Started
9
11
 
10
- - a dedicated working directory per instance
11
- - Promise-based async methods
12
- - matching synchronous variants via `{ sync: true }`
13
- - recursive helpers for copy, remove, chmod, chown, and mkdir
12
+ ### Installation
14
13
 
15
- Relative paths are resolved against `pfs.pwd`. Absolute paths are used as-is, so `pfs.pwd` is a convenience base path, not a sandbox.
16
-
17
- ## Why Use It
18
-
19
- Use `pwd-fs` when you want file system operations to be rooted at a specific working directory without manually calling `path.resolve()` before every operation.
20
-
21
- It is especially useful for:
22
-
23
- - CLI tools that operate inside a project root
24
- - build or code generation scripts
25
- - isolated test fixtures
26
- - small automation tasks that need Promise-based file system helpers
27
-
28
- ## Installation
14
+ To use `Powered File System` in your project, run:
29
15
 
30
16
  ```bash
31
17
  npm install pwd-fs
32
18
  ```
33
19
 
34
- ## Table of Contents
35
-
36
- - [Quick Start](#quick-start)
37
- - [Common Recipes](#common-recipes)
38
- - [Compatibility](#compatibility)
39
- - [Exports](#exports)
40
- - [API](#api)
41
- - [`new PoweredFileSystem(pwd?)`](#new-poweredfilesystempwd)
42
- - [`pfs.pwd`](#pfspwd)
43
- - [`pfs.resolve(src)`](#pfsresolvesrc)
44
- - [`pfs.constants`](#pfsconstants)
45
- - [`PoweredFileSystem.bitmask(mode)`](#poweredfilesystembitmaskmode)
46
- - [`pfs.test(src, options?)`](#pfstestsrc-options)
47
- - [`pfs.stat(src, options?)`](#pfsstatsrc-options)
48
- - [`pfs.chmod(src, mode, options?)`](#pfschmodsrc-mode-options)
49
- - [`pfs.chown(src, options?)`](#pfschownsrc-options)
50
- - [`pfs.symlink(src, dest, options?)`](#pfssymlinksrc-dest-options)
51
- - [`pfs.copy(src, dest, options?)`](#pfscopysrc-dest-options)
52
- - [`pfs.rename(src, dest, options?)`](#pfsrenamesrc-dest-options)
53
- - [`pfs.remove(src, options?)`](#pfsremovesrc-options)
54
- - [`pfs.emptyDir(src, options?)`](#pfsemptydirsrc-options)
55
- - [`pfs.read(src, options?)`](#pfsreadsrc-options)
56
- - [`pfs.write(src, data, options?)`](#pfswritesrc-data-options)
57
- - [`pfs.append(src, data, options?)`](#pfsappendsrc-data-options)
58
- - [`pfs.readdir(dir, options?)`](#pfsreaddirdir-options)
59
- - [`pfs.readlink(src, options?)`](#pfsreadlinksrc-options)
60
- - [`pfs.realpath(src, options?)`](#pfsrealpathsrc-options)
61
- - [`pfs.mkdir(dir, options?)`](#pfsmkdirdir-options)
62
- - [Sync Mode](#sync-mode)
63
- - [Error Behavior](#error-behavior)
64
- - [Umask Behavior](#umask-behavior)
65
- - [Notes](#notes)
66
- - [Platform Caveats](#platform-caveats)
67
- - [When To Use Native `fs`](#when-to-use-native-fs)
68
- - [Development](#development)
69
- - [License](#license)
70
-
71
- ## Quick Start
20
+ #### Table of Contents
72
21
 
73
- ```ts
74
- import { pfs } from 'pwd-fs';
22
+ [class PoweredFileSystem](#class-poweredfilesystem)
75
23
 
76
- await pfs.mkdir('./own/project'); // recursively create the directory
77
- ```
24
+ * [constructor: new PoweredFileSystem([path])](#constructor-new-poweredfilesystempath)
25
+ * [pfs.test(src[, options])](#pfstestsrc-options)
26
+ * [pfs.stat(src[, options])](#pfsstatsrc-options)
27
+ * [pfs.chmod(src, mode[, options])](#pfschmodsrc-mode-options)
28
+ * [pfs.chown(src[, options])](#pfschownsrc-options)
29
+ * [pfs.symlink(src, dest[, options])](#pfssymlinksrc-dest-options)
30
+ * [pfs.copy(src, dir[, options])](#pfscopysrc-dir-options)
31
+ * [pfs.rename(src, dest[, options])](#pfsrenamesrc-dest-options)
32
+ * [pfs.remove(src[, options])](#pfsremovesrc-options)
33
+ * [pfs.emptyDir(src[, options])](#pfsemptydirsrc-options)
34
+ * [pfs.read(src[, options])](#pfsreadsrc-options)
35
+ * [pfs.write(src, data[, options])](#pfswritesrc-data-options)
36
+ * [pfs.append(src, data[, options])](#pfsappendsrc-data-options)
37
+ * [pfs.readdir(dir[, options])](#pfsreaddirdir-options)
38
+ * [pfs.readlink(src[, options])](#pfsreadlinksrc-options)
39
+ * [pfs.realpath(src[, options])](#pfsrealpathsrc-options)
40
+ * [pfs.mkdir(dir[, options])](#pfsmkdirdir-options)
41
+ * [pfs.pwd](#pfspwd)
42
+ * [static: bitmask(mode)](#static-bitmaskmode)
78
43
 
79
- ## Common Recipes
44
+ The class methods are divided into resource groups.
80
45
 
81
- ### Work inside a project directory
46
+ | Resource | Methods |
47
+ |-----------------------------|------------------------------------------------------------------|
48
+ | Common (file and directory) | `chmod` `chown` `copy` `realpath` `remove` `rename` `stat` `test` |
49
+ | File only | `append` `read` `write` |
50
+ | Directory only | `emptyDir` `mkdir` `readdir` |
51
+ | Link only | `readlink` `symlink` |
82
52
 
83
- ```ts
84
- import { PoweredFileSystem } from 'pwd-fs';
85
53
 
86
- const projectFs = new PoweredFileSystem('/workspace/my-project');
54
+ #### class PoweredFileSystem
87
55
 
88
- await projectFs.write('./.cache/build.txt', 'ok');
89
- const exists = await projectFs.test('./.cache/build.txt');
90
- ```
56
+ This class is implemented in TypeScript and follows [Node.js](https://nodejs.org) file system semantics.
91
57
 
92
- ### Copy assets into a build directory
58
+ #### constructor: new PoweredFileSystem([path])
93
59
 
94
- ```ts
95
- await pfs.mkdir('./dist');
96
- await pfs.copy('./assets', './dist');
97
- ```
98
-
99
- Result:
100
-
101
- - source: `./assets`
102
- - destination directory: `./dist`
103
- - created output: `./dist/assets`
60
+ - `path` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative directory name. `path` sets the `pfs.pwd` value. By default, it is [process.cwd()](https://nodejs.org/api/process.html#process_process_cwd).
104
61
 
105
- ### Empty a directory but keep it
62
+ String paths are interpreted as UTF-8 character sequences identifying absolute or relative file names.
106
63
 
107
64
  ```ts
108
- await pfs.emptyDir('./cache');
65
+ import { pfs } from 'pwd-fs';
66
+
67
+ // pfs.pwd === process.cwd()
109
68
  ```
110
69
 
111
- ### Resolve a symlink target
70
+ Relative paths will be resolved relative to the current working directory as specified by `process.cwd()`:
112
71
 
113
72
  ```ts
114
- const target = await pfs.readlink('./current');
115
- const resolved = await pfs.realpath('./current');
116
- ```
73
+ import { PoweredFileSystem } from 'pwd-fs';
117
74
 
118
- ### Append to a file
75
+ // pfs.pwd === `${process.cwd()}/foo/bar`
119
76
 
120
- ```ts
121
- await pfs.write('./app.log', 'first line\n');
122
- await pfs.write('./app.log', 'second line\n', { flag: 'a' });
77
+ const pfs = new PoweredFileSystem('./foo/bar');
123
78
  ```
124
79
 
125
- ### Read a file as a buffer
80
+ Absolute paths:
126
81
 
127
82
  ```ts
128
- const raw = await pfs.read('./archive.bin', { encoding: null });
129
- ```
83
+ import { PoweredFileSystem } from 'pwd-fs';
130
84
 
131
- ### Remove a temporary directory recursively
85
+ // pfs.pwd === __dirname
132
86
 
133
- ```ts
134
- if (await pfs.test('./tmp')) {
135
- await pfs.remove('./tmp');
136
- }
87
+ const pfs = new PoweredFileSystem(__dirname);
137
88
  ```
138
89
 
139
- ## Compatibility
90
+ #### pfs.test(src[, options])
140
91
 
141
- - package `engines`: Node.js `>=18`
142
- - module format: CommonJS package output with TypeScript declarations
143
- - platform notes:
144
- - `chown()` is effectively a no-op on Windows apart from path validation
145
- - `chmod()` behavior on Windows is limited by the platform
146
- - `x` access checks in `test()` do not have the same meaning on Windows as on Unix-like systems
92
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
93
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
94
+ - `flag` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is an optional string that specifies the accessibility checks to be performed. **Default:** `'e'`.
95
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
96
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with a `boolean`.
147
97
 
148
- ## Exports
98
+ Tests a user's permissions for the file or directory specified by path.
149
99
 
150
100
  ```ts
151
- import PoweredFileSystem, { pfs, bitmask } from 'pwd-fs';
101
+ const access = await pfs.test('./path');
102
+ console.log(access); // true
152
103
  ```
104
+ > Function `pfs.test()` resolves with `false` for access errors instead of rejecting.
153
105
 
154
- - `default`: `PoweredFileSystem`
155
- - `pfs`: default instance rooted at `process.cwd()`
156
- - `bitmask(mode)`: helper that extracts standard permission bits from `fs.Stats.mode`
157
-
158
- ## API
159
-
160
- ### `new PoweredFileSystem(pwd?)`
106
+ The following `flag` values are meant for use with `pfs.test()`.
161
107
 
162
- Creates a new instance with `pwd` as the base directory for relative paths.
108
+ Flag | Description
109
+ -----|-------------
110
+ `'e'` | Source exists
111
+ `'r'` | Source can be read
112
+ `'w'` | Source can be written
113
+ `'x'` | Source can be executed. This has no effect on Windows system (will behave like `e`).
163
114
 
164
- - `pwd?: string`
165
- - default: `process.cwd()`
166
-
167
- ```ts
168
- import { PoweredFileSystem } from 'pwd-fs';
115
+ #### pfs.stat(src[, options])
169
116
 
170
- const pfs = new PoweredFileSystem('./workspace');
171
- ```
117
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
118
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
119
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
120
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `fs.Stats`.
172
121
 
173
- ### `pfs.pwd`
122
+ These functions return `lstat` information about a resource in the file system. Symbolic links are reported as links instead of followed targets.
174
123
 
175
- Absolute base directory used to resolve relative paths.
124
+ #### pfs.chmod(src, mode[, options])
176
125
 
177
- ### `pfs.resolve(src)`
126
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
127
+ - `mode` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> Is a numeric `bitmask` created using a logical `OR`.
128
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
129
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
130
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
178
131
 
179
- Resolves `src` against `pfs.pwd`.
132
+ Asynchronously changes the permissions of a file or directory tree.
180
133
 
181
134
  ```ts
182
- const pfs = new PoweredFileSystem('/workspace/project');
183
- const file = pfs.resolve('./src/index.ts');
184
- ```
135
+ import { bitmask } from 'pwd-fs';
185
136
 
186
- Absolute paths are preserved:
137
+ await pfs.chmod('./path', 0o750);
138
+ const { mode } = await pfs.stat('./path');
187
139
 
188
- ```ts
189
- pfs.resolve('/tmp/outside.txt'); // '/tmp/outside.txt'
140
+ console.log(bitmask(mode) === 0o750); // true
190
141
  ```
191
142
 
192
- ### `pfs.constants`
143
+ > **Caveats:** on Windows only the write permission can be changed, and the distinction among the permissions of group, owner or others is not implemented.
193
144
 
194
- Access mode aliases used by `pfs.test()`:
145
+ See manuals [chmod(2)](http://man7.org/linux/man-pages/man2/chmod.2.html)
195
146
 
196
- - `e`: existence
197
- - `r`: readable
198
- - `w`: writable
199
- - `x`: executable
147
+ #### pfs.chown(src[, options])
200
148
 
201
- ### `PoweredFileSystem.bitmask(mode)`
149
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
150
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
151
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
152
+ - `uid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> The file's new owner's user id.
153
+ - `gid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> The file's new group's group id.
154
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
202
155
 
203
- Static alias for `bitmask(mode)`.
156
+ Asynchronously changes owner and group of a file or directory tree.
157
+ If `uid` or `gid` is omitted, the current value is preserved. On Windows, `chown()` validates the path but does not change POSIX ownership.
158
+ See manuals [chown(2)](http://man7.org/linux/man-pages/man2/chown.2.html).
204
159
 
205
- ```ts
206
- const { mode } = await pfs.stat('./file.txt');
207
- const permissions = PoweredFileSystem.bitmask(mode);
208
- ```
160
+ #### pfs.symlink(src, dest[, options])
209
161
 
210
- ### `pfs.test(src, options?)`
162
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
163
+ - `dest` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the symbolic link to create. If `dest` exists, it will not be overwritten.
164
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
165
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
166
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
211
167
 
212
- Checks whether a path is accessible.
168
+ Asynchronously creates a new symbolic link (also known as a soft link).
213
169
 
214
170
  ```ts
215
- test<T extends boolean = false>(
216
- src: string,
217
- options?: { sync?: T; flag?: 'e' | 'r' | 'w' | 'x' }
218
- ): T extends true ? boolean : Promise<boolean>
219
- ```
171
+ await pfs.symlink('./path', './link');
172
+ const stats = await pfs.stat('./link');
220
173
 
221
- - `src`: absolute or instance-relative path
222
- - `flag`: access check to perform
223
- - default flag: `'e'`
224
-
225
- ```ts
226
- const exists = await pfs.test('./notes.txt');
227
- const writable = pfs.test('./notes.txt', { sync: true, flag: 'w' });
174
+ console.log(stats.isSymbolicLink()); // true
228
175
  ```
229
176
 
230
- ### `pfs.stat(src, options?)`
231
-
232
- Returns `fs.lstat()` information for a path.
233
-
234
- ```ts
235
- stat<T extends boolean = false>(
236
- src: string,
237
- options?: { sync?: T }
238
- ): T extends true ? Stats : Promise<Stats>
239
- ```
177
+ See manuals [symlink(2)](http://man7.org/linux/man-pages/man2/symlink.2.html).
240
178
 
241
- This method uses `lstat`, so symbolic links are reported as links instead of followed targets.
179
+ #### pfs.copy(src, dir[, options])
242
180
 
243
- ### `pfs.chmod(src, mode, options?)`
181
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
182
+ - `dir` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the directory to which the resource is to be copied.
183
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
184
+ - `umask` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> Umask or file [mode creation mask](#mode-creation-mask) is a grouping of bits, each of which restricts how its corresponding permission is set for newly created files or directories. See manuals [umask(2)](http://man7.org/linux/man-pages/man2/umask.2.html). Not supported on Windows system. **Default:** `0o000`.
185
+ - `overwrite` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Replace an existing target before copying. **Default:** `false`.
186
+ - `filter` <[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)> Optional `(src, dest) => boolean` predicate. Return `false` to skip a resource.
187
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
188
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
244
189
 
245
- Recursively applies permissions to a file or directory tree.
190
+ Asynchronously copies a file or directory recursively into `dir`. The destination directory must exist. The created target is `path.join(dir, path.basename(src))`.
246
191
 
247
192
  ```ts
248
- chmod<T extends boolean = false>(
249
- src: string,
250
- mode: number,
251
- options?: { sync?: T }
252
- ): T extends true ? void : Promise<void>
253
- ```
193
+ import { pfs } from 'pwd-fs';
254
194
 
255
- ```ts
256
- await pfs.chmod('./build', 0o755);
195
+ await pfs.mkdir('./dist');
196
+ await pfs.copy('./path/file.txt', './dist');
257
197
  ```
258
198
 
259
- Note: on Windows, permission handling is limited by platform behavior.
199
+ #### pfs.rename(src, dest[, options])
260
200
 
261
- ### `pfs.chown(src, options?)`
201
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
202
+ - `dest` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative destination path in the file system.
203
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
204
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
205
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
262
206
 
263
- Recursively applies ownership to a file or directory tree.
207
+ Rename file or directory. See manuals [rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html).
264
208
 
265
209
  ```ts
266
- chown<T extends boolean = false>(
267
- src: string,
268
- options?: { sync?: T; uid?: number; gid?: number }
269
- ): T extends true ? void : Promise<void>
210
+ await pfs.rename('./path/old_name.txt', './path/new_name.txt');
270
211
  ```
271
212
 
272
- - `uid` and `gid` default to `0`
273
- - when `uid` or `gid` is `0`, the current value from the source entry is preserved
274
- - on Windows, ownership changes are not performed, but path validation still happens
275
-
276
- ### `pfs.symlink(src, dest, options?)`
213
+ #### pfs.remove(src[, options])
277
214
 
278
- Creates a symbolic link from `dest` to `src`.
215
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
216
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
217
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
218
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
279
219
 
280
- ```ts
281
- symlink<T extends boolean = false>(
282
- src: string,
283
- dest: string,
284
- options?: { sync?: T }
285
- ): T extends true ? void : Promise<void>
286
- ```
220
+ Asynchronously removes a file or directory recursively. Missing paths reject or throw, matching `fs.rm(..., { force: false })`.
287
221
 
288
- ```ts
289
- await pfs.symlink('./target.txt', './target-link.txt');
290
- ```
222
+ #### pfs.emptyDir(src[, options])
291
223
 
292
- ### `pfs.copy(src, dest, options?)`
224
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the directory in the file system. Relative paths are resolved against `pfs.pwd`.
225
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
226
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
227
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
293
228
 
294
- Copies `src` into the destination directory.
229
+ Asynchronously removes all entries inside a directory while preserving the directory itself.
295
230
 
296
231
  ```ts
297
- copy<T extends boolean = false>(
298
- src: string,
299
- dest: string,
300
- options?: {
301
- sync?: T;
302
- umask?: number;
303
- overwrite?: boolean;
304
- filter?: (src: string, dest: string) => boolean;
305
- }
306
- ): T extends true ? void : Promise<void>
232
+ await pfs.emptyDir('./cache');
307
233
  ```
308
234
 
309
- Behavior:
235
+ #### pfs.read(src[, options])
310
236
 
311
- - copying a file creates `dest/<basename(src)>`
312
- - copying a directory creates `dest/<basename(src)>` recursively
313
- - the target must not already exist
314
- - `overwrite: true` replaces an existing target entry with the same basename
315
- - `filter()` can skip specific source entries during the copy
316
-
317
- ```ts
318
- await pfs.copy('./assets', './dist');
319
- ```
237
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
238
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
239
+ - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> | <[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
240
+ - `flag` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> See support of [file system flags](#file-system-flags). **Default:** `'r'`.
241
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
242
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with a `string`. If `encoding` is <[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null)>, the data is returned as a <[Buffer](https://nodejs.org/api/buffer.html)> object.
320
243
 
321
- This creates `./dist/assets`, not a direct rename to `./dist`.
244
+ Asynchronously reads the entire contents of a file.
322
245
 
323
246
  ```ts
324
- await pfs.copy('./assets', './dist', {
325
- overwrite: true,
326
- filter: (src) => !src.endsWith('.map')
327
- });
247
+ const content = await pfs.read('./file.txt');
248
+ console.log(content); // 'Lorem Ipsum...'
328
249
  ```
329
250
 
330
- ### `pfs.rename(src, dest, options?)`
331
-
332
- Renames or moves a file system entry.
333
-
334
- ```ts
335
- rename<T extends boolean = false>(
336
- src: string,
337
- dest: string,
338
- options?: { sync?: T }
339
- ): T extends true ? void : Promise<void>
340
- ```
251
+ #### pfs.write(src, data[, options])
341
252
 
342
- ### `pfs.remove(src, options?)`
253
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
254
+ - `data` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> | <[Buffer](https://nodejs.org/api/buffer.html)>
255
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
256
+ - `umask` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> Umask or file [mode creation mask](#mode-creation-mask) is a grouping of bits, each of which restricts how its corresponding permission is set for newly created files or directories. See manuals [umask(2)](http://man7.org/linux/man-pages/man2/umask.2.html). Not supported on Windows system. **Default:** `0o000`.
257
+ - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
258
+ - `flag` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> See support of [file system flags](#file-system-flags). **Default:** `'w'`.
259
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
260
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
343
261
 
344
- Removes a file, directory, or symbolic link.
262
+ Asynchronously writes `data` to a file, replacing the file if it already exists. If the file does not exist, a new file is created.
263
+ The encoding option is ignored if data is a buffer.
345
264
 
346
265
  ```ts
347
- remove<T extends boolean = false>(
348
- src: string,
349
- options?: { sync?: T }
350
- ): T extends true ? void : Promise<void>
266
+ await pfs.write('./file.txt', '... some text');
351
267
  ```
352
268
 
353
- Behavior:
269
+ > For `stream`, `fs.createWriteStream()` is recommended.
354
270
 
355
- - directories are removed recursively
356
- - symbolic links are unlinked without deleting the target
271
+ #### pfs.append(src, data[, options])
357
272
 
358
- ### `pfs.emptyDir(src, options?)`
359
273
 
360
- Removes all entries inside a directory while preserving the directory itself.
274
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
275
+ - `data` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> | <[Buffer](https://nodejs.org/api/buffer.html)>
276
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
277
+ - `umask` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> Umask or file [mode creation mask](#mode-creation-mask) is a grouping of bits, each of which restricts how its corresponding permission is set for newly created files or directories. See manuals [umask(2)](http://man7.org/linux/man-pages/man2/umask.2.html). Not supported on Windows system. **Default:** `0o000`.
278
+ - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
279
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
280
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
361
281
 
362
- ```ts
363
- emptyDir<T extends boolean = false>(
364
- src: string,
365
- options?: { sync?: T }
366
- ): T extends true ? void : Promise<void>
367
- ```
368
-
369
- ```ts
370
- await pfs.emptyDir('./tmp');
371
- ```
282
+ Asynchronously appends data to a file, creating the file if it does not yet exist.
372
283
 
373
- ### `pfs.read(src, options?)`
284
+ > NOTE Method is deprecated. May be removed in the next major version
374
285
 
375
- Reads a file.
286
+ **Use instead [pfs.write(src, data[, options])](#pfswritesrc-data-options) with { flag: 'a' } option**
376
287
 
377
288
  ```ts
378
- read<T extends boolean = false>(
379
- src: string,
380
- options?: {
381
- sync?: T;
382
- encoding?: BufferEncoding | null;
383
- flag?: string;
384
- }
385
- ): T extends true ? string | Buffer : Promise<string | Buffer>
289
+ await pfs.write('./file', 'some content', {
290
+ flag: 'a'
291
+ });
386
292
  ```
387
293
 
388
- - default `encoding`: `'utf8'`
389
- - use `encoding: null` to get a `Buffer`
390
- - default `flag`: `'r'`
391
-
392
- ```ts
393
- const text = await pfs.read('./file.txt');
394
- const buffer = pfs.read('./file.txt', { sync: true, encoding: null });
395
- ```
294
+ #### pfs.readdir(dir[, options])
396
295
 
397
- ### `pfs.write(src, data, options?)`
296
+ - `dir` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the directory you want to read.
297
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
298
+ - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> | <[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
299
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
300
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with an `Array` of file names in the directory excluding `'.'` and `'..'`. If `encoding` is <[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null)>, entries are returned as <[Buffer](https://nodejs.org/api/buffer.html)> objects. Otherwise, entries are strings.
398
301
 
399
- Writes a file and explicitly reapplies the computed mode.
302
+ Asynchronously reads the contents of a directory. Returns an empty `Array` if the directory is empty. See manuals [readdir(3)](http://man7.org/linux/man-pages/man3/readdir.3.html).
400
303
 
401
304
  ```ts
402
- write<T extends boolean = false>(
403
- src: string,
404
- data: Buffer | string,
405
- options?: {
406
- sync?: T;
407
- encoding?: BufferEncoding | null;
408
- umask?: number;
409
- flag?: string;
410
- }
411
- ): T extends true ? void : Promise<void>
305
+ const list = await pfs.readdir('./files');
306
+ console.log(list); // ["icons", "logo.svg"]
412
307
  ```
413
308
 
414
- - default `encoding`: `'utf8'`
415
- - default `umask`: `0o000`
416
- - default `flag`: `'w'`
417
- - use `flag: 'a'` to append
418
- - any valid Node.js string file flag is accepted, such as `'r'`, `'w'`, `'a'`, `'wx'`, or `'a+'`
419
-
420
- ```ts
421
- await pfs.write('./report.txt', 'generated output');
422
- await pfs.write('./report.txt', '\nnext line', { flag: 'a' });
423
- ```
309
+ #### pfs.readlink(src[, options])
424
310
 
425
- ### `pfs.append(src, data, options?)`
311
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the symbolic link in the file system. Relative paths are resolved against `pfs.pwd`.
312
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
313
+ - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
314
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
315
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with a `string`.
426
316
 
427
- Deprecated wrapper around `write(..., { flag: 'a' })`.
317
+ Asynchronously reads the path stored in a symbolic link.
428
318
 
429
319
  ```ts
430
- append<T extends boolean = false>(
431
- src: string,
432
- data: Buffer | string,
433
- options?: {
434
- sync?: T;
435
- encoding?: BufferEncoding | null;
436
- umask?: number;
437
- }
438
- ): T extends true ? void : Promise<void>
320
+ const target = await pfs.readlink('./current');
321
+ console.log(target); // "./releases/current"
439
322
  ```
440
323
 
441
- Prefer:
324
+ #### pfs.realpath(src[, options])
442
325
 
443
- ```ts
444
- await pfs.write('./file.txt', 'content', { flag: 'a' });
445
- ```
446
-
447
- ### `pfs.readdir(dir, options?)`
326
+ - `src` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the resource in the file system. Relative paths are resolved against `pfs.pwd`.
327
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
328
+ - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
329
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
330
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with a `string`.
448
331
 
449
- Reads a directory and returns entry names.
332
+ Asynchronously resolves a path to its canonical absolute location.
450
333
 
451
334
  ```ts
452
- readdir<T extends boolean = false>(
453
- dir: string,
454
- options?: { sync?: T; encoding?: BufferEncoding | null }
455
- ): T extends true ? string[] : Promise<string[]>
335
+ const realpath = await pfs.realpath('./current');
336
+ console.log(realpath); // "/absolute/path/to/releases/current"
456
337
  ```
457
338
 
458
- - default `encoding`: `'utf8'`
339
+ #### pfs.mkdir(dir[, options])
459
340
 
460
- ### `pfs.readlink(src, options?)`
341
+ - `dir` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Absolute or relative path to the directory you want to create.
342
+ - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
343
+ - `umask` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> Umask or file [mode creation mask](#mode-creation-mask) is a grouping of bits, each of which restricts how its corresponding permission is set for newly created files or directories. See manuals [umask(2)](http://man7.org/linux/man-pages/man2/umask.2.html). Not supported on Windows system. **Default:** `0o000`.
344
+ - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
345
+ - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Resolves with `undefined`.
461
346
 
462
- Reads the stored target path from a symbolic link.
347
+ Recursively creates directories. Resolves successfully if the directory already exists.
463
348
 
464
349
  ```ts
465
- readlink<T extends boolean = false>(
466
- src: string,
467
- options?: { sync?: T; encoding?: BufferEncoding }
468
- ): T extends true ? string : Promise<string>
350
+ await pfs.mkdir('./static/images');
469
351
  ```
470
352
 
471
- ### `pfs.realpath(src, options?)`
353
+ #### pfs.pwd
472
354
 
473
- Resolves a path to its canonical absolute location.
355
+ - <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>
474
356
 
475
- ```ts
476
- realpath<T extends boolean = false>(
477
- src: string,
478
- options?: { sync?: T; encoding?: BufferEncoding }
479
- ): T extends true ? string : Promise<string>
480
- ```
357
+ The full path from the root directory to the working directory: in the context of which relative paths will be resolved.
481
358
 
482
- ### `pfs.mkdir(dir, options?)`
359
+ #### static: bitmask(mode)
483
360
 
484
- Creates a directory tree recursively.
361
+ Masking is the act of applying a mask to a value. Bitwise ANDing in order to extract a subset of the bits in the value.
485
362
 
486
363
  ```ts
487
- mkdir<T extends boolean = false>(
488
- dir: string,
489
- options?: { sync?: T; umask?: number }
490
- ): T extends true ? void : Promise<void>
491
- ```
364
+ import { bitmask } from 'pwd-fs';
492
365
 
493
- - existing directories are accepted
494
- - default `umask`: `0o000`
366
+ // Access: (0644/-rw-r--r--)
367
+ const { mode } = await pfs.stat('./things.txt');
368
+ const access = bitmask(mode);
495
369
 
496
- ```ts
497
- await pfs.mkdir('./public/assets/icons');
370
+ console.log(access === 0o644); // true
498
371
  ```
499
372
 
500
- ## Sync Mode
501
-
502
- Every API method supports a synchronous form through `{ sync: true }`.
373
+ Applying the mask to the value means that we want to clear the first (higher) 4 bits, and keep the last (lower) 4 bits. Thus we have extracted the lower 4 bits. The result is:
503
374
 
504
- ```ts
505
- pfs.mkdir('./cache', { sync: true });
506
- pfs.write('./cache/data.json', '{}', { sync: true });
507
- const content = pfs.read('./cache/data.json', { sync: true });
375
+ ```
376
+ mode: 33188
377
+ mask: 0o644 (rw-rw-r--)
508
378
  ```
509
379
 
510
- ## Error Behavior
511
-
512
- Most async methods reject with the underlying Node.js error. Their sync variants throw the same class of error synchronously.
513
-
514
- Typical cases:
515
-
516
- - `test()` is the exception:
517
- it returns `false` for inaccessible or missing paths instead of rejecting or throwing
518
- - `read()`, `stat()`, `readdir()`, `chmod()`, `chown()`, `rename()`, and `remove()` fail for missing paths
519
- - `readlink()` and `realpath()` fail for missing paths
520
- - `read()` fails when the target is a directory
521
- - `readdir()` fails when the target is not a directory
522
- - `emptyDir()` fails when the target is not a directory
523
- - `write()` fails when the target path points to a directory
524
- - `copy()` fails when the source does not exist
525
- - `copy()` fails when the destination already contains an entry with the same basename as the source, unless `overwrite: true` is used
526
- - `copy()` fails when a directory is copied into itself
527
- - `symlink()` fails when the destination already exists
528
- - `mkdir()` accepts an existing directory, but fails when a path segment is a file
529
-
530
- Practical pattern:
531
-
532
- ```ts
533
- if (await pfs.test('./dist')) {
534
- await pfs.remove('./dist');
535
- }
380
+ #### Mode creation mask
536
381
 
537
- await pfs.mkdir('./dist');
538
- ```
382
+ The following table shows some examples of how to set the extension `mode` or `umask` for files and directories.
539
383
 
540
- ## Umask Behavior
384
+ | Umask | Mode files | Mode directories |
385
+ |-------|-------------------|-------------------|
386
+ | 0o000 | 0o666 (rw-rw-rw-) | 0o777 (rwxrwxrwx) |
387
+ | 0o002 | 0o664 (rw-rw-r--) | 0o775 (rwxrwxr-x) |
388
+ | 0o007 | 0o660 (rw-rw----) | 0o770 (rwxrwx---) |
389
+ | 0o022 | 0o644 (rw-r--r--) | 0o755 (rwxr-xr-x) |
390
+ | 0o027 | 0o640 (rw-r-----) | 0o750 (rwxr-x---) |
391
+ | 0o077 | 0o600 (rw-------) | 0o700 (rwx------) |
392
+ | 0o277 | 0o400 (r--------) | 0o500 (r-x------) |
541
393
 
542
- `copy()`, `write()`, and `mkdir()` support `umask`.
394
+ #### String encoding
543
395
 
544
- Effective permissions:
396
+ The following encodings are available wherever the encoding option takes a <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>.
545
397
 
546
- | Umask | File mode | Directory mode |
547
- | --- | --- | --- |
548
- | `0o000` | `0o666` | `0o777` |
549
- | `0o022` | `0o644` | `0o755` |
550
- | `0o027` | `0o640` | `0o750` |
551
- | `0o077` | `0o600` | `0o700` |
398
+ Encoding | Description
399
+ ---------|------------
400
+ `'ascii'` | Each alphabetic, numeric or special character is represented by a 7-bit binary number (a string of seven 0 or 1), which is assigned a number from 0 to 127.
401
+ `'base64'` | Three 8-bit bytes (i.e., a total of 24 bits) can be represented by four 6-bit digits. The full specification of this form is contained in IANA [RFC 1421](https://tools.ietf.org/html/rfc1421) and [RFC 2045](https://tools.ietf.org/html/rfc2045).
402
+ `'hex'` | Encode each byte as two hexadecimal characters.
403
+ `'ucs2'` | 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.
404
+ `'utf16le'` | Like `'ucs2`.
405
+ `'utf8'` | Multibyte encoded Unicode characters. The first 128 characters of Unicode, which correspond one-to-one with `ascii`, are encoded using a single octet with the same binary value as `ascii`, so that valid `ascii` text is valid `utf8`-encoded Unicode as well.
406
+ `'latin1'` | Defined by the IANA in [RFC1345](https://tools.ietf.org/html/rfc1345), only in node 6.4.0+.
407
+ `'binary'` | Like `'latin1`.
552
408
 
553
- ## Notes
409
+ #### File system flags
554
410
 
555
- - Relative paths are resolved against `pfs.pwd`
556
- - Absolute paths are not constrained by `pfs.pwd`
557
- - `stat()` returns `lstat()` data
558
- - `remove()` does not follow symbolic links
559
- - `append()` is kept for backward compatibility and is deprecated
411
+ The following flags are available for `pfs.read` and `pfs.write` the flag option takes a <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>.
560
412
 
561
- ## Platform Caveats
413
+ Flag | Description
414
+ -----|------------
415
+ `'a'` | Open file for appending. The file is created if it does not exist.
416
+ `'ax'` | Like `'a'` but fails if the path exists.
417
+ `'a+'` | Open file for reading and appending. The file is created if it does not exist.
418
+ `'ax+'` | Like `'a+'` but fails if the path exists.
419
+ `'as'` | Open file for appending in synchronous mode. The file is created if it does not exist.
420
+ `'as+'` | Open file for reading and appending in synchronous mode. The file is created if it does not exist.
421
+ `'r'` | Open file for reading. Fails if the file does not exist.
422
+ `'r+'` | Open file for reading and writing. Fails if the file does not exist.
423
+ `'rs+'` | Open file for reading and writing in synchronous mode. Instructs the operating system to bypass the local file system cache. Using this flag is not recommended unless it is needed.
424
+ `'w'`| Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
425
+ `'wx'` | Like `'w'` but fails if the path exists.
426
+ `'w+'` | Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
427
+ `'wx+'` | Like `'w+'` but fails if the path exists.
562
428
 
563
- | Area | Unix-like systems | Windows |
564
- | --- | --- | --- |
565
- | `chmod()` | Recursive permission changes work as expected | Permission handling is limited by platform behavior |
566
- | `chown()` | Recursive ownership changes are applied | Ownership is not changed; only path validation is performed |
567
- | `symlink()` | Link type is inferred by the platform | The implementation resolves the source first and chooses `file` or `junction` explicitly |
568
- | `test(..., { flag: 'x' })` | Uses executable access checks | Does not have the same semantics as Unix execute checks |
569
- | `remove()` on symlinks | Removes the link, not the target | Removes the link, not the target |
429
+ The behavior of some flags is platform-specific.
570
430
 
571
- ## When To Use Native `fs`
431
+ #### When To Use Native `fs`
572
432
 
573
433
  Prefer native `node:fs` APIs directly when you need:
574
434
 
575
435
  - streams such as `createReadStream()` or `createWriteStream()`
576
436
  - advanced flags and options not exposed by this wrapper
577
437
  - very low-level control over file descriptors
578
- - exact parity with Node's callback-based APIs
579
-
580
- ## Development
581
-
582
- ```bash
583
- yarn install --frozen-lockfile
584
- yarn lint
585
- yarn build
586
- yarn test
587
- ```
588
-
589
- ## License
590
-
591
- MIT
438
+ - exact parity with Node's callback-based APIs