bare-fs 3.1.0 → 4.0.0

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/index.js CHANGED
@@ -6,7 +6,7 @@ const binding = require('./binding')
6
6
 
7
7
  const isWindows = Bare.platform === 'win32'
8
8
 
9
- const constants = exports.constants = {
9
+ const constants = (exports.constants = {
10
10
  O_RDWR: binding.O_RDWR,
11
11
  O_RDONLY: binding.O_RDONLY,
12
12
  O_WRONLY: binding.O_WRONLY,
@@ -52,108 +52,126 @@ const constants = exports.constants = {
52
52
  COPYFILE_FICLONE_FORCE: binding.UV_FS_COPYFILE_FICLONE_FORCE,
53
53
  UV_FS_SYMLINK_DIR: binding.UV_FS_SYMLINK_DIR,
54
54
  UV_FS_SYMLINK_JUNCTION: binding.UV_FS_SYMLINK_JUNCTION
55
- }
56
-
57
- const reqs = []
58
- let used = 0
59
-
60
- const fs = {
61
- handle: Buffer.allocUnsafe(binding.sizeofFS)
62
- }
63
-
64
- binding.init(fs.handle, fs, onresponse)
65
-
66
- Bare.on('exit', () => {
67
- for (const req of reqs) binding.reqCancel(req.handle)
68
-
69
- binding.destroy(fs.handle)
70
55
  })
71
56
 
72
57
  // Lightly-modified from the Node FS internal utils.
73
- function flagsToNumber (flags) {
58
+ function flagsToNumber(flags) {
74
59
  switch (flags) {
75
- case 'r' : return constants.O_RDONLY
76
- case 'rs' : // Fall through.
77
- case 'sr' : return constants.O_RDONLY | constants.O_SYNC
78
- case 'r+' : return constants.O_RDWR
79
- case 'rs+' : // Fall through.
80
- case 'sr+' : return constants.O_RDWR | constants.O_SYNC
81
-
82
- case 'w' : return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY
83
- case 'wx' : // Fall through.
84
- case 'xw' : return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL
85
-
86
- case 'w+' : return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR
60
+ case 'r':
61
+ return constants.O_RDONLY
62
+ case 'rs': // Fall through.
63
+ case 'sr':
64
+ return constants.O_RDONLY | constants.O_SYNC
65
+ case 'r+':
66
+ return constants.O_RDWR
67
+ case 'rs+': // Fall through.
68
+ case 'sr+':
69
+ return constants.O_RDWR | constants.O_SYNC
70
+
71
+ case 'w':
72
+ return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY
73
+ case 'wx': // Fall through.
74
+ case 'xw':
75
+ return (
76
+ constants.O_TRUNC |
77
+ constants.O_CREAT |
78
+ constants.O_WRONLY |
79
+ constants.O_EXCL
80
+ )
81
+
82
+ case 'w+':
83
+ return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR
87
84
  case 'wx+': // Fall through.
88
- case 'xw+': return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL
89
-
90
- case 'a' : return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY
91
- case 'ax' : // Fall through.
92
- case 'xa' : return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL
93
- case 'as' : // Fall through.
94
- case 'sa' : return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_SYNC
95
-
96
- case 'a+' : return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR
85
+ case 'xw+':
86
+ return (
87
+ constants.O_TRUNC |
88
+ constants.O_CREAT |
89
+ constants.O_RDWR |
90
+ constants.O_EXCL
91
+ )
92
+
93
+ case 'a':
94
+ return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY
95
+ case 'ax': // Fall through.
96
+ case 'xa':
97
+ return (
98
+ constants.O_APPEND |
99
+ constants.O_CREAT |
100
+ constants.O_WRONLY |
101
+ constants.O_EXCL
102
+ )
103
+ case 'as': // Fall through.
104
+ case 'sa':
105
+ return (
106
+ constants.O_APPEND |
107
+ constants.O_CREAT |
108
+ constants.O_WRONLY |
109
+ constants.O_SYNC
110
+ )
111
+
112
+ case 'a+':
113
+ return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR
97
114
  case 'ax+': // Fall through.
98
- case 'xa+': return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL
115
+ case 'xa+':
116
+ return (
117
+ constants.O_APPEND |
118
+ constants.O_CREAT |
119
+ constants.O_RDWR |
120
+ constants.O_EXCL
121
+ )
99
122
  case 'as+': // Fall through.
100
- case 'sa+': return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_SYNC
123
+ case 'sa+':
124
+ return (
125
+ constants.O_APPEND |
126
+ constants.O_CREAT |
127
+ constants.O_RDWR |
128
+ constants.O_SYNC
129
+ )
101
130
  }
102
131
 
103
132
  throw typeError('ERR_INVALID_ARG_VALUE', `Invalid value in flags: ${flags}`)
104
133
  }
105
134
 
106
- function modeToNumber (mode) {
135
+ function modeToNumber(mode) {
107
136
  mode = parseInt(mode, 8)
108
- if (isNaN(mode)) throw typeError('ERR_INVALID_ARG_VALUE', 'Mode must be a number or octal string')
137
+ if (isNaN(mode))
138
+ throw typeError(
139
+ 'ERR_INVALID_ARG_VALUE',
140
+ 'Mode must be a number or octal string'
141
+ )
109
142
  return mode
110
143
  }
111
144
 
112
- function alloc () {
113
- const handle = Buffer.alloc(binding.sizeofFSReq)
114
-
115
- binding.reqInit(fs.handle, handle)
116
-
117
- const view = new Uint32Array(handle.buffer, handle.byteOffset + binding.offsetofFSReqID, 1)
118
-
119
- view[0] = reqs.length
145
+ const free = []
120
146
 
121
- const req = {
122
- handle,
123
- view,
124
- type: 0,
125
- callback: null
126
- }
127
-
128
- used++
129
- reqs.push(req)
147
+ function alloc() {
148
+ const req = { handle: null, callback: null }
149
+ req.handle = binding.init(req, onresponse)
130
150
  return req
131
151
  }
132
152
 
133
- function getReq () {
134
- return used === reqs.length ? alloc() : reqs[used++]
153
+ function getReq() {
154
+ return free.length ? free.pop() : alloc()
135
155
  }
136
156
 
137
- function onresponse (id, err, result) {
138
- const req = reqs[id]
139
- used--
140
-
141
- if (used !== id) {
142
- const u = reqs[used]
143
- reqs[u.view[0] = id] = u
144
- reqs[req.view[0] = used] = req
145
- }
146
-
147
- const callback = req.callback
148
-
157
+ function onresponse(err, result) {
158
+ const req = this
159
+ const cb = req.callback
149
160
  req.callback = null
150
-
151
- callback(err, result)
161
+ free.push(req)
162
+ cb(err, result)
152
163
  }
153
164
 
154
- function open (filepath, flags, mode, cb) {
165
+ function open(filepath, flags, mode, cb) {
155
166
  if (typeof filepath !== 'string') {
156
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
167
+ throw typeError(
168
+ 'ERR_INVALID_ARG_TYPE',
169
+ 'Path must be a string. Received type ' +
170
+ typeof filepath +
171
+ ' (' +
172
+ filepath +
173
+ ')'
174
+ )
157
175
  }
158
176
 
159
177
  if (typeof cb !== 'function') {
@@ -165,7 +183,14 @@ function open (filepath, flags, mode, cb) {
165
183
  cb = mode
166
184
  mode = 0o666
167
185
  } else {
168
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
186
+ throw typeError(
187
+ 'ERR_INVALID_ARG_TYPE',
188
+ 'Callback must be a function. Received type ' +
189
+ typeof cb +
190
+ ' (' +
191
+ cb +
192
+ ')'
193
+ )
169
194
  }
170
195
  }
171
196
 
@@ -177,9 +202,16 @@ function open (filepath, flags, mode, cb) {
177
202
  binding.open(req.handle, filepath, flags, mode)
178
203
  }
179
204
 
180
- function openSync (filepath, flags = 'r', mode = 0o666) {
205
+ function openSync(filepath, flags = 'r', mode = 0o666) {
181
206
  if (typeof filepath !== 'string') {
182
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
207
+ throw typeError(
208
+ 'ERR_INVALID_ARG_TYPE',
209
+ 'Path must be a string. Received type ' +
210
+ typeof filepath +
211
+ ' (' +
212
+ filepath +
213
+ ')'
214
+ )
183
215
  }
184
216
 
185
217
  if (typeof flags === 'string') flags = flagsToNumber(flags)
@@ -188,17 +220,35 @@ function openSync (filepath, flags = 'r', mode = 0o666) {
188
220
  return binding.openSync(filepath, flags, mode)
189
221
  }
190
222
 
191
- function close (fd, cb = noop) {
223
+ function close(fd, cb = noop) {
192
224
  if (typeof fd !== 'number') {
193
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
225
+ throw typeError(
226
+ 'ERR_INVALID_ARG_TYPE',
227
+ 'File descriptor must be a number. Received type ' +
228
+ typeof fd +
229
+ ' (' +
230
+ fd +
231
+ ')'
232
+ )
194
233
  }
195
234
 
196
235
  if (fd < 0 || fd > 0x7fffffff) {
197
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
236
+ throw typeError(
237
+ 'ERR_OUT_OF_RANGE',
238
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
239
+ fd
240
+ )
198
241
  }
199
242
 
200
243
  if (typeof cb !== 'function') {
201
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
244
+ throw typeError(
245
+ 'ERR_INVALID_ARG_TYPE',
246
+ 'Callback must be a function. Received type ' +
247
+ typeof cb +
248
+ ' (' +
249
+ cb +
250
+ ')'
251
+ )
202
252
  }
203
253
 
204
254
  const req = getReq()
@@ -206,21 +256,39 @@ function close (fd, cb = noop) {
206
256
  binding.close(req.handle, fd)
207
257
  }
208
258
 
209
- function closeSync (fd) {
259
+ function closeSync(fd) {
210
260
  if (typeof fd !== 'number') {
211
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
261
+ throw typeError(
262
+ 'ERR_INVALID_ARG_TYPE',
263
+ 'File descriptor must be a number. Received type ' +
264
+ typeof fd +
265
+ ' (' +
266
+ fd +
267
+ ')'
268
+ )
212
269
  }
213
270
 
214
271
  if (fd < 0 || fd > 0x7fffffff) {
215
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
272
+ throw typeError(
273
+ 'ERR_OUT_OF_RANGE',
274
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
275
+ fd
276
+ )
216
277
  }
217
278
 
218
279
  return binding.closeSync(fd)
219
280
  }
220
281
 
221
- function access (filepath, mode, cb) {
282
+ function access(filepath, mode, cb) {
222
283
  if (typeof filepath !== 'string') {
223
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
284
+ throw typeError(
285
+ 'ERR_INVALID_ARG_TYPE',
286
+ 'Path must be a string. Received type ' +
287
+ typeof filepath +
288
+ ' (' +
289
+ filepath +
290
+ ')'
291
+ )
224
292
  }
225
293
 
226
294
  if (typeof cb !== 'function') {
@@ -228,7 +296,14 @@ function access (filepath, mode, cb) {
228
296
  cb = mode
229
297
  mode = constants.F_OK
230
298
  } else {
231
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
299
+ throw typeError(
300
+ 'ERR_INVALID_ARG_TYPE',
301
+ 'Callback must be a function. Received type ' +
302
+ typeof cb +
303
+ ' (' +
304
+ cb +
305
+ ')'
306
+ )
232
307
  }
233
308
  }
234
309
 
@@ -237,29 +312,57 @@ function access (filepath, mode, cb) {
237
312
  binding.access(req.handle, filepath, mode)
238
313
  }
239
314
 
240
- function accessSync (filepath, mode = constants.F_OK) {
315
+ function accessSync(filepath, mode = constants.F_OK) {
241
316
  if (typeof filepath !== 'string') {
242
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
317
+ throw typeError(
318
+ 'ERR_INVALID_ARG_TYPE',
319
+ 'Path must be a string. Received type ' +
320
+ typeof filepath +
321
+ ' (' +
322
+ filepath +
323
+ ')'
324
+ )
243
325
  }
244
326
 
245
327
  binding.accessSync(filepath, mode)
246
328
  }
247
329
 
248
- function exists (filepath, cb) {
330
+ function exists(filepath, cb) {
249
331
  if (typeof filepath !== 'string') {
250
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
332
+ throw typeError(
333
+ 'ERR_INVALID_ARG_TYPE',
334
+ 'Path must be a string. Received type ' +
335
+ typeof filepath +
336
+ ' (' +
337
+ filepath +
338
+ ')'
339
+ )
251
340
  }
252
341
 
253
342
  if (typeof cb !== 'function') {
254
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
343
+ throw typeError(
344
+ 'ERR_INVALID_ARG_TYPE',
345
+ 'Callback must be a function. Received type ' +
346
+ typeof cb +
347
+ ' (' +
348
+ cb +
349
+ ')'
350
+ )
255
351
  }
256
352
 
257
- return access(filepath, (err) => cb(!!err)) // eslint-disable-line n/no-callback-literal
353
+ return access(filepath, (err) => cb(!!err))
258
354
  }
259
355
 
260
- function existsSync (filepath) {
356
+ function existsSync(filepath) {
261
357
  if (typeof filepath !== 'string') {
262
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
358
+ throw typeError(
359
+ 'ERR_INVALID_ARG_TYPE',
360
+ 'Path must be a string. Received type ' +
361
+ typeof filepath +
362
+ ' (' +
363
+ filepath +
364
+ ')'
365
+ )
263
366
  }
264
367
 
265
368
  try {
@@ -270,17 +373,35 @@ function existsSync (filepath) {
270
373
  }
271
374
  }
272
375
 
273
- function read (fd, buffer, offset, len, pos, cb) {
376
+ function read(fd, buffer, offset, len, pos, cb) {
274
377
  if (typeof fd !== 'number') {
275
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
378
+ throw typeError(
379
+ 'ERR_INVALID_ARG_TYPE',
380
+ 'File descriptor must be a number. Received type ' +
381
+ typeof fd +
382
+ ' (' +
383
+ fd +
384
+ ')'
385
+ )
276
386
  }
277
387
 
278
388
  if (fd < 0 || fd > 0x7fffffff) {
279
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
389
+ throw typeError(
390
+ 'ERR_OUT_OF_RANGE',
391
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
392
+ fd
393
+ )
280
394
  }
281
395
 
282
396
  if (!Buffer.isBuffer(buffer) && !ArrayBuffer.isView(buffer)) {
283
- throw typeError('ERR_INVALID_ARG_TYPE', 'Buffer must be a buffer. Received type ' + (typeof buffer) + ' (' + buffer + ')')
397
+ throw typeError(
398
+ 'ERR_INVALID_ARG_TYPE',
399
+ 'Buffer must be a buffer. Received type ' +
400
+ typeof buffer +
401
+ ' (' +
402
+ buffer +
403
+ ')'
404
+ )
284
405
  }
285
406
 
286
407
  if (typeof cb !== 'function') {
@@ -297,7 +418,14 @@ function read (fd, buffer, offset, len, pos, cb) {
297
418
  cb = pos
298
419
  pos = -1
299
420
  } else {
300
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
421
+ throw typeError(
422
+ 'ERR_INVALID_ARG_TYPE',
423
+ 'Callback must be a function. Received type ' +
424
+ typeof cb +
425
+ ' (' +
426
+ cb +
427
+ ')'
428
+ )
301
429
  }
302
430
  }
303
431
 
@@ -308,36 +436,78 @@ function read (fd, buffer, offset, len, pos, cb) {
308
436
  binding.read(req.handle, fd, buffer, offset, len, pos)
309
437
  }
310
438
 
311
- function readSync (fd, buffer, offset = 0, len = buffer.byteLength - offset, pos = -1) {
439
+ function readSync(
440
+ fd,
441
+ buffer,
442
+ offset = 0,
443
+ len = buffer.byteLength - offset,
444
+ pos = -1
445
+ ) {
312
446
  if (typeof fd !== 'number') {
313
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
447
+ throw typeError(
448
+ 'ERR_INVALID_ARG_TYPE',
449
+ 'File descriptor must be a number. Received type ' +
450
+ typeof fd +
451
+ ' (' +
452
+ fd +
453
+ ')'
454
+ )
314
455
  }
315
456
 
316
457
  if (fd < 0 || fd > 0x7fffffff) {
317
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
458
+ throw typeError(
459
+ 'ERR_OUT_OF_RANGE',
460
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
461
+ fd
462
+ )
318
463
  }
319
464
 
320
465
  if (!Buffer.isBuffer(buffer) && !ArrayBuffer.isView(buffer)) {
321
- throw typeError('ERR_INVALID_ARG_TYPE', 'Buffer must be a buffer. Received type ' + (typeof buffer) + ' (' + buffer + ')')
466
+ throw typeError(
467
+ 'ERR_INVALID_ARG_TYPE',
468
+ 'Buffer must be a buffer. Received type ' +
469
+ typeof buffer +
470
+ ' (' +
471
+ buffer +
472
+ ')'
473
+ )
322
474
  }
323
475
 
324
476
  return binding.readSync(fd, buffer, offset, len, pos)
325
477
  }
326
478
 
327
- function readv (fd, buffers, pos, cb) {
479
+ function readv(fd, buffers, pos, cb) {
328
480
  if (typeof fd !== 'number') {
329
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
481
+ throw typeError(
482
+ 'ERR_INVALID_ARG_TYPE',
483
+ 'File descriptor must be a number. Received type ' +
484
+ typeof fd +
485
+ ' (' +
486
+ fd +
487
+ ')'
488
+ )
330
489
  }
331
490
 
332
491
  if (fd < 0 || fd > 0x7fffffff) {
333
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
492
+ throw typeError(
493
+ 'ERR_OUT_OF_RANGE',
494
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
495
+ fd
496
+ )
334
497
  }
335
498
 
336
499
  if (typeof pos === 'function') {
337
500
  cb = pos
338
501
  pos = -1
339
502
  } else if (typeof cb !== 'function') {
340
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
503
+ throw typeError(
504
+ 'ERR_INVALID_ARG_TYPE',
505
+ 'Callback must be a function. Received type ' +
506
+ typeof cb +
507
+ ' (' +
508
+ cb +
509
+ ')'
510
+ )
341
511
  }
342
512
 
343
513
  if (typeof pos !== 'number') pos = -1
@@ -347,17 +517,35 @@ function readv (fd, buffers, pos, cb) {
347
517
  binding.readv(req.handle, fd, buffers, pos)
348
518
  }
349
519
 
350
- function write (fd, data, offset, len, pos, cb) {
520
+ function write(fd, data, offset, len, pos, cb) {
351
521
  if (typeof fd !== 'number') {
352
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
522
+ throw typeError(
523
+ 'ERR_INVALID_ARG_TYPE',
524
+ 'File descriptor must be a number. Received type ' +
525
+ typeof fd +
526
+ ' (' +
527
+ fd +
528
+ ')'
529
+ )
353
530
  }
354
531
 
355
532
  if (fd < 0 || fd > 0x7fffffff) {
356
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
533
+ throw typeError(
534
+ 'ERR_OUT_OF_RANGE',
535
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
536
+ fd
537
+ )
357
538
  }
358
539
 
359
- if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
360
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
540
+ if (
541
+ typeof data !== 'string' &&
542
+ !Buffer.isBuffer(data) &&
543
+ !ArrayBuffer.isView(data)
544
+ ) {
545
+ throw typeError(
546
+ 'ERR_INVALID_ARG_TYPE',
547
+ 'Data must be a string or buffer. Received type ' + typeof data
548
+ )
361
549
  }
362
550
 
363
551
  if (typeof data === 'string') {
@@ -374,7 +562,14 @@ function write (fd, data, offset, len, pos, cb) {
374
562
  cb = encoding
375
563
  encoding = 'utf8'
376
564
  } else {
377
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
565
+ throw typeError(
566
+ 'ERR_INVALID_ARG_TYPE',
567
+ 'Callback must be a function. Received type ' +
568
+ typeof cb +
569
+ ' (' +
570
+ cb +
571
+ ')'
572
+ )
378
573
  }
379
574
  }
380
575
 
@@ -400,7 +595,14 @@ function write (fd, data, offset, len, pos, cb) {
400
595
  cb = pos
401
596
  pos = -1
402
597
  } else {
403
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
598
+ throw typeError(
599
+ 'ERR_INVALID_ARG_TYPE',
600
+ 'Callback must be a function. Received type ' +
601
+ typeof cb +
602
+ ' (' +
603
+ cb +
604
+ ')'
605
+ )
404
606
  }
405
607
  }
406
608
 
@@ -411,17 +613,35 @@ function write (fd, data, offset, len, pos, cb) {
411
613
  binding.write(req.handle, fd, data, offset, len, pos)
412
614
  }
413
615
 
414
- function writeSync (fd, data, offset = 0, len, pos) {
616
+ function writeSync(fd, data, offset = 0, len, pos) {
415
617
  if (typeof fd !== 'number') {
416
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
618
+ throw typeError(
619
+ 'ERR_INVALID_ARG_TYPE',
620
+ 'File descriptor must be a number. Received type ' +
621
+ typeof fd +
622
+ ' (' +
623
+ fd +
624
+ ')'
625
+ )
417
626
  }
418
627
 
419
628
  if (fd < 0 || fd > 0x7fffffff) {
420
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
629
+ throw typeError(
630
+ 'ERR_OUT_OF_RANGE',
631
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
632
+ fd
633
+ )
421
634
  }
422
635
 
423
- if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
424
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
636
+ if (
637
+ typeof data !== 'string' &&
638
+ !Buffer.isBuffer(data) &&
639
+ !ArrayBuffer.isView(data)
640
+ ) {
641
+ throw typeError(
642
+ 'ERR_INVALID_ARG_TYPE',
643
+ 'Data must be a string or buffer. Received type ' + typeof data
644
+ )
425
645
  }
426
646
 
427
647
  if (typeof data === 'string') data = Buffer.from(data)
@@ -433,20 +653,38 @@ function writeSync (fd, data, offset = 0, len, pos) {
433
653
  return binding.writeSync(fd, data, offset, len, pos)
434
654
  }
435
655
 
436
- function writev (fd, buffers, pos, cb) {
656
+ function writev(fd, buffers, pos, cb) {
437
657
  if (typeof fd !== 'number') {
438
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
658
+ throw typeError(
659
+ 'ERR_INVALID_ARG_TYPE',
660
+ 'File descriptor must be a number. Received type ' +
661
+ typeof fd +
662
+ ' (' +
663
+ fd +
664
+ ')'
665
+ )
439
666
  }
440
667
 
441
668
  if (fd < 0 || fd > 0x7fffffff) {
442
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
669
+ throw typeError(
670
+ 'ERR_OUT_OF_RANGE',
671
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
672
+ fd
673
+ )
443
674
  }
444
675
 
445
676
  if (typeof pos === 'function') {
446
677
  cb = pos
447
678
  pos = -1
448
679
  } else if (typeof cb !== 'function') {
449
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
680
+ throw typeError(
681
+ 'ERR_INVALID_ARG_TYPE',
682
+ 'Callback must be a function. Received type ' +
683
+ typeof cb +
684
+ ' (' +
685
+ cb +
686
+ ')'
687
+ )
450
688
  }
451
689
 
452
690
  if (typeof pos !== 'number') pos = -1
@@ -456,13 +694,27 @@ function writev (fd, buffers, pos, cb) {
456
694
  binding.writev(req.handle, fd, buffers, pos)
457
695
  }
458
696
 
459
- function stat (filepath, cb) {
697
+ function stat(filepath, cb) {
460
698
  if (typeof filepath !== 'string') {
461
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
699
+ throw typeError(
700
+ 'ERR_INVALID_ARG_TYPE',
701
+ 'Path must be a string. Received type ' +
702
+ typeof filepath +
703
+ ' (' +
704
+ filepath +
705
+ ')'
706
+ )
462
707
  }
463
708
 
464
709
  if (typeof cb !== 'function') {
465
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
710
+ throw typeError(
711
+ 'ERR_INVALID_ARG_TYPE',
712
+ 'Callback must be a function. Received type ' +
713
+ typeof cb +
714
+ ' (' +
715
+ cb +
716
+ ')'
717
+ )
466
718
  }
467
719
 
468
720
  const data = new Array(Stats.length)
@@ -477,21 +729,42 @@ function stat (filepath, cb) {
477
729
  binding.stat(req.handle, filepath, data)
478
730
  }
479
731
 
480
- function statSync (filepath) {
732
+ function statSync(filepath) {
481
733
  if (typeof filepath !== 'string') {
482
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
734
+ throw typeError(
735
+ 'ERR_INVALID_ARG_TYPE',
736
+ 'Path must be a string. Received type ' +
737
+ typeof filepath +
738
+ ' (' +
739
+ filepath +
740
+ ')'
741
+ )
483
742
  }
484
743
 
485
744
  return new Stats(...binding.statSync(filepath))
486
745
  }
487
746
 
488
- function lstat (filepath, cb) {
747
+ function lstat(filepath, cb) {
489
748
  if (typeof filepath !== 'string') {
490
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
749
+ throw typeError(
750
+ 'ERR_INVALID_ARG_TYPE',
751
+ 'Path must be a string. Received type ' +
752
+ typeof filepath +
753
+ ' (' +
754
+ filepath +
755
+ ')'
756
+ )
491
757
  }
492
758
 
493
759
  if (typeof cb !== 'function') {
494
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
760
+ throw typeError(
761
+ 'ERR_INVALID_ARG_TYPE',
762
+ 'Callback must be a function. Received type ' +
763
+ typeof cb +
764
+ ' (' +
765
+ cb +
766
+ ')'
767
+ )
495
768
  }
496
769
 
497
770
  const data = new Array(Stats.length)
@@ -506,25 +779,50 @@ function lstat (filepath, cb) {
506
779
  binding.lstat(req.handle, filepath, data)
507
780
  }
508
781
 
509
- function lstatSync (filepath) {
782
+ function lstatSync(filepath) {
510
783
  if (typeof filepath !== 'string') {
511
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
784
+ throw typeError(
785
+ 'ERR_INVALID_ARG_TYPE',
786
+ 'Path must be a string. Received type ' +
787
+ typeof filepath +
788
+ ' (' +
789
+ filepath +
790
+ ')'
791
+ )
512
792
  }
513
793
 
514
794
  return new Stats(...binding.lstatSync(filepath))
515
795
  }
516
796
 
517
- function fstat (fd, cb) {
797
+ function fstat(fd, cb) {
518
798
  if (typeof fd !== 'number') {
519
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
799
+ throw typeError(
800
+ 'ERR_INVALID_ARG_TYPE',
801
+ 'File descriptor must be a number. Received type ' +
802
+ typeof fd +
803
+ ' (' +
804
+ fd +
805
+ ')'
806
+ )
520
807
  }
521
808
 
522
809
  if (fd < 0 || fd > 0x7fffffff) {
523
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
810
+ throw typeError(
811
+ 'ERR_OUT_OF_RANGE',
812
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
813
+ fd
814
+ )
524
815
  }
525
816
 
526
817
  if (typeof cb !== 'function') {
527
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
818
+ throw typeError(
819
+ 'ERR_INVALID_ARG_TYPE',
820
+ 'Callback must be a function. Received type ' +
821
+ typeof cb +
822
+ ' (' +
823
+ cb +
824
+ ')'
825
+ )
528
826
  }
529
827
 
530
828
  const data = new Array(Stats.length)
@@ -539,32 +837,61 @@ function fstat (fd, cb) {
539
837
  binding.fstat(req.handle, fd, data)
540
838
  }
541
839
 
542
- function fstatSync (fd) {
840
+ function fstatSync(fd) {
543
841
  if (typeof fd !== 'number') {
544
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
842
+ throw typeError(
843
+ 'ERR_INVALID_ARG_TYPE',
844
+ 'File descriptor must be a number. Received type ' +
845
+ typeof fd +
846
+ ' (' +
847
+ fd +
848
+ ')'
849
+ )
545
850
  }
546
851
 
547
852
  if (fd < 0 || fd > 0x7fffffff) {
548
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
853
+ throw typeError(
854
+ 'ERR_OUT_OF_RANGE',
855
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
856
+ fd
857
+ )
549
858
  }
550
859
 
551
860
  return new Stats(...binding.fstatSync(fd))
552
861
  }
553
862
 
554
- function ftruncate (fd, len, cb) {
863
+ function ftruncate(fd, len, cb) {
555
864
  if (typeof fd !== 'number') {
556
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
865
+ throw typeError(
866
+ 'ERR_INVALID_ARG_TYPE',
867
+ 'File descriptor must be a number. Received type ' +
868
+ typeof fd +
869
+ ' (' +
870
+ fd +
871
+ ')'
872
+ )
557
873
  }
558
874
 
559
875
  if (fd < 0 || fd > 0x7fffffff) {
560
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
876
+ throw typeError(
877
+ 'ERR_OUT_OF_RANGE',
878
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
879
+ fd
880
+ )
561
881
  }
562
882
 
563
883
  if (typeof len === 'function') {
564
884
  cb = len
565
885
  len = 0
566
886
  } else if (typeof cb !== 'function') {
567
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
887
+ throw typeError(
888
+ 'ERR_INVALID_ARG_TYPE',
889
+ 'Callback must be a function. Received type ' +
890
+ typeof cb +
891
+ ' (' +
892
+ cb +
893
+ ')'
894
+ )
568
895
  }
569
896
 
570
897
  const req = getReq()
@@ -572,9 +899,16 @@ function ftruncate (fd, len, cb) {
572
899
  binding.ftruncate(req.handle, fd, len)
573
900
  }
574
901
 
575
- function chmod (filepath, mode, cb) {
902
+ function chmod(filepath, mode, cb) {
576
903
  if (typeof filepath !== 'string') {
577
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
904
+ throw typeError(
905
+ 'ERR_INVALID_ARG_TYPE',
906
+ 'Path must be a string. Received type ' +
907
+ typeof filepath +
908
+ ' (' +
909
+ filepath +
910
+ ')'
911
+ )
578
912
  }
579
913
 
580
914
  if (typeof mode === 'string') mode = modeToNumber(mode)
@@ -584,9 +918,16 @@ function chmod (filepath, mode, cb) {
584
918
  binding.chmod(req.handle, filepath, mode)
585
919
  }
586
920
 
587
- function chmodSync (filepath, mode) {
921
+ function chmodSync(filepath, mode) {
588
922
  if (typeof filepath !== 'string') {
589
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
923
+ throw typeError(
924
+ 'ERR_INVALID_ARG_TYPE',
925
+ 'Path must be a string. Received type ' +
926
+ typeof filepath +
927
+ ' (' +
928
+ filepath +
929
+ ')'
930
+ )
590
931
  }
591
932
 
592
933
  if (typeof mode === 'string') mode = modeToNumber(mode)
@@ -594,13 +935,24 @@ function chmodSync (filepath, mode) {
594
935
  binding.chmodSync(filepath, mode)
595
936
  }
596
937
 
597
- function fchmod (fd, mode, cb) {
938
+ function fchmod(fd, mode, cb) {
598
939
  if (typeof fd !== 'number') {
599
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
940
+ throw typeError(
941
+ 'ERR_INVALID_ARG_TYPE',
942
+ 'File descriptor must be a number. Received type ' +
943
+ typeof fd +
944
+ ' (' +
945
+ fd +
946
+ ')'
947
+ )
600
948
  }
601
949
 
602
950
  if (fd < 0 || fd > 0x7fffffff) {
603
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
951
+ throw typeError(
952
+ 'ERR_OUT_OF_RANGE',
953
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
954
+ fd
955
+ )
604
956
  }
605
957
 
606
958
  if (typeof mode === 'string') mode = modeToNumber(mode)
@@ -610,13 +962,24 @@ function fchmod (fd, mode, cb) {
610
962
  binding.fchmod(req.handle, fd, mode)
611
963
  }
612
964
 
613
- function fchmodSync (fd, mode) {
965
+ function fchmodSync(fd, mode) {
614
966
  if (typeof fd !== 'number') {
615
- throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
967
+ throw typeError(
968
+ 'ERR_INVALID_ARG_TYPE',
969
+ 'File descriptor must be a number. Received type ' +
970
+ typeof fd +
971
+ ' (' +
972
+ fd +
973
+ ')'
974
+ )
616
975
  }
617
976
 
618
977
  if (fd < 0 || fd > 0x7fffffff) {
619
- throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
978
+ throw typeError(
979
+ 'ERR_OUT_OF_RANGE',
980
+ 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' +
981
+ fd
982
+ )
620
983
  }
621
984
 
622
985
  if (typeof mode === 'string') mode = modeToNumber(mode)
@@ -624,7 +987,7 @@ function fchmodSync (fd, mode) {
624
987
  binding.fchmodSync(fd, mode)
625
988
  }
626
989
 
627
- function mkdirRecursive (filepath, mode, cb) {
990
+ function mkdirRecursive(filepath, mode, cb) {
628
991
  mkdir(filepath, { mode }, function (err) {
629
992
  if (err === null) return cb(null, 0, null)
630
993
 
@@ -657,16 +1020,30 @@ function mkdirRecursive (filepath, mode, cb) {
657
1020
  })
658
1021
  }
659
1022
 
660
- function mkdir (filepath, opts, cb) {
1023
+ function mkdir(filepath, opts, cb) {
661
1024
  if (typeof filepath !== 'string') {
662
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1025
+ throw typeError(
1026
+ 'ERR_INVALID_ARG_TYPE',
1027
+ 'Path must be a string. Received type ' +
1028
+ typeof filepath +
1029
+ ' (' +
1030
+ filepath +
1031
+ ')'
1032
+ )
663
1033
  }
664
1034
 
665
1035
  if (typeof opts === 'function') {
666
1036
  cb = opts
667
1037
  opts = { mode: 0o777 }
668
1038
  } else if (typeof cb !== 'function') {
669
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1039
+ throw typeError(
1040
+ 'ERR_INVALID_ARG_TYPE',
1041
+ 'Callback must be a function. Received type ' +
1042
+ typeof cb +
1043
+ ' (' +
1044
+ cb +
1045
+ ')'
1046
+ )
670
1047
  }
671
1048
 
672
1049
  if (typeof opts === 'number') opts = { mode: opts }
@@ -674,14 +1051,15 @@ function mkdir (filepath, opts, cb) {
674
1051
 
675
1052
  const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
676
1053
 
677
- if (opts.recursive) return mkdirRecursive(filepath.replace(/\//g, path.sep), mode, cb)
1054
+ if (opts.recursive)
1055
+ return mkdirRecursive(filepath.replace(/\//g, path.sep), mode, cb)
678
1056
 
679
1057
  const req = getReq()
680
1058
  req.callback = cb
681
1059
  binding.mkdir(req.handle, filepath, mode)
682
1060
  }
683
1061
 
684
- function mkdirRecursiveSync (filepath, mode) {
1062
+ function mkdirRecursiveSync(filepath, mode) {
685
1063
  try {
686
1064
  mkdirSync(filepath, { mode })
687
1065
  } catch (err) {
@@ -707,9 +1085,16 @@ function mkdirRecursiveSync (filepath, mode) {
707
1085
  }
708
1086
  }
709
1087
 
710
- function mkdirSync (filepath, opts) {
1088
+ function mkdirSync(filepath, opts) {
711
1089
  if (typeof filepath !== 'string') {
712
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1090
+ throw typeError(
1091
+ 'ERR_INVALID_ARG_TYPE',
1092
+ 'Path must be a string. Received type ' +
1093
+ typeof filepath +
1094
+ ' (' +
1095
+ filepath +
1096
+ ')'
1097
+ )
713
1098
  }
714
1099
 
715
1100
  if (typeof opts === 'number') opts = { mode: opts }
@@ -717,18 +1102,33 @@ function mkdirSync (filepath, opts) {
717
1102
 
718
1103
  const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
719
1104
 
720
- if (opts.recursive) return mkdirRecursiveSync(filepath.replace(/\//g, path.sep), mode)
1105
+ if (opts.recursive)
1106
+ return mkdirRecursiveSync(filepath.replace(/\//g, path.sep), mode)
721
1107
 
722
1108
  binding.mkdirSync(filepath, mode)
723
1109
  }
724
1110
 
725
- function rmdir (filepath, cb) {
1111
+ function rmdir(filepath, cb) {
726
1112
  if (typeof filepath !== 'string') {
727
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1113
+ throw typeError(
1114
+ 'ERR_INVALID_ARG_TYPE',
1115
+ 'Path must be a string. Received type ' +
1116
+ typeof filepath +
1117
+ ' (' +
1118
+ filepath +
1119
+ ')'
1120
+ )
728
1121
  }
729
1122
 
730
1123
  if (typeof cb !== 'function') {
731
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1124
+ throw typeError(
1125
+ 'ERR_INVALID_ARG_TYPE',
1126
+ 'Callback must be a function. Received type ' +
1127
+ typeof cb +
1128
+ ' (' +
1129
+ cb +
1130
+ ')'
1131
+ )
732
1132
  }
733
1133
 
734
1134
  const req = getReq()
@@ -736,15 +1136,22 @@ function rmdir (filepath, cb) {
736
1136
  binding.rmdir(req.handle, filepath)
737
1137
  }
738
1138
 
739
- function rmdirSync (filepath) {
1139
+ function rmdirSync(filepath) {
740
1140
  if (typeof filepath !== 'string') {
741
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1141
+ throw typeError(
1142
+ 'ERR_INVALID_ARG_TYPE',
1143
+ 'Path must be a string. Received type ' +
1144
+ typeof filepath +
1145
+ ' (' +
1146
+ filepath +
1147
+ ')'
1148
+ )
742
1149
  }
743
1150
 
744
1151
  binding.rmdirSync(filepath)
745
1152
  }
746
1153
 
747
- function rmRecursive (filepath, opts, cb) {
1154
+ function rmRecursive(filepath, opts, cb) {
748
1155
  rmdir(filepath, function (err) {
749
1156
  if (err === null) return cb(null)
750
1157
 
@@ -774,16 +1181,30 @@ function rmRecursive (filepath, opts, cb) {
774
1181
  })
775
1182
  }
776
1183
 
777
- function rm (filepath, opts, cb) {
1184
+ function rm(filepath, opts, cb) {
778
1185
  if (typeof filepath !== 'string') {
779
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1186
+ throw typeError(
1187
+ 'ERR_INVALID_ARG_TYPE',
1188
+ 'Path must be a string. Received type ' +
1189
+ typeof filepath +
1190
+ ' (' +
1191
+ filepath +
1192
+ ')'
1193
+ )
780
1194
  }
781
1195
 
782
1196
  if (typeof opts === 'function') {
783
1197
  cb = opts
784
1198
  opts = {}
785
1199
  } else if (typeof cb !== 'function') {
786
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1200
+ throw typeError(
1201
+ 'ERR_INVALID_ARG_TYPE',
1202
+ 'Callback must be a function. Received type ' +
1203
+ typeof cb +
1204
+ ' (' +
1205
+ cb +
1206
+ ')'
1207
+ )
787
1208
  }
788
1209
 
789
1210
  if (!opts) opts = {}
@@ -805,7 +1226,7 @@ function rm (filepath, opts, cb) {
805
1226
  })
806
1227
  }
807
1228
 
808
- function rmRecursiveSync (filepath, opts) {
1229
+ function rmRecursiveSync(filepath, opts) {
809
1230
  try {
810
1231
  rmdirSync(filepath)
811
1232
  } catch (err) {
@@ -821,9 +1242,16 @@ function rmRecursiveSync (filepath, opts) {
821
1242
  }
822
1243
  }
823
1244
 
824
- function rmSync (filepath, opts) {
1245
+ function rmSync(filepath, opts) {
825
1246
  if (typeof filepath !== 'string') {
826
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1247
+ throw typeError(
1248
+ 'ERR_INVALID_ARG_TYPE',
1249
+ 'Path must be a string. Received type ' +
1250
+ typeof filepath +
1251
+ ' (' +
1252
+ filepath +
1253
+ ')'
1254
+ )
827
1255
  }
828
1256
 
829
1257
  if (!opts) opts = {}
@@ -845,13 +1273,27 @@ function rmSync (filepath, opts) {
845
1273
  }
846
1274
  }
847
1275
 
848
- function unlink (filepath, cb) {
1276
+ function unlink(filepath, cb) {
849
1277
  if (typeof filepath !== 'string') {
850
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1278
+ throw typeError(
1279
+ 'ERR_INVALID_ARG_TYPE',
1280
+ 'Path must be a string. Received type ' +
1281
+ typeof filepath +
1282
+ ' (' +
1283
+ filepath +
1284
+ ')'
1285
+ )
851
1286
  }
852
1287
 
853
1288
  if (typeof cb !== 'function') {
854
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1289
+ throw typeError(
1290
+ 'ERR_INVALID_ARG_TYPE',
1291
+ 'Callback must be a function. Received type ' +
1292
+ typeof cb +
1293
+ ' (' +
1294
+ cb +
1295
+ ')'
1296
+ )
855
1297
  }
856
1298
 
857
1299
  const req = getReq()
@@ -859,25 +1301,45 @@ function unlink (filepath, cb) {
859
1301
  binding.unlink(req.handle, filepath)
860
1302
  }
861
1303
 
862
- function unlinkSync (filepath) {
1304
+ function unlinkSync(filepath) {
863
1305
  if (typeof filepath !== 'string') {
864
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1306
+ throw typeError(
1307
+ 'ERR_INVALID_ARG_TYPE',
1308
+ 'Path must be a string. Received type ' +
1309
+ typeof filepath +
1310
+ ' (' +
1311
+ filepath +
1312
+ ')'
1313
+ )
865
1314
  }
866
1315
 
867
1316
  binding.unlinkSync(filepath)
868
1317
  }
869
1318
 
870
- function rename (src, dst, cb) {
1319
+ function rename(src, dst, cb) {
871
1320
  if (typeof src !== 'string') {
872
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof src) + ' (' + src + ')')
1321
+ throw typeError(
1322
+ 'ERR_INVALID_ARG_TYPE',
1323
+ 'Path must be a string. Received type ' + typeof src + ' (' + src + ')'
1324
+ )
873
1325
  }
874
1326
 
875
1327
  if (typeof dst !== 'string') {
876
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof dst) + ' (' + dst + ')')
1328
+ throw typeError(
1329
+ 'ERR_INVALID_ARG_TYPE',
1330
+ 'Path must be a string. Received type ' + typeof dst + ' (' + dst + ')'
1331
+ )
877
1332
  }
878
1333
 
879
1334
  if (typeof cb !== 'function') {
880
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1335
+ throw typeError(
1336
+ 'ERR_INVALID_ARG_TYPE',
1337
+ 'Callback must be a function. Received type ' +
1338
+ typeof cb +
1339
+ ' (' +
1340
+ cb +
1341
+ ')'
1342
+ )
881
1343
  }
882
1344
 
883
1345
  const req = getReq()
@@ -885,30 +1347,42 @@ function rename (src, dst, cb) {
885
1347
  binding.rename(req.handle, src, dst)
886
1348
  }
887
1349
 
888
- function renameSync (src, dst) {
1350
+ function renameSync(src, dst) {
889
1351
  if (typeof src !== 'string') {
890
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof src) + ' (' + src + ')')
1352
+ throw typeError(
1353
+ 'ERR_INVALID_ARG_TYPE',
1354
+ 'Path must be a string. Received type ' + typeof src + ' (' + src + ')'
1355
+ )
891
1356
  }
892
1357
 
893
1358
  if (typeof dst !== 'string') {
894
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof dst) + ' (' + dst + ')')
1359
+ throw typeError(
1360
+ 'ERR_INVALID_ARG_TYPE',
1361
+ 'Path must be a string. Received type ' + typeof dst + ' (' + dst + ')'
1362
+ )
895
1363
  }
896
1364
 
897
1365
  binding.renameSync(src, dst)
898
1366
  }
899
1367
 
900
- function copyFile (src, dst, mode, cb) {
1368
+ function copyFile(src, dst, mode, cb) {
901
1369
  if (typeof mode === 'function') {
902
1370
  cb = mode
903
1371
  mode = 0
904
1372
  }
905
1373
 
906
1374
  if (typeof src !== 'string') {
907
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof src) + ' (' + src + ')')
1375
+ throw typeError(
1376
+ 'ERR_INVALID_ARG_TYPE',
1377
+ 'Path must be a string. Received type ' + typeof src + ' (' + src + ')'
1378
+ )
908
1379
  }
909
1380
 
910
1381
  if (typeof dst !== 'string') {
911
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof dst) + ' (' + dst + ')')
1382
+ throw typeError(
1383
+ 'ERR_INVALID_ARG_TYPE',
1384
+ 'Path must be a string. Received type ' + typeof dst + ' (' + dst + ')'
1385
+ )
912
1386
  }
913
1387
 
914
1388
  const req = getReq()
@@ -916,36 +1390,54 @@ function copyFile (src, dst, mode, cb) {
916
1390
  binding.copyfile(req.handle, src, dst, mode)
917
1391
  }
918
1392
 
919
- function copyFileSync (src, dst, mode = 0) {
1393
+ function copyFileSync(src, dst, mode = 0) {
920
1394
  if (typeof src !== 'string') {
921
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof src) + ' (' + src + ')')
1395
+ throw typeError(
1396
+ 'ERR_INVALID_ARG_TYPE',
1397
+ 'Path must be a string. Received type ' + typeof src + ' (' + src + ')'
1398
+ )
922
1399
  }
923
1400
 
924
1401
  if (typeof dst !== 'string') {
925
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof dst) + ' (' + dst + ')')
1402
+ throw typeError(
1403
+ 'ERR_INVALID_ARG_TYPE',
1404
+ 'Path must be a string. Received type ' + typeof dst + ' (' + dst + ')'
1405
+ )
926
1406
  }
927
1407
 
928
1408
  binding.copyfileSync(src, dst, mode)
929
1409
  }
930
1410
 
931
- function realpath (filepath, opts, cb) {
1411
+ function realpath(filepath, opts, cb) {
932
1412
  if (typeof filepath !== 'string') {
933
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1413
+ throw typeError(
1414
+ 'ERR_INVALID_ARG_TYPE',
1415
+ 'Path must be a string. Received type ' +
1416
+ typeof filepath +
1417
+ ' (' +
1418
+ filepath +
1419
+ ')'
1420
+ )
934
1421
  }
935
1422
 
936
1423
  if (typeof opts === 'function') {
937
1424
  cb = opts
938
1425
  opts = {}
939
1426
  } else if (typeof cb !== 'function') {
940
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1427
+ throw typeError(
1428
+ 'ERR_INVALID_ARG_TYPE',
1429
+ 'Callback must be a function. Received type ' +
1430
+ typeof cb +
1431
+ ' (' +
1432
+ cb +
1433
+ ')'
1434
+ )
941
1435
  }
942
1436
 
943
1437
  if (typeof opts === 'string') opts = { encoding: opts }
944
1438
  else if (!opts) opts = {}
945
1439
 
946
- const {
947
- encoding = 'utf8'
948
- } = opts
1440
+ const { encoding = 'utf8' } = opts
949
1441
 
950
1442
  const data = Buffer.allocUnsafe(binding.sizeofFSPath)
951
1443
 
@@ -961,17 +1453,22 @@ function realpath (filepath, opts, cb) {
961
1453
  binding.realpath(req.handle, filepath, data)
962
1454
  }
963
1455
 
964
- function realpathSync (filepath, opts) {
1456
+ function realpathSync(filepath, opts) {
965
1457
  if (typeof filepath !== 'string') {
966
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1458
+ throw typeError(
1459
+ 'ERR_INVALID_ARG_TYPE',
1460
+ 'Path must be a string. Received type ' +
1461
+ typeof filepath +
1462
+ ' (' +
1463
+ filepath +
1464
+ ')'
1465
+ )
967
1466
  }
968
1467
 
969
1468
  if (typeof opts === 'string') opts = { encoding: opts }
970
1469
  else if (!opts) opts = {}
971
1470
 
972
- const {
973
- encoding = 'utf8'
974
- } = opts
1471
+ const { encoding = 'utf8' } = opts
975
1472
 
976
1473
  const data = Buffer.allocUnsafe(binding.sizeofFSPath)
977
1474
 
@@ -982,24 +1479,36 @@ function realpathSync (filepath, opts) {
982
1479
  return filepath
983
1480
  }
984
1481
 
985
- function readlink (filepath, opts, cb) {
1482
+ function readlink(filepath, opts, cb) {
986
1483
  if (typeof filepath !== 'string') {
987
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1484
+ throw typeError(
1485
+ 'ERR_INVALID_ARG_TYPE',
1486
+ 'Path must be a string. Received type ' +
1487
+ typeof filepath +
1488
+ ' (' +
1489
+ filepath +
1490
+ ')'
1491
+ )
988
1492
  }
989
1493
 
990
1494
  if (typeof opts === 'function') {
991
1495
  cb = opts
992
1496
  opts = {}
993
1497
  } else if (typeof cb !== 'function') {
994
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1498
+ throw typeError(
1499
+ 'ERR_INVALID_ARG_TYPE',
1500
+ 'Callback must be a function. Received type ' +
1501
+ typeof cb +
1502
+ ' (' +
1503
+ cb +
1504
+ ')'
1505
+ )
995
1506
  }
996
1507
 
997
1508
  if (typeof opts === 'string') opts = { encoding: opts }
998
1509
  else if (!opts) opts = {}
999
1510
 
1000
- const {
1001
- encoding = 'utf8'
1002
- } = opts
1511
+ const { encoding = 'utf8' } = opts
1003
1512
 
1004
1513
  const data = Buffer.allocUnsafe(binding.sizeofFSPath)
1005
1514
 
@@ -1015,17 +1524,22 @@ function readlink (filepath, opts, cb) {
1015
1524
  binding.readlink(req.handle, filepath, data)
1016
1525
  }
1017
1526
 
1018
- function readlinkSync (filepath, opts) {
1527
+ function readlinkSync(filepath, opts) {
1019
1528
  if (typeof filepath !== 'string') {
1020
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1529
+ throw typeError(
1530
+ 'ERR_INVALID_ARG_TYPE',
1531
+ 'Path must be a string. Received type ' +
1532
+ typeof filepath +
1533
+ ' (' +
1534
+ filepath +
1535
+ ')'
1536
+ )
1021
1537
  }
1022
1538
 
1023
1539
  if (typeof opts === 'string') opts = { encoding: opts }
1024
1540
  else if (!opts) opts = {}
1025
1541
 
1026
- const {
1027
- encoding = 'utf8'
1028
- } = opts
1542
+ const { encoding = 'utf8' } = opts
1029
1543
 
1030
1544
  const data = Buffer.allocUnsafe(binding.sizeofFSPath)
1031
1545
 
@@ -1036,7 +1550,7 @@ function readlinkSync (filepath, opts) {
1036
1550
  return filepath
1037
1551
  }
1038
1552
 
1039
- function normalizeSymlinkTarget (target, type, filepath) {
1553
+ function normalizeSymlinkTarget(target, type, filepath) {
1040
1554
  if (isWindows) {
1041
1555
  if (type === 'junction') target = path.resolve(filepath, '..', target)
1042
1556
 
@@ -1048,20 +1562,41 @@ function normalizeSymlinkTarget (target, type, filepath) {
1048
1562
  return target
1049
1563
  }
1050
1564
 
1051
- function symlink (target, filepath, type, cb) {
1565
+ function symlink(target, filepath, type, cb) {
1052
1566
  if (typeof target !== 'string') {
1053
- throw typeError('ERR_INVALID_ARG_TYPE', 'Target must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1567
+ throw typeError(
1568
+ 'ERR_INVALID_ARG_TYPE',
1569
+ 'Target must be a string. Received type ' +
1570
+ typeof filepath +
1571
+ ' (' +
1572
+ filepath +
1573
+ ')'
1574
+ )
1054
1575
  }
1055
1576
 
1056
1577
  if (typeof filepath !== 'string') {
1057
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1578
+ throw typeError(
1579
+ 'ERR_INVALID_ARG_TYPE',
1580
+ 'Path must be a string. Received type ' +
1581
+ typeof filepath +
1582
+ ' (' +
1583
+ filepath +
1584
+ ')'
1585
+ )
1058
1586
  }
1059
1587
 
1060
1588
  if (typeof type === 'function') {
1061
1589
  cb = type
1062
1590
  type = null
1063
1591
  } else if (typeof cb !== 'function') {
1064
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1592
+ throw typeError(
1593
+ 'ERR_INVALID_ARG_TYPE',
1594
+ 'Callback must be a function. Received type ' +
1595
+ typeof cb +
1596
+ ' (' +
1597
+ cb +
1598
+ ')'
1599
+ )
1065
1600
  }
1066
1601
 
1067
1602
  if (typeof type === 'string') {
@@ -1076,14 +1611,22 @@ function symlink (target, filepath, type, cb) {
1076
1611
  type = constants.UV_FS_SYMLINK_JUNCTION
1077
1612
  break
1078
1613
  default:
1079
- throw typeError('ERR_FS_INVALID_SYMLINK_TYPE', 'Symlink type must be one of "dir", "file", or "junction". Received "' + type + '"')
1614
+ throw typeError(
1615
+ 'ERR_FS_INVALID_SYMLINK_TYPE',
1616
+ 'Symlink type must be one of "dir", "file", or "junction". Received "' +
1617
+ type +
1618
+ '"'
1619
+ )
1080
1620
  }
1081
1621
  } else if (typeof type !== 'number') {
1082
1622
  if (isWindows) {
1083
1623
  target = path.resolve(filepath, '..', target)
1084
1624
 
1085
1625
  stat(target, (err, st) => {
1086
- type = err === null && st.isDirectory() ? constants.UV_FS_SYMLINK_DIR : constants.UV_FS_SYMLINK_JUNCTION
1626
+ type =
1627
+ err === null && st.isDirectory()
1628
+ ? constants.UV_FS_SYMLINK_DIR
1629
+ : constants.UV_FS_SYMLINK_JUNCTION
1087
1630
 
1088
1631
  symlink(target, filepath, type, cb)
1089
1632
  })
@@ -1096,16 +1639,35 @@ function symlink (target, filepath, type, cb) {
1096
1639
 
1097
1640
  const req = getReq()
1098
1641
  req.callback = cb
1099
- binding.symlink(req.handle, normalizeSymlinkTarget(target), path.toNamespacedPath(filepath), type)
1642
+ binding.symlink(
1643
+ req.handle,
1644
+ normalizeSymlinkTarget(target),
1645
+ path.toNamespacedPath(filepath),
1646
+ type
1647
+ )
1100
1648
  }
1101
1649
 
1102
- function symlinkSync (target, filepath, type) {
1650
+ function symlinkSync(target, filepath, type) {
1103
1651
  if (typeof target !== 'string') {
1104
- throw typeError('ERR_INVALID_ARG_TYPE', 'Target must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1652
+ throw typeError(
1653
+ 'ERR_INVALID_ARG_TYPE',
1654
+ 'Target must be a string. Received type ' +
1655
+ typeof filepath +
1656
+ ' (' +
1657
+ filepath +
1658
+ ')'
1659
+ )
1105
1660
  }
1106
1661
 
1107
1662
  if (typeof filepath !== 'string') {
1108
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1663
+ throw typeError(
1664
+ 'ERR_INVALID_ARG_TYPE',
1665
+ 'Path must be a string. Received type ' +
1666
+ typeof filepath +
1667
+ ' (' +
1668
+ filepath +
1669
+ ')'
1670
+ )
1109
1671
  }
1110
1672
 
1111
1673
  if (typeof type === 'string') {
@@ -1120,31 +1682,56 @@ function symlinkSync (target, filepath, type) {
1120
1682
  type = constants.UV_FS_SYMLINK_JUNCTION
1121
1683
  break
1122
1684
  default:
1123
- throw typeError('ERR_FS_INVALID_SYMLINK_TYPE', 'Symlink type must be one of "dir", "file", or "junction". Received "' + type + '"')
1685
+ throw typeError(
1686
+ 'ERR_FS_INVALID_SYMLINK_TYPE',
1687
+ 'Symlink type must be one of "dir", "file", or "junction". Received "' +
1688
+ type +
1689
+ '"'
1690
+ )
1124
1691
  }
1125
1692
  } else if (typeof type !== 'number') {
1126
1693
  if (isWindows) {
1127
1694
  target = path.resolve(filepath, '..', target)
1128
1695
 
1129
- type = statSync(target).isDirectory() ? constants.UV_FS_SYMLINK_DIR : constants.UV_FS_SYMLINK_JUNCTION
1696
+ type = statSync(target).isDirectory()
1697
+ ? constants.UV_FS_SYMLINK_DIR
1698
+ : constants.UV_FS_SYMLINK_JUNCTION
1130
1699
  } else {
1131
1700
  type = 0
1132
1701
  }
1133
1702
  }
1134
1703
 
1135
- binding.symlinkSync(normalizeSymlinkTarget(target), path.toNamespacedPath(filepath), type)
1704
+ binding.symlinkSync(
1705
+ normalizeSymlinkTarget(target),
1706
+ path.toNamespacedPath(filepath),
1707
+ type
1708
+ )
1136
1709
  }
1137
1710
 
1138
- function opendir (filepath, opts, cb) {
1711
+ function opendir(filepath, opts, cb) {
1139
1712
  if (typeof filepath !== 'string') {
1140
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1713
+ throw typeError(
1714
+ 'ERR_INVALID_ARG_TYPE',
1715
+ 'Path must be a string. Received type ' +
1716
+ typeof filepath +
1717
+ ' (' +
1718
+ filepath +
1719
+ ')'
1720
+ )
1141
1721
  }
1142
1722
 
1143
1723
  if (typeof opts === 'function') {
1144
1724
  cb = opts
1145
1725
  opts = {}
1146
1726
  } else if (typeof cb !== 'function') {
1147
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1727
+ throw typeError(
1728
+ 'ERR_INVALID_ARG_TYPE',
1729
+ 'Callback must be a function. Received type ' +
1730
+ typeof cb +
1731
+ ' (' +
1732
+ cb +
1733
+ ')'
1734
+ )
1148
1735
  }
1149
1736
 
1150
1737
  if (typeof opts === 'string') opts = { encoding: opts }
@@ -1162,9 +1749,16 @@ function opendir (filepath, opts, cb) {
1162
1749
  binding.opendir(req.handle, filepath, data)
1163
1750
  }
1164
1751
 
1165
- function opendirSync (filepath, opts) {
1752
+ function opendirSync(filepath, opts) {
1166
1753
  if (typeof filepath !== 'string') {
1167
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1754
+ throw typeError(
1755
+ 'ERR_INVALID_ARG_TYPE',
1756
+ 'Path must be a string. Received type ' +
1757
+ typeof filepath +
1758
+ ' (' +
1759
+ filepath +
1760
+ ')'
1761
+ )
1168
1762
  }
1169
1763
 
1170
1764
  if (typeof opts === 'string') opts = { encoding: opts }
@@ -1175,24 +1769,36 @@ function opendirSync (filepath, opts) {
1175
1769
  return new Dir(filepath, data, opts)
1176
1770
  }
1177
1771
 
1178
- function readdir (filepath, opts, cb) {
1772
+ function readdir(filepath, opts, cb) {
1179
1773
  if (typeof filepath !== 'string') {
1180
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1774
+ throw typeError(
1775
+ 'ERR_INVALID_ARG_TYPE',
1776
+ 'Path must be a string. Received type ' +
1777
+ typeof filepath +
1778
+ ' (' +
1779
+ filepath +
1780
+ ')'
1781
+ )
1181
1782
  }
1182
1783
 
1183
1784
  if (typeof opts === 'function') {
1184
1785
  cb = opts
1185
1786
  opts = {}
1186
1787
  } else if (typeof cb !== 'function') {
1187
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1788
+ throw typeError(
1789
+ 'ERR_INVALID_ARG_TYPE',
1790
+ 'Callback must be a function. Received type ' +
1791
+ typeof cb +
1792
+ ' (' +
1793
+ cb +
1794
+ ')'
1795
+ )
1188
1796
  }
1189
1797
 
1190
1798
  if (typeof opts === 'string') opts = { encoding: opts }
1191
1799
  else if (!opts) opts = {}
1192
1800
 
1193
- const {
1194
- withFileTypes = false
1195
- } = opts
1801
+ const { withFileTypes = false } = opts
1196
1802
 
1197
1803
  opendir(filepath, opts, async (err, dir) => {
1198
1804
  if (err) return cb(err, null)
@@ -1204,17 +1810,22 @@ function readdir (filepath, opts, cb) {
1204
1810
  })
1205
1811
  }
1206
1812
 
1207
- function readdirSync (filepath, opts) {
1813
+ function readdirSync(filepath, opts) {
1208
1814
  if (typeof filepath !== 'string') {
1209
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1815
+ throw typeError(
1816
+ 'ERR_INVALID_ARG_TYPE',
1817
+ 'Path must be a string. Received type ' +
1818
+ typeof filepath +
1819
+ ' (' +
1820
+ filepath +
1821
+ ')'
1822
+ )
1210
1823
  }
1211
1824
 
1212
1825
  if (typeof opts === 'string') opts = { encoding: opts }
1213
1826
  else if (!opts) opts = {}
1214
1827
 
1215
- const {
1216
- withFileTypes = false
1217
- } = opts
1828
+ const { withFileTypes = false } = opts
1218
1829
 
1219
1830
  const dir = opendirSync(filepath, opts)
1220
1831
  const result = []
@@ -1228,24 +1839,36 @@ function readdirSync (filepath, opts) {
1228
1839
  return result
1229
1840
  }
1230
1841
 
1231
- function readFile (filepath, opts, cb) {
1842
+ function readFile(filepath, opts, cb) {
1232
1843
  if (typeof filepath !== 'string') {
1233
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1844
+ throw typeError(
1845
+ 'ERR_INVALID_ARG_TYPE',
1846
+ 'Path must be a string. Received type ' +
1847
+ typeof filepath +
1848
+ ' (' +
1849
+ filepath +
1850
+ ')'
1851
+ )
1234
1852
  }
1235
1853
 
1236
1854
  if (typeof opts === 'function') {
1237
1855
  cb = opts
1238
1856
  opts = {}
1239
1857
  } else if (typeof cb !== 'function') {
1240
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1858
+ throw typeError(
1859
+ 'ERR_INVALID_ARG_TYPE',
1860
+ 'Callback must be a function. Received type ' +
1861
+ typeof cb +
1862
+ ' (' +
1863
+ cb +
1864
+ ')'
1865
+ )
1241
1866
  }
1242
1867
 
1243
1868
  if (typeof opts === 'string') opts = { encoding: opts }
1244
1869
  else if (!opts) opts = {}
1245
1870
 
1246
- const {
1247
- encoding = 'buffer'
1248
- } = opts
1871
+ const { encoding = 'buffer' } = opts
1249
1872
 
1250
1873
  open(filepath, opts.flag || 'r', function (err, fd) {
1251
1874
  if (err) return cb(err)
@@ -1258,14 +1881,14 @@ function readFile (filepath, opts, cb) {
1258
1881
 
1259
1882
  read(fd, buffer, loop)
1260
1883
 
1261
- function loop (err, r) {
1884
+ function loop(err, r) {
1262
1885
  if (err) return closeAndError(err)
1263
1886
  len += r
1264
1887
  if (r === 0 || len === buffer.byteLength) return done()
1265
1888
  read(fd, buffer.subarray(len), loop)
1266
1889
  }
1267
1890
 
1268
- function done () {
1891
+ function done() {
1269
1892
  if (len !== buffer.byteLength) buffer = buffer.subarray(0, len)
1270
1893
  close(fd, function (err) {
1271
1894
  if (err) return cb(err)
@@ -1275,7 +1898,7 @@ function readFile (filepath, opts, cb) {
1275
1898
  }
1276
1899
  })
1277
1900
 
1278
- function closeAndError (err) {
1901
+ function closeAndError(err) {
1279
1902
  close(fd, function () {
1280
1903
  cb(err)
1281
1904
  })
@@ -1283,17 +1906,22 @@ function readFile (filepath, opts, cb) {
1283
1906
  })
1284
1907
  }
1285
1908
 
1286
- function readFileSync (filepath, opts) {
1909
+ function readFileSync(filepath, opts) {
1287
1910
  if (typeof filepath !== 'string') {
1288
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1911
+ throw typeError(
1912
+ 'ERR_INVALID_ARG_TYPE',
1913
+ 'Path must be a string. Received type ' +
1914
+ typeof filepath +
1915
+ ' (' +
1916
+ filepath +
1917
+ ')'
1918
+ )
1289
1919
  }
1290
1920
 
1291
1921
  if (typeof opts === 'string') opts = { encoding: opts }
1292
1922
  else if (!opts) opts = {}
1293
1923
 
1294
- const {
1295
- encoding = 'buffer'
1296
- } = opts
1924
+ const { encoding = 'buffer' } = opts
1297
1925
 
1298
1926
  const fd = openSync(filepath, opts.flag || 'r')
1299
1927
 
@@ -1319,20 +1947,41 @@ function readFileSync (filepath, opts) {
1319
1947
  }
1320
1948
  }
1321
1949
 
1322
- function writeFile (filepath, data, opts, cb) {
1950
+ function writeFile(filepath, data, opts, cb) {
1323
1951
  if (typeof filepath !== 'string') {
1324
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1325
- }
1326
-
1327
- if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
1328
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
1952
+ throw typeError(
1953
+ 'ERR_INVALID_ARG_TYPE',
1954
+ 'Path must be a string. Received type ' +
1955
+ typeof filepath +
1956
+ ' (' +
1957
+ filepath +
1958
+ ')'
1959
+ )
1960
+ }
1961
+
1962
+ if (
1963
+ typeof data !== 'string' &&
1964
+ !Buffer.isBuffer(data) &&
1965
+ !ArrayBuffer.isView(data)
1966
+ ) {
1967
+ throw typeError(
1968
+ 'ERR_INVALID_ARG_TYPE',
1969
+ 'Data must be a string or buffer. Received type ' + typeof data
1970
+ )
1329
1971
  }
1330
1972
 
1331
1973
  if (typeof opts === 'function') {
1332
1974
  cb = opts
1333
1975
  opts = {}
1334
1976
  } else if (typeof cb !== 'function') {
1335
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
1977
+ throw typeError(
1978
+ 'ERR_INVALID_ARG_TYPE',
1979
+ 'Callback must be a function. Received type ' +
1980
+ typeof cb +
1981
+ ' (' +
1982
+ cb +
1983
+ ')'
1984
+ )
1336
1985
  }
1337
1986
 
1338
1987
  if (typeof opts === 'string') opts = { encoding: opts }
@@ -1345,20 +1994,20 @@ function writeFile (filepath, data, opts, cb) {
1345
1994
 
1346
1995
  write(fd, data, loop)
1347
1996
 
1348
- function loop (err, w) {
1997
+ function loop(err, w) {
1349
1998
  if (err) return closeAndError(err)
1350
1999
  if (w === data.byteLength) return done()
1351
2000
  write(fd, data.subarray(w), loop)
1352
2001
  }
1353
2002
 
1354
- function done () {
2003
+ function done() {
1355
2004
  close(fd, function (err) {
1356
2005
  if (err) return cb(err)
1357
2006
  return cb(null)
1358
2007
  })
1359
2008
  }
1360
2009
 
1361
- function closeAndError (err) {
2010
+ function closeAndError(err) {
1362
2011
  close(fd, function () {
1363
2012
  cb(err)
1364
2013
  })
@@ -1366,13 +2015,27 @@ function writeFile (filepath, data, opts, cb) {
1366
2015
  })
1367
2016
  }
1368
2017
 
1369
- function writeFileSync (filepath, data, opts) {
2018
+ function writeFileSync(filepath, data, opts) {
1370
2019
  if (typeof filepath !== 'string') {
1371
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1372
- }
1373
-
1374
- if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
1375
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
2020
+ throw typeError(
2021
+ 'ERR_INVALID_ARG_TYPE',
2022
+ 'Path must be a string. Received type ' +
2023
+ typeof filepath +
2024
+ ' (' +
2025
+ filepath +
2026
+ ')'
2027
+ )
2028
+ }
2029
+
2030
+ if (
2031
+ typeof data !== 'string' &&
2032
+ !Buffer.isBuffer(data) &&
2033
+ !ArrayBuffer.isView(data)
2034
+ ) {
2035
+ throw typeError(
2036
+ 'ERR_INVALID_ARG_TYPE',
2037
+ 'Data must be a string or buffer. Received type ' + typeof data
2038
+ )
1376
2039
  }
1377
2040
 
1378
2041
  if (typeof opts === 'string') opts = { encoding: opts }
@@ -1396,20 +2059,41 @@ function writeFileSync (filepath, data, opts) {
1396
2059
  }
1397
2060
  }
1398
2061
 
1399
- function appendFile (filepath, data, opts, cb) {
2062
+ function appendFile(filepath, data, opts, cb) {
1400
2063
  if (typeof filepath !== 'string') {
1401
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1402
- }
1403
-
1404
- if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
1405
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
2064
+ throw typeError(
2065
+ 'ERR_INVALID_ARG_TYPE',
2066
+ 'Path must be a string. Received type ' +
2067
+ typeof filepath +
2068
+ ' (' +
2069
+ filepath +
2070
+ ')'
2071
+ )
2072
+ }
2073
+
2074
+ if (
2075
+ typeof data !== 'string' &&
2076
+ !Buffer.isBuffer(data) &&
2077
+ !ArrayBuffer.isView(data)
2078
+ ) {
2079
+ throw typeError(
2080
+ 'ERR_INVALID_ARG_TYPE',
2081
+ 'Data must be a string or buffer. Received type ' + typeof data
2082
+ )
1406
2083
  }
1407
2084
 
1408
2085
  if (typeof opts === 'function') {
1409
2086
  cb = opts
1410
2087
  opts = {}
1411
2088
  } else if (typeof cb !== 'function') {
1412
- throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
2089
+ throw typeError(
2090
+ 'ERR_INVALID_ARG_TYPE',
2091
+ 'Callback must be a function. Received type ' +
2092
+ typeof cb +
2093
+ ' (' +
2094
+ cb +
2095
+ ')'
2096
+ )
1413
2097
  }
1414
2098
 
1415
2099
  if (typeof opts === 'string') opts = { encoding: opts }
@@ -1422,13 +2106,27 @@ function appendFile (filepath, data, opts, cb) {
1422
2106
  return writeFile(filepath, data, opts, cb)
1423
2107
  }
1424
2108
 
1425
- function appendFileSync (filepath, data, opts) {
2109
+ function appendFileSync(filepath, data, opts) {
1426
2110
  if (typeof filepath !== 'string') {
1427
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
1428
- }
1429
-
1430
- if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
1431
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
2111
+ throw typeError(
2112
+ 'ERR_INVALID_ARG_TYPE',
2113
+ 'Path must be a string. Received type ' +
2114
+ typeof filepath +
2115
+ ' (' +
2116
+ filepath +
2117
+ ')'
2118
+ )
2119
+ }
2120
+
2121
+ if (
2122
+ typeof data !== 'string' &&
2123
+ !Buffer.isBuffer(data) &&
2124
+ !ArrayBuffer.isView(data)
2125
+ ) {
2126
+ throw typeError(
2127
+ 'ERR_INVALID_ARG_TYPE',
2128
+ 'Data must be a string or buffer. Received type ' + typeof data
2129
+ )
1432
2130
  }
1433
2131
 
1434
2132
  if (typeof opts === 'string') opts = { encoding: opts }
@@ -1441,9 +2139,16 @@ function appendFileSync (filepath, data, opts) {
1441
2139
  return writeFileSync(filepath, data, opts)
1442
2140
  }
1443
2141
 
1444
- function watch (filepath, opts, cb) {
2142
+ function watch(filepath, opts, cb) {
1445
2143
  if (typeof filepath !== 'string') {
1446
- throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof filepath) + ' (' + filepath + ')')
2144
+ throw typeError(
2145
+ 'ERR_INVALID_ARG_TYPE',
2146
+ 'Path must be a string. Received type ' +
2147
+ typeof filepath +
2148
+ ' (' +
2149
+ filepath +
2150
+ ')'
2151
+ )
1447
2152
  }
1448
2153
 
1449
2154
  if (typeof opts === 'function') {
@@ -1460,7 +2165,22 @@ function watch (filepath, opts, cb) {
1460
2165
  }
1461
2166
 
1462
2167
  class Stats {
1463
- constructor (dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs) {
2168
+ constructor(
2169
+ dev,
2170
+ mode,
2171
+ nlink,
2172
+ uid,
2173
+ gid,
2174
+ rdev,
2175
+ blksize,
2176
+ ino,
2177
+ size,
2178
+ blocks,
2179
+ atimeMs,
2180
+ mtimeMs,
2181
+ ctimeMs,
2182
+ birthtimeMs
2183
+ ) {
1464
2184
  this.dev = dev
1465
2185
  this.mode = mode
1466
2186
  this.nlink = nlink
@@ -1481,41 +2201,38 @@ class Stats {
1481
2201
  this.birthtime = new Date(birthtimeMs)
1482
2202
  }
1483
2203
 
1484
- isDirectory () {
2204
+ isDirectory() {
1485
2205
  return (this.mode & constants.S_IFMT) === constants.S_IFDIR
1486
2206
  }
1487
2207
 
1488
- isFile () {
2208
+ isFile() {
1489
2209
  return (this.mode & constants.S_IFMT) === constants.S_IFREG
1490
2210
  }
1491
2211
 
1492
- isBlockDevice () {
2212
+ isBlockDevice() {
1493
2213
  return (this.mode & constants.S_IFMT) === constants.S_IFBLK
1494
2214
  }
1495
2215
 
1496
- isCharacterDevice () {
2216
+ isCharacterDevice() {
1497
2217
  return (this.mode & constants.S_IFCHR) === constants.S_IFCHR
1498
2218
  }
1499
2219
 
1500
- isFIFO () {
2220
+ isFIFO() {
1501
2221
  return (this.mode & constants.S_IFMT) === constants.S_IFIFO
1502
2222
  }
1503
2223
 
1504
- isSymbolicLink () {
2224
+ isSymbolicLink() {
1505
2225
  return (this.mode & constants.S_IFMT) === constants.S_IFLNK
1506
2226
  }
1507
2227
 
1508
- isSocket () {
2228
+ isSocket() {
1509
2229
  return (this.mode & constants.S_IFMT) === constants.S_IFSOCK
1510
2230
  }
1511
2231
  }
1512
2232
 
1513
2233
  class Dir {
1514
- constructor (path, handle, opts = {}) {
1515
- const {
1516
- encoding = 'utf8',
1517
- bufferSize = 32
1518
- } = opts
2234
+ constructor(path, handle, opts = {}) {
2235
+ const { encoding = 'utf8', bufferSize = 32 } = opts
1519
2236
 
1520
2237
  this._handle = handle
1521
2238
  this._dirents = Buffer.allocUnsafe(binding.sizeofFSDirent * bufferSize)
@@ -1526,10 +2243,11 @@ class Dir {
1526
2243
  this.path = path
1527
2244
  }
1528
2245
 
1529
- read (cb) {
2246
+ read(cb) {
1530
2247
  if (!cb) return promisify(this.read.bind(this))
1531
2248
 
1532
- if (this._buffer.length) return queueMicrotask(() => cb(null, this._buffer.shift()))
2249
+ if (this._buffer.length)
2250
+ return queueMicrotask(() => cb(null, this._buffer.shift()))
1533
2251
  if (this._ended) return queueMicrotask(() => cb(null, null))
1534
2252
 
1535
2253
  const data = []
@@ -1553,7 +2271,7 @@ class Dir {
1553
2271
  binding.readdir(req.handle, this._handle, this._dirents, data)
1554
2272
  }
1555
2273
 
1556
- readSync () {
2274
+ readSync() {
1557
2275
  if (this._buffer.length) return this._buffer.shift()
1558
2276
  if (this._ended) return null
1559
2277
 
@@ -1574,7 +2292,7 @@ class Dir {
1574
2292
  return this._buffer.shift()
1575
2293
  }
1576
2294
 
1577
- close (cb) {
2295
+ close(cb) {
1578
2296
  if (!cb) return promisify(this.close.bind(this))
1579
2297
 
1580
2298
  const req = getReq()
@@ -1587,12 +2305,12 @@ class Dir {
1587
2305
  binding.closedir(req.handle, this._handle)
1588
2306
  }
1589
2307
 
1590
- closeSync () {
2308
+ closeSync() {
1591
2309
  binding.closedirSync(this._handle)
1592
2310
  this._handle = null
1593
2311
  }
1594
2312
 
1595
- [Symbol.iterator] () {
2313
+ [Symbol.iterator]() {
1596
2314
  return {
1597
2315
  next: () => {
1598
2316
  if (this._buffer.length) {
@@ -1616,69 +2334,70 @@ class Dir {
1616
2334
  }
1617
2335
  }
1618
2336
 
1619
- [Symbol.asyncIterator] () {
2337
+ [Symbol.asyncIterator]() {
1620
2338
  return {
1621
- next: () => new Promise((resolve, reject) => {
1622
- if (this._buffer.length) {
1623
- return resolve({ done: false, value: this._buffer.shift() })
1624
- }
2339
+ next: () =>
2340
+ new Promise((resolve, reject) => {
2341
+ if (this._buffer.length) {
2342
+ return resolve({ done: false, value: this._buffer.shift() })
2343
+ }
1625
2344
 
1626
- if (this._ended) {
1627
- return resolve({ done: true })
1628
- }
2345
+ if (this._ended) {
2346
+ return resolve({ done: true })
2347
+ }
1629
2348
 
1630
- this.read((err, entry) => {
1631
- if (err) return reject(err)
2349
+ this.read((err, entry) => {
2350
+ if (err) return reject(err)
1632
2351
 
1633
- if (entry) {
1634
- return resolve({ done: false, value: entry })
1635
- }
2352
+ if (entry) {
2353
+ return resolve({ done: false, value: entry })
2354
+ }
1636
2355
 
1637
- this.close((err) => err ? reject(err) : resolve({ done: true }))
2356
+ this.close((err) => (err ? reject(err) : resolve({ done: true })))
2357
+ })
1638
2358
  })
1639
- })
1640
2359
  }
1641
2360
  }
1642
2361
  }
1643
2362
 
1644
2363
  class Dirent {
1645
- constructor (path, name, type) {
2364
+ constructor(path, name, type) {
1646
2365
  this.type = type
1647
2366
  this.path = path
1648
2367
  this.name = name
1649
2368
  }
1650
2369
 
1651
- isFile () {
2370
+ isFile() {
1652
2371
  return this.type === constants.UV_DIRENT_FILE
1653
2372
  }
1654
2373
 
1655
- isDirectory () {
2374
+ isDirectory() {
1656
2375
  return this.type === constants.UV_DIRENT_DIR
1657
2376
  }
1658
2377
 
1659
- isSymbolicLink () {
2378
+ isSymbolicLink() {
1660
2379
  return this.type === constants.UV_DIRENT_LINK
1661
2380
  }
1662
2381
 
1663
- isFIFO () {
2382
+ isFIFO() {
1664
2383
  return this.type === constants.UV_DIRENT_FIFO
1665
2384
  }
1666
2385
 
1667
- isSocket () {
2386
+ isSocket() {
1668
2387
  return this.type === constants.UV_DIRENT_SOCKET
1669
2388
  }
1670
2389
 
1671
- isCharacterDevice () {
2390
+ isCharacterDevice() {
1672
2391
  return this.type === constants.UV_DIRENT_CHAR
1673
2392
  }
1674
2393
 
1675
- isBlockDevice () {
2394
+ isBlockDevice() {
1676
2395
  return this.type === constants.UV_DIRENT_BLOCK
1677
2396
  }
1678
2397
  }
1679
2398
 
1680
2399
  class FileWriteStream extends Writable {
1681
- constructor (path, opts = {}) {
2400
+ constructor(path, opts = {}) {
1682
2401
  super({ map })
1683
2402
 
1684
2403
  this.path = path
@@ -1687,7 +2406,7 @@ class FileWriteStream extends Writable {
1687
2406
  this.mode = opts.mode || 0o666
1688
2407
  }
1689
2408
 
1690
- _open (cb) {
2409
+ _open(cb) {
1691
2410
  open(this.path, this.flags, this.mode, (err, fd) => {
1692
2411
  if (err) return cb(err)
1693
2412
  this.fd = fd
@@ -1695,18 +2414,22 @@ class FileWriteStream extends Writable {
1695
2414
  })
1696
2415
  }
1697
2416
 
1698
- _writev (batch, cb) {
1699
- writev(this.fd, batch.map(({ chunk }) => chunk), cb)
2417
+ _writev(batch, cb) {
2418
+ writev(
2419
+ this.fd,
2420
+ batch.map(({ chunk }) => chunk),
2421
+ cb
2422
+ )
1700
2423
  }
1701
2424
 
1702
- _destroy (err, cb) {
2425
+ _destroy(err, cb) {
1703
2426
  if (!this.fd) return cb(err)
1704
2427
  close(this.fd, () => cb(err))
1705
2428
  }
1706
2429
  }
1707
2430
 
1708
2431
  class FileReadStream extends Readable {
1709
- constructor (path, opts = {}) {
2432
+ constructor(path, opts = {}) {
1710
2433
  super()
1711
2434
 
1712
2435
  this.path = path
@@ -1715,12 +2438,16 @@ class FileReadStream extends Readable {
1715
2438
  this._offset = opts.start || 0
1716
2439
  this._missing = 0
1717
2440
 
1718
- if (opts.length) this._missing = opts.length
1719
- else if (typeof opts.end === 'number') this._missing = opts.end - this._offset + 1
1720
- else this._missing = -1
2441
+ if (opts.length) {
2442
+ this._missing = opts.length
2443
+ } else if (typeof opts.end === 'number') {
2444
+ this._missing = opts.end - this._offset + 1
2445
+ } else {
2446
+ this._missing = -1
2447
+ }
1721
2448
  }
1722
2449
 
1723
- _open (cb) {
2450
+ _open(cb) {
1724
2451
  open(this.path, constants.O_RDONLY, (err, fd) => {
1725
2452
  if (err) return cb(err)
1726
2453
 
@@ -1728,7 +2455,8 @@ class FileReadStream extends Readable {
1728
2455
 
1729
2456
  fstat(fd, (err, st) => {
1730
2457
  if (err) return onerror(err)
1731
- if (!st.isFile()) return onerror(new Error(this.path + ' is not a file'))
2458
+ if (!st.isFile())
2459
+ return onerror(new Error(this.path + ' is not a file'))
1732
2460
 
1733
2461
  this.fd = fd
1734
2462
  if (this._missing === -1) this._missing = st.size
@@ -1748,7 +2476,7 @@ class FileReadStream extends Readable {
1748
2476
  })
1749
2477
  }
1750
2478
 
1751
- _read (size) {
2479
+ _read(size) {
1752
2480
  if (!this._missing) {
1753
2481
  this.push(null)
1754
2482
  return
@@ -1772,37 +2500,40 @@ class FileReadStream extends Readable {
1772
2500
  })
1773
2501
  }
1774
2502
 
1775
- _destroy (err, cb) {
2503
+ _destroy(err, cb) {
1776
2504
  if (!this.fd) return cb(err)
1777
2505
  close(this.fd, () => cb(err))
1778
2506
  }
1779
2507
  }
1780
2508
 
1781
2509
  class Watcher extends EventEmitter {
1782
- constructor (path, opts) {
1783
- const {
1784
- persistent = true,
1785
- recursive = false,
1786
- encoding = 'utf8'
1787
- } = opts
2510
+ constructor(path, opts) {
2511
+ const { persistent = true, recursive = false, encoding = 'utf8' } = opts
1788
2512
 
1789
2513
  super()
1790
2514
 
1791
2515
  this._closed = false
1792
2516
  this._encoding = encoding
1793
- this._handle = binding.watcherInit(path, recursive, this, this._onevent, this._onclose)
2517
+ this._handle = binding.watcherInit(
2518
+ path,
2519
+ recursive,
2520
+ this,
2521
+ this._onevent,
2522
+ this._onclose
2523
+ )
1794
2524
 
1795
2525
  if (!persistent) this.unref()
1796
2526
  }
1797
2527
 
1798
- _onevent (err, events, filename) {
2528
+ _onevent(err, events, filename) {
1799
2529
  if (err) {
1800
2530
  this.close()
1801
2531
  this.emit('error', err)
1802
2532
  } else {
1803
- const path = this._encoding === 'buffer'
1804
- ? Buffer.from(filename)
1805
- : Buffer.from(filename).toString(this._encoding)
2533
+ const path =
2534
+ this._encoding === 'buffer'
2535
+ ? Buffer.from(filename)
2536
+ : Buffer.from(filename).toString(this._encoding)
1806
2537
 
1807
2538
  if (events & binding.UV_RENAME) {
1808
2539
  this.emit('change', 'rename', path)
@@ -1814,44 +2545,43 @@ class Watcher extends EventEmitter {
1814
2545
  }
1815
2546
  }
1816
2547
 
1817
- _onclose () {
2548
+ _onclose() {
1818
2549
  this._handle = null
1819
2550
 
1820
2551
  this.emit('close')
1821
2552
  }
1822
2553
 
1823
- close () {
2554
+ close() {
1824
2555
  if (this._closed) return
1825
2556
  this._closed = true
1826
2557
 
1827
2558
  binding.watcherClose(this._handle)
1828
2559
  }
1829
2560
 
1830
- ref () {
2561
+ ref() {
1831
2562
  if (this._handle) binding.watcherRef(this._handle)
1832
2563
  return this
1833
2564
  }
1834
2565
 
1835
- unref () {
2566
+ unref() {
1836
2567
  if (this._handle) binding.watcherUnref(this._handle)
1837
2568
  return this
1838
2569
  }
1839
2570
 
1840
- [Symbol.asyncIterator] () {
2571
+ [Symbol.asyncIterator]() {
1841
2572
  const buffer = []
1842
2573
  let done = false
1843
2574
  let error = null
1844
2575
  let next = null
1845
2576
 
1846
- this
1847
- .on('change', (eventType, filename) => {
1848
- if (next) {
1849
- next.resolve({ done: false, value: { eventType, filename } })
1850
- next = null
1851
- } else {
1852
- buffer.push({ eventType, filename })
1853
- }
1854
- })
2577
+ this.on('change', (eventType, filename) => {
2578
+ if (next) {
2579
+ next.resolve({ done: false, value: { eventType, filename } })
2580
+ next = null
2581
+ } else {
2582
+ buffer.push({ eventType, filename })
2583
+ }
2584
+ })
1855
2585
  .on('error', (err) => {
1856
2586
  done = true
1857
2587
  error = err
@@ -1871,28 +2601,30 @@ class Watcher extends EventEmitter {
1871
2601
  })
1872
2602
 
1873
2603
  return {
1874
- next: () => new Promise((resolve, reject) => {
1875
- if (error) return reject(error)
2604
+ next: () =>
2605
+ new Promise((resolve, reject) => {
2606
+ if (error) return reject(error)
1876
2607
 
1877
- if (buffer.length) return resolve({ done: false, value: buffer.shift() })
2608
+ if (buffer.length)
2609
+ return resolve({ done: false, value: buffer.shift() })
1878
2610
 
1879
- if (done) return resolve({ done })
2611
+ if (done) return resolve({ done })
1880
2612
 
1881
- next = { resolve, reject }
1882
- })
2613
+ next = { resolve, reject }
2614
+ })
1883
2615
  }
1884
2616
  }
1885
2617
  }
1886
2618
 
1887
2619
  exports.promises = {}
1888
2620
 
1889
- function typeError (code, message) {
2621
+ function typeError(code, message) {
1890
2622
  const error = new TypeError(message)
1891
2623
  error.code = code
1892
2624
  return error
1893
2625
  }
1894
2626
 
1895
- function noop () {}
2627
+ function noop() {}
1896
2628
 
1897
2629
  exports.access = access
1898
2630
  exports.appendFile = appendFile
@@ -1977,16 +2709,16 @@ exports.Dirent = Dirent
1977
2709
  exports.Watcher = Watcher
1978
2710
 
1979
2711
  exports.ReadStream = FileReadStream
1980
- exports.createReadStream = function createReadStream (path, opts) {
2712
+ exports.createReadStream = function createReadStream(path, opts) {
1981
2713
  return new FileReadStream(path, opts)
1982
2714
  }
1983
2715
 
1984
2716
  exports.WriteStream = FileWriteStream
1985
- exports.createWriteStream = function createWriteStream (path, opts) {
2717
+ exports.createWriteStream = function createWriteStream(path, opts) {
1986
2718
  return new FileWriteStream(path, opts)
1987
2719
  }
1988
2720
 
1989
- function promisify (fn) {
2721
+ function promisify(fn) {
1990
2722
  return function (...args) {
1991
2723
  return new Promise((resolve, reject) => {
1992
2724
  fn(...args, function (err, res) {
@@ -1997,6 +2729,6 @@ function promisify (fn) {
1997
2729
  }
1998
2730
  }
1999
2731
 
2000
- function map (data) {
2732
+ function map(data) {
2001
2733
  return typeof data === 'string' ? Buffer.from(data) : data
2002
2734
  }