pwd-fs 3.2.1 → 3.2.3

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.
@@ -76,14 +76,14 @@ export declare class PoweredFileSystem {
76
76
  }): Promise<void>;
77
77
  read(src: string, options: {
78
78
  sync: true;
79
- encoding?: BufferEncoding;
79
+ encoding: null;
80
80
  flag?: Flag;
81
- }): string;
81
+ }): Buffer;
82
82
  read(src: string, options: {
83
83
  sync: true;
84
- encoding?: null;
84
+ encoding?: BufferEncoding;
85
85
  flag?: Flag;
86
- }): Buffer;
86
+ }): string;
87
87
  read(src: string, options: {
88
88
  sync?: false;
89
89
  encoding: null;
@@ -162,10 +162,13 @@ class PoweredFileSystem {
162
162
  read(src, { sync = false, encoding = 'utf8', flag = 'r' } = {}) {
163
163
  src = this.resolve(src);
164
164
  if (sync) {
165
- return node_fs_1.default.readFileSync(src, {
165
+ const content = node_fs_1.default.readFileSync(src, {
166
166
  encoding,
167
167
  flag
168
168
  });
169
+ return encoding === null
170
+ ? Buffer.from(content)
171
+ : content;
169
172
  }
170
173
  return new Promise((resolve, reject) => {
171
174
  node_fs_1.default.readFile(src, {
@@ -202,9 +205,6 @@ class PoweredFileSystem {
202
205
  });
203
206
  });
204
207
  }
205
- /**
206
- * @deprecated The method should not be used
207
- */
208
208
  append(src, data, { sync = false, encoding = 'utf8', umask = 0o000, flag = 'a' } = {}) {
209
209
  src = this.resolve(src);
210
210
  const mode = 0o666 - umask;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pwd-fs",
3
- "version": "3.2.1",
3
+ "version": "3.2.3",
4
4
  "description": "Extend the file system the capabilities of declaring the present working directory and recursive execution",
5
5
  "keywords": [
6
6
  "umask",
package/readme.md CHANGED
@@ -37,10 +37,10 @@ npm install pwd-fs
37
37
  * [pfs.remove(src[, options])](#pfsremovesrc-options)
38
38
  * [pfs.read(src[, options])](#pfsreadsrc-options)
39
39
  * [pfs.write(src, data[, options])](#pfswritesrc-data-options)
40
- * [pfs.append(src, data[, options])](#pfsappendsrc-data-options-deprecated) `deprecated`
41
40
  * [pfs.readdir(dir[, options])](#pfsreaddirdir-options)
42
41
  * [pfs.mkdir(dir[, options])](#pfsmkdirdir-options)
43
42
  * [pfs.pwd](#pfspwd)
43
+ * [static: bitmask(mode)](#static-bitmaskmode)
44
44
 
45
45
  The scope `URI` of the class methods are divided into groups.
46
46
 
@@ -65,9 +65,7 @@ String form paths are interpreted as UTF-8 character sequences identifying the a
65
65
  ```ts
66
66
  import { pfs } from 'pwd-fs';
67
67
 
68
- /**
69
- * pfs.pwd === process.cwd()
70
- */
68
+ // pfs.pwd === process.cwd()
71
69
  ```
72
70
 
73
71
  Relative paths will be resolved relative to the current working directory as specified by `process.cwd()`:
@@ -75,9 +73,7 @@ Relative paths will be resolved relative to the current working directory as spe
75
73
  ```ts
76
74
  import { PoweredFileSystem } from 'pwd-fs';
77
75
 
78
- /**
79
- * pfs.pwd === `${process.cwd()}/foo/bar`
80
- */
76
+ // pfs.pwd === `${process.cwd()}/foo/bar`
81
77
 
82
78
  const pfs = new PoweredFileSystem('./foo/bar');
83
79
  ```
@@ -87,9 +83,7 @@ Absolute paths:
87
83
  ```ts
88
84
  import { PoweredFileSystem } from 'pwd-fs';
89
85
 
90
- /**
91
- * pfs.pwd === __dirname
92
- */
86
+ // pfs.pwd === __dirname
93
87
 
94
88
  const pfs = new PoweredFileSystem(__dirname);
95
89
  ```
@@ -194,12 +188,9 @@ See manuals [symlink(2)](http://man7.org/linux/man-pages/man2/symlink.2.html).
194
188
  Asynchronously recursively copy a file or directory.
195
189
 
196
190
  ```ts
197
- import { bitmask } from 'pwd-fs';
191
+ import { pfs } from 'pwd-fs';
198
192
 
199
193
  await pfs.copy('./path/file.txt', './dist');
200
- const { mode } = await pfs.stat('./dist/path/file.txt');
201
-
202
- console.log(bitmask(mode) === 0o666); // true
203
194
  ```
204
195
 
205
196
  #### pfs.rename(src, use[, options])
@@ -321,19 +312,40 @@ await pfs.mkdir('./static/images');
321
312
 
322
313
  The full path from the root directory to the present working directory: in the context of which relative paths will be resolved.
323
314
 
315
+ #### static: bitmask(mode)
316
+
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.
318
+
319
+ ```ts
320
+ import { bitmask } from 'pwd-fs';
321
+
322
+ // Access: (0644/-rw-r--r--)
323
+ const { mode } = await pfs.stat('./things.txt');
324
+ const access = bitmask(mode);
325
+
326
+ console.log(access === 0o644); // true
327
+ ```
328
+
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:
330
+
331
+ ```
332
+ mode: 33188
333
+ mask: 0o644 (rw-rw-r--)
334
+ ```
335
+
324
336
  #### Mode creation mask
325
337
 
326
338
  The following table shows some examples of how to set the extension `mode` or `umask` for files and directories.
327
339
 
328
- Umask | Mode files | Mode directories
329
- ------|-------|------------
330
- 0o000 | 0o666 (rw-rw-rw-) | 0o777 (rwxrwxrwx)
331
- 0o002 | 0o664 (rw-rw-r--) | 0o775 (rwxrwxr-x)
332
- 0o007 | 0o660 (rw-rw----) | 0o770 (rwxrwx---)
333
- 0o022 | 0o644 (rw-r--r--) | 0o755 (rwxr-xr-x)
334
- 0o027 | 0o640 (rw-r-----) | 0o750 (rwxr-x---)
335
- 0o077 | 0o600 (rw-------) | 0o700 (rwx------)
336
- 0o277 | 0o400 (r--------) | 0o500 (r-x------)
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------) |
337
349
 
338
350
  #### String encoding
339
351
 
@@ -92,13 +92,9 @@ export class PoweredFileSystem {
92
92
  });
93
93
  }
94
94
 
95
- chmod(src: string, mode: number, options: {
96
- sync: true
97
- }): void;
95
+ chmod(src: string, mode: number, options: { sync: true }): void;
98
96
 
99
- chmod(src: string, mode: number, options?: {
100
- sync?: false
101
- }): Promise<void>;
97
+ chmod(src: string, mode: number, options?: { sync?: false }): Promise<void>;
102
98
 
103
99
  chmod(src: string, mode: number, { sync = false }: { sync?: boolean } = {}) {
104
100
  src = this.resolve(src);
@@ -148,13 +144,9 @@ export class PoweredFileSystem {
148
144
  });
149
145
  }
150
146
 
151
- symlink(src: string, use: string, options: {
152
- sync: true
153
- }): void;
147
+ symlink(src: string, use: string, options: { sync: true }): void;
154
148
 
155
- symlink(src: string, use: string, options?: {
156
- sync?: false
157
- }): Promise<void>;
149
+ symlink(src: string, use: string, options?: { sync?: false }): Promise<void>;
158
150
 
159
151
  symlink(src: string, use: string, { sync = false }: { sync?: boolean } = {}) {
160
152
  src = this.resolve(src);
@@ -207,13 +199,9 @@ export class PoweredFileSystem {
207
199
  });
208
200
  }
209
201
 
210
- rename(src: string, use: string, options: {
211
- sync: true
212
- }): void;
202
+ rename(src: string, use: string, options: { sync: true }): void;
213
203
 
214
- rename(src: string, use: string, options?: {
215
- sync?: false
216
- }): Promise<void>;
204
+ rename(src: string, use: string, options?: { sync?: false }): Promise<void>;
217
205
 
218
206
  rename(src: string, use: string, { sync = false }: { sync?: boolean } = {}) {
219
207
  src = this.resolve(src);
@@ -234,13 +222,9 @@ export class PoweredFileSystem {
234
222
  });
235
223
  }
236
224
 
237
- remove(src: string, options: {
238
- sync: true
239
- }): void;
225
+ remove(src: string, options: { sync: true }): void;
240
226
 
241
- remove(src: string, options?: {
242
- sync?: false
243
- }): Promise<void>;
227
+ remove(src: string, options?: { sync?: false }): Promise<void>;
244
228
 
245
229
  remove(src: string, { sync = false }: { sync?: boolean } = {}) {
246
230
  src = this.resolve(src);
@@ -268,15 +252,15 @@ export class PoweredFileSystem {
268
252
 
269
253
  read(src: string, options: {
270
254
  sync: true,
271
- encoding?: BufferEncoding,
255
+ encoding: null,
272
256
  flag?: Flag
273
- }): string;
257
+ }): Buffer;
274
258
 
275
259
  read(src: string, options: {
276
260
  sync: true,
277
- encoding?: null,
261
+ encoding?: BufferEncoding,
278
262
  flag?: Flag
279
- }): Buffer;
263
+ }): string;
280
264
 
281
265
  read(src: string, options: {
282
266
  sync?: false,
@@ -298,10 +282,14 @@ export class PoweredFileSystem {
298
282
  src = this.resolve(src);
299
283
 
300
284
  if (sync) {
301
- return fs.readFileSync(src, {
285
+ const content = fs.readFileSync(src, {
302
286
  encoding,
303
287
  flag
304
288
  });
289
+
290
+ return encoding === null
291
+ ? Buffer.from(content)
292
+ : content;
305
293
  }
306
294
 
307
295
  return new Promise((resolve, reject) => {
@@ -421,9 +409,6 @@ export class PoweredFileSystem {
421
409
  flag?: Flag
422
410
  }): Promise<void>;
423
411
 
424
- /**
425
- * @deprecated The method should not be used
426
- */
427
412
  append(src: string, data: Buffer | string, { sync = false, encoding = 'utf8', umask = 0o000, flag = 'a' }: {
428
413
  sync?: boolean,
429
414
  encoding?: BufferEncoding | null,
package/test/read.spec.ts CHANGED
@@ -70,12 +70,12 @@ describe('read(src [, options])', () => {
70
70
 
71
71
 
72
72
  it('[sync] Positive: Must read Buffer content of file when encoding is null', () => {
73
- const buffer = pfs.read('./tmpdir/tings.txt', {
74
- encoding: null,
75
- sync: true
73
+ const buf = pfs.read('./tmpdir/tings.txt', {
74
+ sync: true,
75
+ encoding: null
76
76
  });
77
77
 
78
- assert(buffer instanceof Buffer);
78
+ assert(buf instanceof Buffer);
79
79
  });
80
80
 
81
81
 
package/tsconfig.json CHANGED
@@ -8,12 +8,7 @@
8
8
  "moduleResolution": "node",
9
9
  "resolveJsonModule": true,
10
10
  "esModuleInterop": true,
11
- "allowSyntheticDefaultImports": true,
12
- "strict": true,
13
- "useUnknownInCatchVariables": false,
14
11
  "declaration": true,
15
- "noEmitOnError": true,
16
- "noUnusedLocals": false,
17
- "outDir": "dist"
12
+ "outDir": "./dist"
18
13
  }
19
14
  }