pwd-fs 2.4.2 → 3.1.4
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.
- package/.travis.yml +2 -3
- package/appveyor.yml +2 -4
- package/lib/src/index.d.ts +4 -186
- package/lib/src/index.js +18 -294
- package/lib/src/powered-file-system.d.ts +156 -0
- package/lib/src/powered-file-system.js +264 -0
- package/lib/src/recurse-io-sync.d.ts +10 -5
- package/lib/src/recurse-io-sync.js +74 -69
- package/lib/src/recurse-io.d.ts +14 -6
- package/lib/src/recurse-io.js +164 -160
- package/lib/test/__fmock.d.ts +5 -0
- package/lib/test/__fmock.js +40 -0
- package/lib/test/append.spec.js +36 -77
- package/lib/test/bitmask.spec.js +14 -17
- package/lib/test/chmod.spec.js +42 -84
- package/lib/test/chown.spec.js +45 -71
- package/lib/test/constructor.spec.js +7 -10
- package/lib/test/copy.spec.js +53 -108
- package/lib/test/mkdir.spec.js +62 -119
- package/lib/test/read.spec.js +47 -78
- package/lib/test/readdir.spec.js +48 -90
- package/lib/test/remove.spec.js +44 -65
- package/lib/test/rename.spec.js +43 -75
- package/lib/test/stat.spec.js +50 -78
- package/lib/test/symlink.spec.js +51 -95
- package/lib/test/test.spec.js +37 -66
- package/lib/test/write.spec.js +52 -103
- package/package.json +8 -11
- package/readme.md +10 -21
- package/src/index.ts +4 -623
- package/src/powered-file-system.ts +527 -0
- package/src/recurse-io-sync.ts +77 -71
- package/src/recurse-io.ts +181 -176
- package/test/__fmock.ts +45 -0
- package/test/append.spec.ts +44 -98
- package/test/bitmask.spec.ts +14 -17
- package/test/chmod.spec.ts +45 -95
- package/test/chown.spec.ts +61 -93
- package/test/constructor.spec.ts +4 -7
- package/test/copy.spec.ts +72 -142
- package/test/mkdir.spec.ts +87 -153
- package/test/read.spec.ts +64 -103
- package/test/readdir.spec.ts +65 -113
- package/test/remove.spec.ts +58 -82
- package/test/rename.spec.ts +58 -96
- package/test/stat.spec.ts +68 -100
- package/test/symlink.spec.ts +74 -125
- package/test/test.spec.ts +51 -84
- package/test/write.spec.ts +68 -131
- package/tsconfig.json +14 -7
- package/lib/src/index.js.map +0 -1
- package/lib/src/recurse-io-sync.js.map +0 -1
- package/lib/src/recurse-io.js.map +0 -1
- package/lib/test/append.spec.js.map +0 -1
- package/lib/test/bitmask.spec.js.map +0 -1
- package/lib/test/chmod.spec.js.map +0 -1
- package/lib/test/chown.spec.js.map +0 -1
- package/lib/test/constructor.spec.js.map +0 -1
- package/lib/test/copy.spec.js.map +0 -1
- package/lib/test/mkdir.spec.js.map +0 -1
- package/lib/test/read.spec.js.map +0 -1
- package/lib/test/readdir.spec.js.map +0 -1
- package/lib/test/remove.spec.js.map +0 -1
- package/lib/test/rename.spec.js.map +0 -1
- package/lib/test/stat.spec.js.map +0 -1
- package/lib/test/symlink.spec.js.map +0 -1
- package/lib/test/test.spec.js.map +0 -1
- package/lib/test/write.spec.js.map +0 -1
package/lib/test/write.spec.js
CHANGED
|
@@ -3,131 +3,80 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const mock_fs_1 = __importDefault(require("mock-fs"));
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
8
|
const chance_1 = __importDefault(require("chance"));
|
|
10
|
-
const
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
11
12
|
describe('write(src, data[, options])', () => {
|
|
13
|
+
const chance = new chance_1.default();
|
|
12
14
|
beforeEach(() => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
'flexapp': mock_fs_1.default.symlink({
|
|
20
|
-
path: 'tmpdir/binapp'
|
|
21
|
-
})
|
|
15
|
+
(0, __fmock_1.fmock)({
|
|
16
|
+
'./tmpdir/tings.txt': {
|
|
17
|
+
type: 'file',
|
|
18
|
+
data: chance.string()
|
|
19
|
+
}
|
|
22
20
|
});
|
|
23
21
|
});
|
|
24
|
-
afterEach(
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
24
|
+
});
|
|
25
25
|
it('Positive: Must write content to file', async () => {
|
|
26
|
-
const pfs = new src_1.default();
|
|
27
|
-
const chance = new chance_1.default();
|
|
28
|
-
const base = chance.guid();
|
|
29
|
-
const exists = await pfs.test(`./tmpdir/${base}`);
|
|
30
|
-
(0, assert_1.default)(exists === false);
|
|
31
26
|
const payload = chance.paragraph();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const guid = chance.guid();
|
|
28
|
+
await src_1.pfs.write(`./tmpdir/${guid}.txt`, payload);
|
|
29
|
+
const { size } = node_fs_1.default.lstatSync(`./tmpdir/${guid}.txt`);
|
|
30
|
+
(0, node_assert_1.default)(payload.length === size);
|
|
35
31
|
});
|
|
36
32
|
it('Positive: Must rewrite content if file already exists', async () => {
|
|
37
|
-
const pfs = new src_1.default();
|
|
38
|
-
const chance = new chance_1.default();
|
|
39
33
|
const payload = chance.paragraph();
|
|
40
|
-
await pfs.write('./tmpdir/
|
|
41
|
-
const
|
|
42
|
-
(0,
|
|
43
|
-
});
|
|
44
|
-
it(`Positive: Must write content to file, when path is absolute`, async () => {
|
|
45
|
-
const pfs = new src_1.default();
|
|
46
|
-
const chance = new chance_1.default();
|
|
47
|
-
const payload = chance.paragraph();
|
|
48
|
-
const cwd = process.cwd();
|
|
49
|
-
await pfs.write(`${cwd}${path_1.sep}tmpdir${path_1.sep}binapp`, payload, {
|
|
50
|
-
resolve: false
|
|
51
|
-
});
|
|
52
|
-
const stats = await pfs.stat(`./tmpdir/binapp`);
|
|
53
|
-
(0, assert_1.default)(stats.size > 0);
|
|
34
|
+
await src_1.pfs.write('./tmpdir/tings.txt', payload);
|
|
35
|
+
const { size } = node_fs_1.default.lstatSync('./tmpdir/tings.txt');
|
|
36
|
+
(0, node_assert_1.default)(payload.length === size);
|
|
54
37
|
});
|
|
55
38
|
it('Negative: Throw if resource is directory', async () => {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
catch (err) {
|
|
63
|
-
(0, assert_1.default)(err.errno === -21);
|
|
64
|
-
}
|
|
39
|
+
const payload = chance.paragraph();
|
|
40
|
+
await (0, expect_1.expect)(async () => {
|
|
41
|
+
await src_1.pfs.write('./tmpdir', payload);
|
|
42
|
+
})
|
|
43
|
+
.rejects
|
|
44
|
+
.toThrow();
|
|
65
45
|
});
|
|
66
46
|
it(`Negative: Unexpected option 'flag' returns Error`, async () => {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const payload = chance.paragraph();
|
|
71
|
-
await pfs.write('./tmpdir/binapp', payload, {
|
|
47
|
+
const payload = chance.paragraph();
|
|
48
|
+
await (0, expect_1.expect)(async () => {
|
|
49
|
+
await src_1.pfs.write('./tmpdir/tings.txt', payload, {
|
|
72
50
|
flag: 'r'
|
|
73
51
|
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
52
|
+
})
|
|
53
|
+
.rejects
|
|
54
|
+
.toThrow();
|
|
55
|
+
});
|
|
56
|
+
it('[sync] Positive: Write contents even to a non-existent file', () => {
|
|
57
|
+
const payload = chance.paragraph();
|
|
58
|
+
const guid = chance.guid();
|
|
59
|
+
src_1.pfs.write(`./tmpdir/${guid}.txt`, payload, {
|
|
60
|
+
sync: true
|
|
61
|
+
});
|
|
62
|
+
const content = node_fs_1.default.readFileSync(`./tmpdir/${guid}.txt`, 'utf8');
|
|
63
|
+
(0, node_assert_1.default)(payload === content);
|
|
78
64
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const base = chance.guid();
|
|
84
|
-
const exists = await pfs.test(`./tmpdir/${base}`);
|
|
85
|
-
(0, assert_1.default)(exists === false);
|
|
86
|
-
const payload = chance.paragraph();
|
|
87
|
-
pfs.write(`./tmpdir/${base}`, payload, {
|
|
65
|
+
it('[sync] Negative: Throw if resource is directory', () => {
|
|
66
|
+
const payload = chance.paragraph();
|
|
67
|
+
node_assert_1.default.throws(() => {
|
|
68
|
+
src_1.pfs.write('./tmpdir', payload, {
|
|
88
69
|
sync: true
|
|
89
70
|
});
|
|
90
|
-
const stats = await pfs.stat(`./tmpdir/${base}`);
|
|
91
|
-
(0, assert_1.default)(stats.size > 0);
|
|
92
71
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
pfs.write(`${cwd}${path_1.sep}tmpdir${path_1.sep}binapp`, payload, {
|
|
72
|
+
});
|
|
73
|
+
it(`[sync] Negative: Unexpected option 'flag' returns Error`, () => {
|
|
74
|
+
const payload = chance.paragraph();
|
|
75
|
+
node_assert_1.default.throws(() => {
|
|
76
|
+
src_1.pfs.write('./tmpdir/tings.txt', payload, {
|
|
99
77
|
sync: true,
|
|
100
|
-
|
|
78
|
+
flag: 'r'
|
|
101
79
|
});
|
|
102
|
-
const stats = await pfs.stat(`./tmpdir/binapp`);
|
|
103
|
-
(0, assert_1.default)(stats.size > 0);
|
|
104
|
-
});
|
|
105
|
-
it('Negative: Throw if resource is directory', async () => {
|
|
106
|
-
const pfs = new src_1.default();
|
|
107
|
-
const chance = new chance_1.default();
|
|
108
|
-
try {
|
|
109
|
-
const payload = chance.paragraph();
|
|
110
|
-
pfs.write('./tmpdir/libxbase', payload, {
|
|
111
|
-
sync: true
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
(0, assert_1.default)(err.errno === -21);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
it(`Negative: Unexpected option 'flag' returns Error`, async () => {
|
|
119
|
-
const pfs = new src_1.default();
|
|
120
|
-
const chance = new chance_1.default();
|
|
121
|
-
try {
|
|
122
|
-
const payload = chance.paragraph();
|
|
123
|
-
pfs.write('./tmpdir/binapp', payload, {
|
|
124
|
-
sync: true,
|
|
125
|
-
flag: 'r'
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
(0, assert_1.default)(err.errno === -9);
|
|
130
|
-
}
|
|
131
80
|
});
|
|
132
81
|
});
|
|
133
82
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pwd-fs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "Extend the file system the capabilities of declaring the present working directory and recursive execution",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"umask",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"url": "https://github.com/woodger/pwd-fs.git"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
30
|
+
"node": ">=13.2.0"
|
|
31
31
|
},
|
|
32
32
|
"main": "./lib/src/index.js",
|
|
33
33
|
"types": "./lib/src/index.d.ts",
|
|
@@ -36,14 +36,11 @@
|
|
|
36
36
|
"test": "mocha ./lib/test"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@types/
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"mocha": "^10.1.0",
|
|
46
|
-
"mock-fs": "^5.2.0",
|
|
47
|
-
"typescript": "^4.8.4"
|
|
39
|
+
"@types/chance": "^1.1.6",
|
|
40
|
+
"@types/mocha": "^10.0.6",
|
|
41
|
+
"chance": "^1.1.11",
|
|
42
|
+
"expect": "^29.7.0",
|
|
43
|
+
"mocha": "^10.4.0",
|
|
44
|
+
"typescript": "^5.4.5"
|
|
48
45
|
}
|
|
49
46
|
}
|
package/readme.md
CHANGED
|
@@ -19,7 +19,7 @@ To improve reliability and maintainability the code is migrated to [TypeScript](
|
|
|
19
19
|
To use `Powered File System` in your project, run:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
npm
|
|
22
|
+
npm install pwd-fs
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
#### Table of Contents
|
|
@@ -63,19 +63,17 @@ This class implemented by following the [ECMAScript® 2018 Language Specificatio
|
|
|
63
63
|
String form paths are interpreted as UTF-8 character sequences identifying the absolute or relative filename.
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
import
|
|
66
|
+
import { pfs } from 'pwd-fs';
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* pfs.pwd === process.cwd()
|
|
70
70
|
*/
|
|
71
|
-
|
|
72
|
-
const pfs = new PoweredFileSystem();
|
|
73
71
|
```
|
|
74
72
|
|
|
75
73
|
Relative paths will be resolved relative to the current working directory as specified by `process.cwd()`:
|
|
76
74
|
|
|
77
75
|
```ts
|
|
78
|
-
import PoweredFileSystem from 'pwd-fs';
|
|
76
|
+
import { PoweredFileSystem } from 'pwd-fs';
|
|
79
77
|
|
|
80
78
|
/**
|
|
81
79
|
* pfs.pwd === `${process.cwd()}/foo/bar`
|
|
@@ -87,7 +85,7 @@ const pfs = new PoweredFileSystem('./foo/bar');
|
|
|
87
85
|
Absolute paths:
|
|
88
86
|
|
|
89
87
|
```ts
|
|
90
|
-
import PoweredFileSystem from 'pwd-fs';
|
|
88
|
+
import { PoweredFileSystem } from 'pwd-fs';
|
|
91
89
|
|
|
92
90
|
/**
|
|
93
91
|
* pfs.pwd === __dirname
|
|
@@ -100,7 +98,6 @@ const pfs = new PoweredFileSystem(__dirname);
|
|
|
100
98
|
|
|
101
99
|
- `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`.
|
|
102
100
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
103
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
104
101
|
- `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'`.
|
|
105
102
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
106
103
|
- 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`.
|
|
@@ -126,7 +123,6 @@ Flag | Description
|
|
|
126
123
|
|
|
127
124
|
- `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
125
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
129
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
130
126
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
131
127
|
- 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`.
|
|
132
128
|
|
|
@@ -137,17 +133,18 @@ These functions return information about a resource in the file system.
|
|
|
137
133
|
- `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`.
|
|
138
134
|
- `mode` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> Is a numeric `bitmask` created using a logical `OR`.
|
|
139
135
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
140
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
141
136
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
142
137
|
- 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`.
|
|
143
138
|
|
|
144
139
|
Asynchronously changes the permissions of a file.
|
|
145
140
|
|
|
146
141
|
```ts
|
|
142
|
+
import { bitmask } from 'pwd-fs';
|
|
143
|
+
|
|
147
144
|
await pfs.chmod('./path', 0o750);
|
|
148
145
|
const { mode } = await pfs.stat('./path');
|
|
149
146
|
|
|
150
|
-
console.log(
|
|
147
|
+
console.log(bitmask(mode) === 0o750); // true
|
|
151
148
|
```
|
|
152
149
|
|
|
153
150
|
> **Caveats:** on Windows only the write permission can be changed, and the distinction among the permissions of group, owner or others is not implemented.
|
|
@@ -160,7 +157,6 @@ See manuals [chmod(2)](http://man7.org/linux/man-pages/man2/chmod.2.html)
|
|
|
160
157
|
- `uid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>
|
|
161
158
|
- `gid` <[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>
|
|
162
159
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
163
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
164
160
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
165
161
|
- 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`.
|
|
166
162
|
|
|
@@ -172,7 +168,6 @@ See manuals [chown(2)](http://man7.org/linux/man-pages/man2/chown.2.html).
|
|
|
172
168
|
- `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`.
|
|
173
169
|
- `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.
|
|
174
170
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
175
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
176
171
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
177
172
|
- 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
173
|
|
|
@@ -192,7 +187,6 @@ See manuals [symlink(2)](http://man7.org/linux/man-pages/man2/symlink.2.html).
|
|
|
192
187
|
- `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`.
|
|
193
188
|
- `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.
|
|
194
189
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
195
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
196
190
|
- `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`.
|
|
197
191
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
198
192
|
- 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`.
|
|
@@ -200,10 +194,12 @@ See manuals [symlink(2)](http://man7.org/linux/man-pages/man2/symlink.2.html).
|
|
|
200
194
|
Asynchronously recursively copy a file or directory.
|
|
201
195
|
|
|
202
196
|
```ts
|
|
197
|
+
import { bitmask } from 'pwd-fs';
|
|
198
|
+
|
|
203
199
|
await pfs.copy('./path/file.txt', './dist');
|
|
204
200
|
const { mode } = await pfs.stat('./dist/path/file.txt');
|
|
205
201
|
|
|
206
|
-
console.log(
|
|
202
|
+
console.log(bitmask(mode) === 0o666); // true
|
|
207
203
|
```
|
|
208
204
|
|
|
209
205
|
#### pfs.rename(src, use[, options])
|
|
@@ -211,7 +207,6 @@ console.log(PoweredFileSystem.bitmask(mode) === 0o666); // true
|
|
|
211
207
|
- `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`.
|
|
212
208
|
- `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.
|
|
213
209
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
214
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
215
210
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
216
211
|
- 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`.
|
|
217
212
|
|
|
@@ -225,7 +220,6 @@ await pfs.rename('./path/old_name.txt', './path/new_name.txt');
|
|
|
225
220
|
|
|
226
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`.
|
|
227
222
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
228
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
229
223
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
230
224
|
- 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`.
|
|
231
225
|
|
|
@@ -235,7 +229,6 @@ Asynchronously recursively remove a file or directory. Will be `resolve` if the
|
|
|
235
229
|
|
|
236
230
|
- `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`.
|
|
237
231
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
238
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
239
232
|
- `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
233
|
- `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
234
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
@@ -253,7 +246,6 @@ console.log(content); // 'Lorem Ipsum...'
|
|
|
253
246
|
- `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`.
|
|
254
247
|
- `data` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>
|
|
255
248
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
256
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
257
249
|
- `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`.
|
|
258
250
|
- `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
|
|
259
251
|
- `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'`.
|
|
@@ -275,7 +267,6 @@ await pfs.write('./file.txt', '... some text');
|
|
|
275
267
|
- `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`.
|
|
276
268
|
- `data` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>
|
|
277
269
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
278
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
279
270
|
- `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`.
|
|
280
271
|
- `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
|
|
281
272
|
- `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'`.
|
|
@@ -298,7 +289,6 @@ await pfs.write('./file', 'some content', {
|
|
|
298
289
|
|
|
299
290
|
- `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.
|
|
300
291
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
301
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
302
292
|
- `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'`.
|
|
303
293
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|
|
304
294
|
- 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.
|
|
@@ -314,7 +304,6 @@ console.log(list); // ["icons", "logo.svg"]
|
|
|
314
304
|
|
|
315
305
|
- `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.
|
|
316
306
|
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
|
|
317
|
-
- `resolve` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Declaration whether relative paths will be resolved. **Default:** `true`.
|
|
318
307
|
- `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`.
|
|
319
308
|
- `encoding` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)> Is the expected [string encoding](#string-encoding). **Default:** `'utf8'`.
|
|
320
309
|
- `sync` <[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)> Synchronous execution. **Default:** `false`.
|