pwd-fs 3.2.4 → 3.3.2

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 (101) hide show
  1. package/dist/bitmask.d.ts +4 -0
  2. package/dist/bitmask.js +17 -0
  3. package/dist/bitmask.test.d.ts +1 -0
  4. package/dist/bitmask.test.js +29 -0
  5. package/dist/{src/index.d.ts → index.d.ts} +3 -0
  6. package/dist/{src/index.js → index.js} +3 -0
  7. package/dist/powered-file-system/append.d.ts +9 -0
  8. package/dist/powered-file-system/append.js +10 -0
  9. package/dist/powered-file-system/append.test.d.ts +1 -0
  10. package/dist/powered-file-system/append.test.js +47 -0
  11. package/dist/powered-file-system/chmod.d.ts +7 -0
  12. package/dist/powered-file-system/chmod.js +28 -0
  13. package/dist/powered-file-system/chmod.test.d.ts +1 -0
  14. package/dist/powered-file-system/chmod.test.js +71 -0
  15. package/dist/powered-file-system/chown.d.ts +9 -0
  16. package/dist/powered-file-system/chown.js +45 -0
  17. package/dist/powered-file-system/chown.test.d.ts +1 -0
  18. package/dist/powered-file-system/chown.test.js +82 -0
  19. package/dist/powered-file-system/copy.d.ts +8 -0
  20. package/dist/powered-file-system/copy.js +29 -0
  21. package/dist/powered-file-system/copy.test.d.ts +1 -0
  22. package/dist/powered-file-system/copy.test.js +82 -0
  23. package/dist/powered-file-system/mkdir.d.ts +8 -0
  24. package/dist/powered-file-system/mkdir.js +28 -0
  25. package/dist/powered-file-system/mkdir.test.d.ts +1 -0
  26. package/dist/powered-file-system/mkdir.test.js +116 -0
  27. package/dist/powered-file-system/read.d.ts +9 -0
  28. package/dist/powered-file-system/read.js +29 -0
  29. package/dist/powered-file-system/read.test.d.ts +1 -0
  30. package/dist/powered-file-system/read.test.js +75 -0
  31. package/dist/powered-file-system/readdir.d.ts +8 -0
  32. package/dist/powered-file-system/readdir.js +26 -0
  33. package/dist/powered-file-system/readdir.test.d.ts +1 -0
  34. package/dist/powered-file-system/readdir.test.js +72 -0
  35. package/dist/powered-file-system/remove.d.ts +7 -0
  36. package/dist/powered-file-system/remove.js +36 -0
  37. package/dist/powered-file-system/remove.test.d.ts +1 -0
  38. package/dist/powered-file-system/remove.test.js +78 -0
  39. package/dist/powered-file-system/rename.d.ts +7 -0
  40. package/dist/powered-file-system/rename.js +28 -0
  41. package/dist/powered-file-system/rename.test.d.ts +1 -0
  42. package/dist/powered-file-system/rename.test.js +70 -0
  43. package/dist/powered-file-system/stat.d.ts +7 -0
  44. package/dist/powered-file-system/stat.js +26 -0
  45. package/dist/powered-file-system/stat.test.d.ts +1 -0
  46. package/dist/powered-file-system/stat.test.js +79 -0
  47. package/dist/powered-file-system/symlink.d.ts +4 -0
  48. package/dist/powered-file-system/symlink.js +52 -0
  49. package/dist/powered-file-system/symlink.test.d.ts +1 -0
  50. package/dist/powered-file-system/symlink.test.js +77 -0
  51. package/dist/powered-file-system/test.d.ts +8 -0
  52. package/dist/powered-file-system/test.js +30 -0
  53. package/dist/powered-file-system/test.test.d.ts +1 -0
  54. package/dist/powered-file-system/test.test.js +76 -0
  55. package/dist/powered-file-system/write.d.ts +10 -0
  56. package/dist/powered-file-system/write.js +36 -0
  57. package/dist/powered-file-system/write.test.d.ts +1 -0
  58. package/dist/powered-file-system/write.test.js +97 -0
  59. package/dist/powered-file-system.d.ts +127 -0
  60. package/dist/powered-file-system.js +144 -0
  61. package/dist/powered-file-system.test.d.ts +1 -0
  62. package/dist/powered-file-system.test.js +21 -0
  63. package/dist/recurse-io-sync.d.ts +20 -0
  64. package/dist/{src/recurse-io-sync.js → recurse-io-sync.js} +37 -37
  65. package/dist/{src/recurse-io.d.ts → recurse-io.d.ts} +15 -1
  66. package/dist/{src/recurse-io.js → recurse-io.js} +52 -58
  67. package/dist/suite.test.d.ts +1 -0
  68. package/dist/suite.test.js +40 -0
  69. package/dist/test-utils.d.ts +18 -0
  70. package/dist/test-utils.js +72 -0
  71. package/package.json +31 -14
  72. package/readme.md +331 -246
  73. package/.travis.yml +0 -12
  74. package/appveyor.yml +0 -16
  75. package/dist/src/bitmask.d.ts +0 -1
  76. package/dist/src/bitmask.js +0 -18
  77. package/dist/src/powered-file-system.d.ts +0 -173
  78. package/dist/src/powered-file-system.js +0 -262
  79. package/dist/src/recurse-io-sync.d.ts +0 -5
  80. package/src/bitmask.ts +0 -20
  81. package/src/index.ts +0 -7
  82. package/src/powered-file-system.ts +0 -508
  83. package/src/recurse-io-sync.ts +0 -108
  84. package/src/recurse-io.ts +0 -238
  85. package/test/__fmock.ts +0 -45
  86. package/test/append.spec.ts +0 -71
  87. package/test/bitmask.spec.ts +0 -23
  88. package/test/chmod.spec.ts +0 -77
  89. package/test/chown.spec.ts +0 -92
  90. package/test/constructor.spec.ts +0 -15
  91. package/test/copy.spec.ts +0 -101
  92. package/test/mkdir.spec.ts +0 -121
  93. package/test/read.spec.ts +0 -91
  94. package/test/readdir.spec.ts +0 -86
  95. package/test/remove.spec.ts +0 -78
  96. package/test/rename.spec.ts +0 -84
  97. package/test/stat.spec.ts +0 -99
  98. package/test/symlink.spec.ts +0 -95
  99. package/test/test.spec.ts +0 -80
  100. package/test/write.spec.ts +0 -104
  101. package/tsconfig.json +0 -14
package/readme.md CHANGED
@@ -1,385 +1,470 @@
1
- # Powered File System
1
+ # pwd-fs
2
2
 
3
- [![License](https://img.shields.io/npm/l/express.svg)](https://github.com/woodger/pwd-fs/blob/master/LICENSE)
4
- [![Build Status](https://travis-ci.org/woodger/pwd-fs.svg?branch=master)](https://travis-ci.org/woodger/pwd-fs)
5
- [![Build status](https://ci.appveyor.com/api/projects/status/dn30qhwxe845kpxe?svg=true)](https://ci.appveyor.com/project/woodger/pwd-fs)
6
- [![Coverage Status](https://coveralls.io/repos/github/woodger/pwd-fs/badge.svg)](https://coveralls.io/github/woodger/pwd-fs)
7
- [![Known Vulnerabilities](https://snyk.io/test/github/woodger/type-enforcement/badge.svg?targetFile=package.json)](https://snyk.io/test/github/woodger/type-enforcement?targetFile=package.json)
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)
8
5
 
9
- [![npm](https://nodei.co/npm/pwd-fs.png)](https://www.npmjs.com/package/pwd-fs)
6
+ `pwd-fs` is a path-aware wrapper around Node.js file system APIs.
10
7
 
11
- This module expands the [Node.js®](https://nodejs.org) module with the capabilities of declaring the `pwd` (present working directory) and `recursive` execution. By default all file system operations have asynchronous forms. API provides an alternative set of asynchronous file system methods that return `Promise` objects.
8
+ It provides:
12
9
 
13
- To improve reliability and maintainability the code is migrated to [TypeScript](https://www.typescriptlang.org).
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
14
14
 
15
- ## Getting Started
15
+ All relative paths are resolved against `pfs.pwd`.
16
16
 
17
- ### Installation
17
+ ## Why Use It
18
18
 
19
- To use `Powered File System` in your project, run:
19
+ Use `pwd-fs` when you want file system operations to be scoped to 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
20
29
 
21
30
  ```bash
22
31
  npm install pwd-fs
23
32
  ```
24
33
 
25
- #### Table of Contents
34
+ ## Quick Start
26
35
 
27
- [class PoweredFileSystem](#class-poweredfilesystem)
36
+ ```ts
37
+ import { pfs } from 'pwd-fs';
28
38
 
29
- * [constructor: new PoweredFileSystem([path])](#constructor-new-poweredfilesystempath)
30
- * [pfs.test(src[, options])](#pfstestsrc-options)
31
- * [pfs.stat(src[, options])](#pfsstatsrc-options)
32
- * [pfs.chmod(src, mode[, options])](#pfschmodsrc-mode-options)
33
- * [pfs.chown(src, uid, gid[, options])](#pfschownsrc-uid-gid-options)
34
- * [pfs.symlink(src, use[, options])](#pfssymlinksrc-use-options)
35
- * [pfs.copy(src, dir[, options])](#pfscopysrc-dir-options)
36
- * [pfs.rename(src, use[, options])](#pfsrenamesrc-use-options)
37
- * [pfs.remove(src[, options])](#pfsremovesrc-options)
38
- * [pfs.read(src[, options])](#pfsreadsrc-options)
39
- * [pfs.write(src, data[, options])](#pfswritesrc-data-options)
40
- * [pfs.readdir(dir[, options])](#pfsreaddirdir-options)
41
- * [pfs.mkdir(dir[, options])](#pfsmkdirdir-options)
42
- * [pfs.pwd](#pfspwd)
43
- * [static: bitmask(mode)](#static-bitmaskmode)
39
+ await pfs.mkdir('./own/project'); // recursively create the directory
40
+ ```
44
41
 
45
- The scope `URI` of the class methods are divided into groups.
42
+ ## Common Recipes
46
43
 
47
- | URI | Methods |
48
- |-----------------------------|------------------------------------------------------------------|
49
- | Common (file and directory) | `chmod` `chown` `copy` `remove` `rename` `symlink` `stat` `test` |
50
- | File only | `read` `write` |
51
- | Directory only | `mkdir` `readdir` |
44
+ ### Work inside a scoped directory
52
45
 
46
+ ```ts
47
+ import { PoweredFileSystem } from 'pwd-fs';
53
48
 
54
- #### class PoweredFileSystem
49
+ const projectFs = new PoweredFileSystem('/workspace/my-project');
55
50
 
56
- This class implemented by following the [ECMAScript® 2018 Language Specification
57
- ](https://www.ecma-international.org/ecma-262/9.0/index.html) Standard.
51
+ await projectFs.write('./.cache/build.txt', 'ok');
52
+ const exists = await projectFs.test('./.cache/build.txt');
53
+ ```
58
54
 
59
- #### constructor: new PoweredFileSystem([path])
55
+ ### Copy assets into a build directory
60
56
 
61
- - `path` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> absolute or relative dirname. `path` sets `pfs.pwd` value, by default [process.cwd()](https://nodejs.org/api/process.html#process_process_cwd).
57
+ ```ts
58
+ await pfs.mkdir('./dist');
59
+ await pfs.copy('./assets', './dist');
60
+ ```
62
61
 
63
- String form paths are interpreted as UTF-8 character sequences identifying the absolute or relative filename.
62
+ Result:
64
63
 
65
- ```ts
66
- import { pfs } from 'pwd-fs';
64
+ - source: `./assets`
65
+ - destination directory: `./dist`
66
+ - created output: `./dist/assets`
67
67
 
68
- // pfs.pwd === process.cwd()
68
+ ### Append to a file
69
+
70
+ ```ts
71
+ await pfs.write('./app.log', 'first line\n');
72
+ await pfs.write('./app.log', 'second line\n', { flag: 'a' });
69
73
  ```
70
74
 
71
- Relative paths will be resolved relative to the current working directory as specified by `process.cwd()`:
75
+ ### Read a file as a buffer
72
76
 
73
77
  ```ts
74
- import { PoweredFileSystem } from 'pwd-fs';
78
+ const raw = await pfs.read('./archive.bin', { encoding: null });
79
+ ```
75
80
 
76
- // pfs.pwd === `${process.cwd()}/foo/bar`
81
+ ### Remove a temporary directory recursively
77
82
 
78
- const pfs = new PoweredFileSystem('./foo/bar');
83
+ ```ts
84
+ if (await pfs.test('./tmp')) {
85
+ await pfs.remove('./tmp');
86
+ }
79
87
  ```
80
88
 
81
- Absolute paths:
89
+ ## Compatibility
82
90
 
83
- ```ts
84
- import { PoweredFileSystem } from 'pwd-fs';
91
+ - package `engines`: Node.js `>=13.2.0`
92
+ - module format: CommonJS package output with TypeScript declarations
93
+ - platform notes:
94
+ - `chown()` is effectively a no-op on Windows apart from path validation
95
+ - `chmod()` behavior on Windows is limited by the platform
96
+ - `x` access checks in `test()` do not have the same meaning on Windows as on Unix-like systems
85
97
 
86
- // pfs.pwd === __dirname
98
+ ## Exports
87
99
 
88
- const pfs = new PoweredFileSystem(__dirname);
100
+ ```ts
101
+ import PoweredFileSystem, { pfs, bitmask } from 'pwd-fs';
89
102
  ```
90
103
 
91
- #### pfs.test(src[, options])
104
+ - `default`: `PoweredFileSystem`
105
+ - `pfs`: default instance rooted at `process.cwd()`
106
+ - `bitmask(mode)`: helper that extracts standard permission bits from `fs.Stats.mode`
107
+
108
+ ## API
92
109
 
93
- - `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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
94
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
95
- - `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'`.
96
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
97
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful read, the `Promise` is resolved with an value with a `boolean`.
110
+ ### `new PoweredFileSystem(pwd?)`
98
111
 
99
- Tests a user's permissions for the file or directory specified by path.
112
+ Creates a new instance rooted at `pwd`.
113
+
114
+ - `pwd?: string`
115
+ - default: `process.cwd()`
100
116
 
101
117
  ```ts
102
- const access = await pfs.test('./path');
103
- console.log(test); // true
104
- ```
105
- > Function `pfs.test()` return only `Promise.resolve()`
118
+ import { PoweredFileSystem } from 'pwd-fs';
106
119
 
107
- The following `flag` are meant for use with `pfs.test()`.
120
+ const pfs = new PoweredFileSystem('./workspace');
121
+ ```
108
122
 
109
- Flag | Description
110
- -----|-------------
111
- `'e'` | Source is visible
112
- `'r'` | Permitted can be read
113
- `'w'` | Permitted can be written
114
- `'x'` | Permitted can be executed. This has no effect on Windows system (will behave like `e`).
123
+ ### `pfs.pwd`
115
124
 
116
- #### pfs.stat(src[, options])
125
+ Absolute base directory used to resolve all relative paths.
117
126
 
118
- - `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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
119
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
120
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
121
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful read, the `Promise` is resolved with an value with a `fs.Stats`.
127
+ ### `pfs.constants`
122
128
 
123
- These functions return information about a resource in the file system.
129
+ Access mode aliases used by `pfs.test()`:
124
130
 
125
- #### pfs.chmod(src, mode[, options])
131
+ - `e`: existence
132
+ - `r`: readable
133
+ - `w`: writable
134
+ - `x`: executable
126
135
 
127
- - `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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
128
- - `mode` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> Is a numeric `bitmask` created using a logical `OR`.
129
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
130
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
131
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful change, the `Promise` is resolved with an value with a `undefined`.
136
+ ### `PoweredFileSystem.bitmask(mode)`
132
137
 
133
- Asynchronously changes the permissions of a file.
138
+ Static alias for `bitmask(mode)`.
134
139
 
135
140
  ```ts
136
- import { bitmask } from 'pwd-fs';
141
+ const { mode } = await pfs.stat('./file.txt');
142
+ const permissions = PoweredFileSystem.bitmask(mode);
143
+ ```
137
144
 
138
- await pfs.chmod('./path', 0o750);
139
- const { mode } = await pfs.stat('./path');
145
+ ### `pfs.test(src, options?)`
140
146
 
141
- console.log(bitmask(mode) === 0o750); // true
147
+ Checks whether a path is accessible.
148
+
149
+ ```ts
150
+ test<T extends boolean = false>(
151
+ src: string,
152
+ options?: { sync?: T; flag?: 'e' | 'r' | 'w' | 'x' }
153
+ ): T extends true ? boolean : Promise<boolean>
142
154
  ```
143
155
 
144
- > **Caveats:** on Windows only the write permission can be changed, and the distinction among the permissions of group, owner or others is not implemented.
156
+ - `src`: absolute or instance-relative path
157
+ - `flag`: access check to perform
158
+ - default flag: `'e'`
145
159
 
146
- See manuals [chmod(2)](http://man7.org/linux/man-pages/man2/chmod.2.html)
160
+ ```ts
161
+ const exists = await pfs.test('./notes.txt');
162
+ const writable = pfs.test('./notes.txt', { sync: true, flag: 'w' });
163
+ ```
147
164
 
148
- #### pfs.chown(src, [, options])
165
+ ### `pfs.stat(src, options?)`
149
166
 
150
- - `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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
151
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
152
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
153
- - `uid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> The file's new owner's user id.
154
- - `gid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> The file's new group's group id.
155
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful change, the `Promise` is resolved with an value with a `undefined`.
167
+ Returns `fs.lstat()` information for a path.
156
168
 
157
- Asynchronously changes owner and group of a file.
158
- See manuals [chown(2)](http://man7.org/linux/man-pages/man2/chown.2.html).
169
+ ```ts
170
+ stat<T extends boolean = false>(
171
+ src: string,
172
+ options?: { sync?: T }
173
+ ): T extends true ? Stats : Promise<Stats>
174
+ ```
159
175
 
160
- #### pfs.symlink(src, use[, options])
176
+ This method uses `lstat`, so symbolic links are reported as links instead of followed targets.
161
177
 
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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
163
- - `use` <[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. If `use` 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)> Following successful created link, the `Promise` is resolved with an value with a `undefined`.
178
+ ### `pfs.chmod(src, mode, options?)`
167
179
 
168
- Asynchronously creates a new symbolic link (also known as a soft link) may point to an existing file or to a nonexistent one.
180
+ Recursively applies permissions to a file or directory tree.
169
181
 
170
182
  ```ts
171
- await pfs.symlink('./path', './link');
172
- const stats = await pfs.stat('./link');
173
-
174
- console.log(stats.isSymbolicLink()); // true
183
+ chmod<T extends boolean = false>(
184
+ src: string,
185
+ mode: number,
186
+ options?: { sync?: T }
187
+ ): T extends true ? void : Promise<void>
175
188
  ```
176
189
 
177
- See manuals [symlink(2)](http://man7.org/linux/man-pages/man2/symlink.2.html).
190
+ ```ts
191
+ await pfs.chmod('./build', 0o755);
192
+ ```
178
193
 
179
- #### pfs.copy(src, dir[, options])
194
+ Note: on Windows, permission handling is limited by platform behavior.
180
195
 
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 will be resolved relative to the present working directory as specified by `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
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
186
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful copied, the `Promise` is resolved with an value with a `undefined`.
196
+ ### `pfs.chown(src, options?)`
187
197
 
188
- Asynchronously recursively copy a file or directory.
198
+ Recursively applies ownership to a file or directory tree.
189
199
 
190
200
  ```ts
191
- import { pfs } from 'pwd-fs';
192
-
193
- await pfs.copy('./path/file.txt', './dist');
201
+ chown<T extends boolean = false>(
202
+ src: string,
203
+ options?: { sync?: T; uid?: number; gid?: number }
204
+ ): T extends true ? void : Promise<void>
194
205
  ```
195
206
 
196
- #### pfs.rename(src, use[, options])
207
+ - `uid` and `gid` default to `0`
208
+ - when `uid` or `gid` is `0`, the current value from the source entry is preserved
209
+ - on Windows, ownership changes are not performed, but path validation still happens
197
210
 
198
- - `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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
199
- - `use` <[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.
200
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
201
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
202
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful renamed, the `Promise` is resolved with an value with a `undefined`.
211
+ ### `pfs.symlink(src, dest, options?)`
203
212
 
204
- Rename file or directory. See manuals [rename(2)](http://man7.org/linux/man-pages/man2/rename.2.html).
213
+ Creates a symbolic link from `dest` to `src`.
205
214
 
206
215
  ```ts
207
- await pfs.rename('./path/old_name.txt', './path/new_name.txt');
216
+ symlink<T extends boolean = false>(
217
+ src: string,
218
+ dest: string,
219
+ options?: { sync?: T }
220
+ ): T extends true ? void : Promise<void>
208
221
  ```
209
222
 
210
- #### pfs.remove(src[, options])
223
+ ```ts
224
+ await pfs.symlink('./target.txt', './target-link.txt');
225
+ ```
211
226
 
212
- - `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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
213
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
214
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
215
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful removed, the `Promise` is resolved with an value with a `undefined`.
227
+ ### `pfs.copy(src, dest, options?)`
216
228
 
217
- Asynchronously recursively remove a file or directory. Will be `resolve` if the directory already not exists.
229
+ Copies `src` into the destination directory.
218
230
 
219
- #### pfs.read(src[, options])]
231
+ ```ts
232
+ copy<T extends boolean = false>(
233
+ src: string,
234
+ dest: string,
235
+ options?: { sync?: T; umask?: number }
236
+ ): T extends true ? void : Promise<void>
237
+ ```
220
238
 
221
- - `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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
222
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
223
- - `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'`.
224
- - `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'`.
225
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
226
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful read, the `Promise` is resolved with an value with a `string`. If no encoding is specified <[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.
239
+ Behavior:
227
240
 
228
- Asynchronously reads the entire contents of a file.
241
+ - copying a file creates `dest/<basename(src)>`
242
+ - copying a directory creates `dest/<basename(src)>` recursively
243
+ - the target must not already exist
229
244
 
230
245
  ```ts
231
- const content = await pfs.read('./file.txt');
232
- console.log(content); // 'Lorem Ipsum...'
246
+ await pfs.copy('./assets', './dist');
233
247
  ```
234
248
 
235
- #### pfs.write(src, data[, options])
249
+ This creates `./dist/assets`, not a direct rename to `./dist`.
236
250
 
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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
238
- - `data` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>
239
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
240
- - `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`.
241
- - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
242
- - `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'`.
243
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
244
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful write, the `Promise` is resolved with an value with a `undefined`.
251
+ ### `pfs.rename(src, dest, options?)`
245
252
 
246
- Asynchronously writes `data` to a file, replacing the file if it already exists. if the file does not exist, it will create a new one.
247
- The encoding option is ignored if data is a buffer.
253
+ Renames or moves a file system entry.
248
254
 
249
255
  ```ts
250
- await pfs.write('./file.txt', '... some text');
256
+ rename<T extends boolean = false>(
257
+ src: string,
258
+ dest: string,
259
+ options?: { sync?: T }
260
+ ): T extends true ? void : Promise<void>
251
261
  ```
252
262
 
253
- > This function is limited to writing only `string`. For `stream`, `fs.createWriteStream()` is recommended.
263
+ ### `pfs.remove(src, options?)`
254
264
 
255
- #### pfs.append(src, data[, options]) `deprecated`
265
+ Removes a file, directory, or symbolic link.
256
266
 
267
+ ```ts
268
+ remove<T extends boolean = false>(
269
+ src: string,
270
+ options?: { sync?: T }
271
+ ): T extends true ? void : Promise<void>
272
+ ```
257
273
 
258
- - `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 will be resolved relative to the present working directory as specified by `pfs.pwd`.
259
- - `data` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>
260
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
261
- - `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`.
262
- - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
263
- - `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:** `'a'`.
264
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
265
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful write, the `Promise` is resolved with an value with a `undefined`.
274
+ Behavior:
266
275
 
267
- Asynchronously append data to a file, creating the file if it does not yet exist.
276
+ - directories are removed recursively
277
+ - symbolic links are unlinked without deleting the target
268
278
 
269
- > NOTE Method is deprecated. May be removed in the next major version
279
+ ### `pfs.read(src, options?)`
270
280
 
271
- **Use instead [pfs.write(src, data[, options])](#pfswritesrc-data-options) with { flag: 'a' } option**
281
+ Reads a file.
272
282
 
273
283
  ```ts
274
- await pfs.write('./file', 'some content', {
275
- flag: 'a'
276
- });
284
+ read<T extends boolean = false>(
285
+ src: string,
286
+ options?: {
287
+ sync?: T;
288
+ encoding?: BufferEncoding | null;
289
+ flag?: string;
290
+ }
291
+ ): T extends true ? string | Buffer : Promise<string | Buffer>
277
292
  ```
278
293
 
279
- #### pfs.readdir(dir[, options]
294
+ - default `encoding`: `'utf8'`
295
+ - use `encoding: null` to get a `Buffer`
296
+ - default `flag`: `'r'`
280
297
 
281
- - `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.
282
- - `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
283
- - `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'`.
284
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
285
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful write, the `Promise` is resolved with an value with a `Array` of the names of the files in the directory excluding `'.'` and `'..'`. If no encoding is specified <[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. Otherwise, the data will be a string.
298
+ ```ts
299
+ const text = await pfs.read('./file.txt');
300
+ const buffer = pfs.read('./file.txt', { sync: true, encoding: null });
301
+ ```
286
302
 
287
- Asynchronous reads the contents of a directory. The Gets an <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)> of the names of the files in the directory excluding `'.'` and `'..'`. Returns an empty `Array` if the directory is empty. See manuals [readdir(3)](http://man7.org/linux/man-pages/man3/readdir.3.html).
303
+ ### `pfs.write(src, data, options?)`
304
+
305
+ Writes a file and explicitly reapplies the computed mode.
288
306
 
289
307
  ```ts
290
- const list = await pfs.readdir('./files');
291
- console.log(list); // ["icons", "logo.svg"]
308
+ write<T extends boolean = false>(
309
+ src: string,
310
+ data: Buffer | string,
311
+ options?: {
312
+ sync?: T;
313
+ encoding?: BufferEncoding | null;
314
+ umask?: number;
315
+ flag?: string;
316
+ }
317
+ ): T extends true ? void : Promise<void>
292
318
  ```
293
319
 
294
- #### pfs.mkdir(dir[, options])
320
+ - default `encoding`: `'utf8'`
321
+ - default `umask`: `0o000`
322
+ - default `flag`: `'w'`
323
+ - use `flag: 'a'` to append
324
+ - any valid Node.js string file flag is accepted, such as `'r'`, `'w'`, `'a'`, `'wx'`, or `'a+'`
295
325
 
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
- - `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`.
299
- - `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
300
- - `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
301
- - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)> Following successful execution, the `Promise` is resolved with an value with a `undefined`.
326
+ ```ts
327
+ await pfs.write('./report.txt', 'generated output');
328
+ await pfs.write('./report.txt', '\nnext line', { flag: 'a' });
329
+ ```
330
+
331
+ ### `pfs.append(src, data, options?)`
302
332
 
303
- Recursive directory creation. Will be `resolve` if the directory already exists.
333
+ Deprecated wrapper around `write(..., { flag: 'a' })`.
304
334
 
305
335
  ```ts
306
- await pfs.mkdir('./static/images');
336
+ append<T extends boolean = false>(
337
+ src: string,
338
+ data: Buffer | string,
339
+ options?: {
340
+ sync?: T;
341
+ encoding?: BufferEncoding | null;
342
+ umask?: number;
343
+ }
344
+ ): T extends true ? void : Promise<void>
307
345
  ```
308
346
 
309
- #### pfs.pwd
347
+ Prefer:
348
+
349
+ ```ts
350
+ await pfs.write('./file.txt', 'content', { flag: 'a' });
351
+ ```
310
352
 
311
- - <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>
353
+ ### `pfs.readdir(dir, options?)`
354
+
355
+ Reads a directory and returns entry names.
356
+
357
+ ```ts
358
+ readdir<T extends boolean = false>(
359
+ dir: string,
360
+ options?: { sync?: T; encoding?: BufferEncoding | null }
361
+ ): T extends true ? string[] : Promise<string[]>
362
+ ```
312
363
 
313
- The full path from the root directory to the present working directory: in the context of which relative paths will be resolved.
364
+ - default `encoding`: `'utf8'`
314
365
 
315
- #### static: bitmask(mode)
366
+ ### `pfs.mkdir(dir, options?)`
316
367
 
317
- 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.
368
+ Creates a directory tree recursively.
318
369
 
319
370
  ```ts
320
- import { bitmask } from 'pwd-fs';
371
+ mkdir<T extends boolean = false>(
372
+ dir: string,
373
+ options?: { sync?: T; umask?: number }
374
+ ): T extends true ? void : Promise<void>
375
+ ```
321
376
 
322
- // Access: (0644/-rw-r--r--)
323
- const { mode } = await pfs.stat('./things.txt');
324
- const access = bitmask(mode);
377
+ - existing directories are accepted
378
+ - default `umask`: `0o000`
325
379
 
326
- console.log(access === 0o644); // true
380
+ ```ts
381
+ await pfs.mkdir('./public/assets/icons');
327
382
  ```
328
383
 
329
- 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:
384
+ ## Sync Mode
385
+
386
+ Every API method supports a synchronous form through `{ sync: true }`.
330
387
 
388
+ ```ts
389
+ pfs.mkdir('./cache', { sync: true });
390
+ pfs.write('./cache/data.json', '{}', { sync: true });
391
+ const content = pfs.read('./cache/data.json', { sync: true });
331
392
  ```
332
- mode: 33188
333
- mask: 0o644 (rw-rw-r--)
393
+
394
+ ## Error Behavior
395
+
396
+ Most async methods reject with the underlying Node.js error. Their sync variants throw the same class of error synchronously.
397
+
398
+ Typical cases:
399
+
400
+ - `test()` is the exception:
401
+ it returns `false` for inaccessible or missing paths instead of rejecting or throwing
402
+ - `read()`, `stat()`, `readdir()`, `chmod()`, `chown()`, `rename()`, and `remove()` fail for missing paths
403
+ - `read()` fails when the target is a directory
404
+ - `readdir()` fails when the target is not a directory
405
+ - `write()` fails when the target path points to a directory
406
+ - `copy()` fails when the source does not exist
407
+ - `copy()` also fails when the destination already contains an entry with the same basename as the source
408
+ - `symlink()` fails when the destination already exists
409
+ - `mkdir()` accepts an existing directory, but fails when a path segment is a file
410
+
411
+ Practical pattern:
412
+
413
+ ```ts
414
+ if (await pfs.test('./dist')) {
415
+ await pfs.remove('./dist');
416
+ }
417
+
418
+ await pfs.mkdir('./dist');
334
419
  ```
335
420
 
336
- #### Mode creation mask
421
+ ## Umask Behavior
422
+
423
+ `copy()`, `write()`, and `mkdir()` support `umask`.
424
+
425
+ Effective permissions:
426
+
427
+ | Umask | File mode | Directory mode |
428
+ | --- | --- | --- |
429
+ | `0o000` | `0o666` | `0o777` |
430
+ | `0o022` | `0o644` | `0o755` |
431
+ | `0o027` | `0o640` | `0o750` |
432
+ | `0o077` | `0o600` | `0o700` |
337
433
 
338
- The following table shows some examples of how to set the extension `mode` or `umask` for files and directories.
434
+ ## Notes
339
435
 
340
- | Umask | Mode files | Mode directories |
341
- |-------|-------------------|-------------------|
342
- | 0o000 | 0o666 (rw-rw-rw-) | 0o777 (rwxrwxrwx) |
343
- | 0o002 | 0o664 (rw-rw-r--) | 0o775 (rwxrwxr-x) |
344
- | 0o007 | 0o660 (rw-rw----) | 0o770 (rwxrwx---) |
345
- | 0o022 | 0o644 (rw-r--r--) | 0o755 (rwxr-xr-x) |
346
- | 0o027 | 0o640 (rw-r-----) | 0o750 (rwxr-x---) |
347
- | 0o077 | 0o600 (rw-------) | 0o700 (rwx------) |
348
- | 0o277 | 0o400 (r--------) | 0o500 (r-x------) |
436
+ - Relative paths are always resolved against `pfs.pwd`
437
+ - `stat()` returns `lstat()` data
438
+ - `remove()` does not follow symbolic links
439
+ - `append()` is kept for backward compatibility and is deprecated
349
440
 
350
- #### String encoding
441
+ ## Platform Caveats
351
442
 
352
- The following encoding are available wherever the encoding option takes a <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>.
443
+ | Area | Unix-like systems | Windows |
444
+ | --- | --- | --- |
445
+ | `chmod()` | Recursive permission changes work as expected | Permission handling is limited by platform behavior |
446
+ | `chown()` | Recursive ownership changes are applied | Ownership is not changed; only path validation is performed |
447
+ | `symlink()` | Link type is inferred by the platform | The implementation resolves the source first and chooses `file` or `junction` explicitly |
448
+ | `test(..., { flag: 'x' })` | Uses executable access checks | Does not have the same semantics as Unix execute checks |
449
+ | `remove()` on symlinks | Removes the link, not the target | Removes the link, not the target |
353
450
 
354
- Encoding | Description
355
- ---------|------------
356
- `'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.
357
- `'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).
358
- `'hex'` | Encode each byte as two hexadecimal characters.
359
- `'ucs2` | 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.
360
- `'utf16le'` | Like `'ucs2`.
361
- `'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.
362
- `'latin1'` | Defined by the IANA in [RFC1345](https://tools.ietf.org/html/rfc1345), only in node 6.4.0+.
363
- `'binary'` | Like `'latin1`.
451
+ ## When To Use Native `fs`
364
452
 
365
- #### File system flags
453
+ Prefer native `node:fs` APIs directly when you need:
366
454
 
367
- 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)>.
455
+ - streams such as `createReadStream()` or `createWriteStream()`
456
+ - advanced flags and options not exposed by this wrapper
457
+ - very low-level control over file descriptors
458
+ - exact parity with Node's callback-based APIs
459
+
460
+ ## Development
461
+
462
+ ```bash
463
+ npm install
464
+ npm run build
465
+ npm test
466
+ ```
368
467
 
369
- Flag | Description
370
- -----|------------
371
- `'a'` | Open file for appending. The file is created if it does not exist.
372
- `'ax'` | Like `'a'` but fails if the path exists.
373
- `'a+'` | Open file for reading and appending. The file is created if it does not exist.
374
- `'ax+'` | Like `'a+'` but fails if the path exists.
375
- `'as'` | Open file for appending in synchronous mode. The file is created if it does not exist.
376
- `'as+'` | Open file for reading and appending in synchronous mode. The file is created if it does not exist.
377
- `'r'` | Open file for reading. An exception occurs if the file does not exist.
378
- `'r+'` | Open file for reading and writing. An exception occurs if the file does not exist.
379
- `'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.
380
- `'w'`| Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
381
- `'wx'` | Like `'w'` but fails if the path exists.
382
- `'w+'` | Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
383
- `'wx+'` | Like `'w+'` but fails if the path exists.
468
+ ## License
384
469
 
385
- The behavior of some flags are platform-specific.
470
+ MIT