bare-fs 1.6.0 → 1.6.1
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/binding.c +21 -21
- package/index.js +37 -137
- package/package.json +1 -1
package/binding.c
CHANGED
|
@@ -93,13 +93,15 @@ on_fs_stat_response (uv_fs_t *uv_req) {
|
|
|
93
93
|
err = js_get_reference_value(env, req->data, &data);
|
|
94
94
|
assert(err == 0);
|
|
95
95
|
|
|
96
|
+
uint32_t i = 0;
|
|
97
|
+
|
|
96
98
|
#define V(property) \
|
|
97
99
|
{ \
|
|
98
100
|
js_value_t *value; \
|
|
99
101
|
err = js_create_int64(env, uv_req->statbuf.st_##property, &value); \
|
|
100
102
|
assert(err == 0); \
|
|
101
103
|
\
|
|
102
|
-
err =
|
|
104
|
+
err = js_set_element(env, data, i++, value); \
|
|
103
105
|
assert(err == 0); \
|
|
104
106
|
}
|
|
105
107
|
V(dev)
|
|
@@ -108,12 +110,10 @@ on_fs_stat_response (uv_fs_t *uv_req) {
|
|
|
108
110
|
V(uid)
|
|
109
111
|
V(gid)
|
|
110
112
|
V(rdev)
|
|
113
|
+
V(blksize)
|
|
111
114
|
V(ino)
|
|
112
115
|
V(size)
|
|
113
|
-
V(blksize)
|
|
114
116
|
V(blocks)
|
|
115
|
-
V(flags)
|
|
116
|
-
V(gen)
|
|
117
117
|
#undef V
|
|
118
118
|
|
|
119
119
|
#define V(property) \
|
|
@@ -124,7 +124,7 @@ on_fs_stat_response (uv_fs_t *uv_req) {
|
|
|
124
124
|
err = js_create_int64(env, time.tv_sec * 1e3 + time.tv_nsec / 1e6, &value); \
|
|
125
125
|
assert(err == 0); \
|
|
126
126
|
\
|
|
127
|
-
err =
|
|
127
|
+
err = js_set_element(env, data, i++, value); \
|
|
128
128
|
assert(err == 0); \
|
|
129
129
|
}
|
|
130
130
|
V(atim)
|
|
@@ -210,7 +210,7 @@ on_fs_readdir_response (uv_fs_t *uv_req) {
|
|
|
210
210
|
|
|
211
211
|
js_value_t *name;
|
|
212
212
|
void *data;
|
|
213
|
-
err = js_create_arraybuffer(env, strlen(dirent->name)
|
|
213
|
+
err = js_create_arraybuffer(env, strlen(dirent->name) + 1 /* NULL */, &data, &name);
|
|
214
214
|
assert(err == 0);
|
|
215
215
|
|
|
216
216
|
strcpy(data, dirent->name);
|
|
@@ -924,13 +924,15 @@ bare_fs_stat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
924
924
|
uv_fs_stat(loop, &req, (char *) path, NULL);
|
|
925
925
|
|
|
926
926
|
if (req.result == 0) {
|
|
927
|
+
uint32_t i = 0;
|
|
928
|
+
|
|
927
929
|
#define V(property) \
|
|
928
930
|
{ \
|
|
929
931
|
js_value_t *value; \
|
|
930
932
|
err = js_create_int64(env, req.statbuf.st_##property, &value); \
|
|
931
933
|
assert(err == 0); \
|
|
932
934
|
\
|
|
933
|
-
err =
|
|
935
|
+
err = js_set_element(env, data, i++, value); \
|
|
934
936
|
assert(err == 0); \
|
|
935
937
|
}
|
|
936
938
|
V(dev)
|
|
@@ -939,12 +941,10 @@ bare_fs_stat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
939
941
|
V(uid)
|
|
940
942
|
V(gid)
|
|
941
943
|
V(rdev)
|
|
944
|
+
V(blksize)
|
|
942
945
|
V(ino)
|
|
943
946
|
V(size)
|
|
944
|
-
V(blksize)
|
|
945
947
|
V(blocks)
|
|
946
|
-
V(flags)
|
|
947
|
-
V(gen)
|
|
948
948
|
#undef V
|
|
949
949
|
|
|
950
950
|
#define V(property) \
|
|
@@ -955,7 +955,7 @@ bare_fs_stat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
955
955
|
err = js_create_int64(env, time.tv_sec * 1e3 + time.tv_nsec / 1e6, &value); \
|
|
956
956
|
assert(err == 0); \
|
|
957
957
|
\
|
|
958
|
-
err =
|
|
958
|
+
err = js_set_element(env, data, i++, value); \
|
|
959
959
|
assert(err == 0); \
|
|
960
960
|
}
|
|
961
961
|
V(atim)
|
|
@@ -1030,13 +1030,15 @@ bare_fs_lstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1030
1030
|
uv_fs_lstat(loop, &req, (char *) path, NULL);
|
|
1031
1031
|
|
|
1032
1032
|
if (req.result == 0) {
|
|
1033
|
+
uint32_t i = 0;
|
|
1034
|
+
|
|
1033
1035
|
#define V(property) \
|
|
1034
1036
|
{ \
|
|
1035
1037
|
js_value_t *value; \
|
|
1036
1038
|
err = js_create_int64(env, req.statbuf.st_##property, &value); \
|
|
1037
1039
|
assert(err == 0); \
|
|
1038
1040
|
\
|
|
1039
|
-
err =
|
|
1041
|
+
err = js_set_element(env, data, i++, value); \
|
|
1040
1042
|
assert(err == 0); \
|
|
1041
1043
|
}
|
|
1042
1044
|
V(dev)
|
|
@@ -1045,12 +1047,10 @@ bare_fs_lstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1045
1047
|
V(uid)
|
|
1046
1048
|
V(gid)
|
|
1047
1049
|
V(rdev)
|
|
1050
|
+
V(blksize)
|
|
1048
1051
|
V(ino)
|
|
1049
1052
|
V(size)
|
|
1050
|
-
V(blksize)
|
|
1051
1053
|
V(blocks)
|
|
1052
|
-
V(flags)
|
|
1053
|
-
V(gen)
|
|
1054
1054
|
#undef V
|
|
1055
1055
|
|
|
1056
1056
|
#define V(property) \
|
|
@@ -1061,7 +1061,7 @@ bare_fs_lstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1061
1061
|
err = js_create_int64(env, time.tv_sec * 1e3 + time.tv_nsec / 1e6, &value); \
|
|
1062
1062
|
assert(err == 0); \
|
|
1063
1063
|
\
|
|
1064
|
-
err =
|
|
1064
|
+
err = js_set_element(env, data, i++, value); \
|
|
1065
1065
|
assert(err == 0); \
|
|
1066
1066
|
}
|
|
1067
1067
|
V(atim)
|
|
@@ -1136,13 +1136,15 @@ bare_fs_fstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1136
1136
|
uv_fs_fstat(loop, &req, fd, NULL);
|
|
1137
1137
|
|
|
1138
1138
|
if (req.result == 0) {
|
|
1139
|
+
uint32_t i = 0;
|
|
1140
|
+
|
|
1139
1141
|
#define V(property) \
|
|
1140
1142
|
{ \
|
|
1141
1143
|
js_value_t *value; \
|
|
1142
1144
|
err = js_create_int64(env, req.statbuf.st_##property, &value); \
|
|
1143
1145
|
assert(err == 0); \
|
|
1144
1146
|
\
|
|
1145
|
-
err =
|
|
1147
|
+
err = js_set_element(env, data, i++, value); \
|
|
1146
1148
|
assert(err == 0); \
|
|
1147
1149
|
}
|
|
1148
1150
|
V(dev)
|
|
@@ -1151,12 +1153,10 @@ bare_fs_fstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1151
1153
|
V(uid)
|
|
1152
1154
|
V(gid)
|
|
1153
1155
|
V(rdev)
|
|
1156
|
+
V(blksize)
|
|
1154
1157
|
V(ino)
|
|
1155
1158
|
V(size)
|
|
1156
|
-
V(blksize)
|
|
1157
1159
|
V(blocks)
|
|
1158
|
-
V(flags)
|
|
1159
|
-
V(gen)
|
|
1160
1160
|
#undef V
|
|
1161
1161
|
|
|
1162
1162
|
#define V(property) \
|
|
@@ -1167,7 +1167,7 @@ bare_fs_fstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1167
1167
|
err = js_create_int64(env, time.tv_sec * 1e3 + time.tv_nsec / 1e6, &value); \
|
|
1168
1168
|
assert(err == 0); \
|
|
1169
1169
|
\
|
|
1170
|
-
err =
|
|
1170
|
+
err = js_set_element(env, data, i++, value); \
|
|
1171
1171
|
assert(err == 0); \
|
|
1172
1172
|
}
|
|
1173
1173
|
V(atim)
|
package/index.js
CHANGED
|
@@ -377,30 +377,13 @@ function stat (path, cb) {
|
|
|
377
377
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
-
const data =
|
|
381
|
-
dev: 0,
|
|
382
|
-
mode: 0,
|
|
383
|
-
nlink: 0,
|
|
384
|
-
uid: 0,
|
|
385
|
-
gid: 0,
|
|
386
|
-
rdev: 0,
|
|
387
|
-
ino: 0,
|
|
388
|
-
size: 0,
|
|
389
|
-
blksize: 0,
|
|
390
|
-
blocks: 0,
|
|
391
|
-
flags: 0,
|
|
392
|
-
gen: 0,
|
|
393
|
-
atim: 0,
|
|
394
|
-
mtim: 0,
|
|
395
|
-
ctim: 0,
|
|
396
|
-
birthtim: 0
|
|
397
|
-
}
|
|
380
|
+
const data = new Array(Stats.length)
|
|
398
381
|
|
|
399
382
|
const req = getReq()
|
|
400
383
|
|
|
401
384
|
req.callback = function (err, _) {
|
|
402
385
|
if (err) cb(err, null)
|
|
403
|
-
else cb(null, new Stats(data))
|
|
386
|
+
else cb(null, new Stats(...data))
|
|
404
387
|
}
|
|
405
388
|
|
|
406
389
|
binding.stat(req.handle, path, data)
|
|
@@ -411,29 +394,12 @@ function statSync (path) {
|
|
|
411
394
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
|
|
412
395
|
}
|
|
413
396
|
|
|
414
|
-
const data =
|
|
415
|
-
dev: 0,
|
|
416
|
-
mode: 0,
|
|
417
|
-
nlink: 0,
|
|
418
|
-
uid: 0,
|
|
419
|
-
gid: 0,
|
|
420
|
-
rdev: 0,
|
|
421
|
-
ino: 0,
|
|
422
|
-
size: 0,
|
|
423
|
-
blksize: 0,
|
|
424
|
-
blocks: 0,
|
|
425
|
-
flags: 0,
|
|
426
|
-
gen: 0,
|
|
427
|
-
atim: 0,
|
|
428
|
-
mtim: 0,
|
|
429
|
-
ctim: 0,
|
|
430
|
-
birthtim: 0
|
|
431
|
-
}
|
|
397
|
+
const data = new Array(Stats.length)
|
|
432
398
|
|
|
433
399
|
const res = binding.statSync(path, data)
|
|
434
400
|
if (res < 0) throw createError(res)
|
|
435
401
|
|
|
436
|
-
return new Stats(data)
|
|
402
|
+
return new Stats(...data)
|
|
437
403
|
}
|
|
438
404
|
|
|
439
405
|
function lstat (path, cb) {
|
|
@@ -445,30 +411,13 @@ function lstat (path, cb) {
|
|
|
445
411
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
|
|
446
412
|
}
|
|
447
413
|
|
|
448
|
-
const data =
|
|
449
|
-
dev: 0,
|
|
450
|
-
mode: 0,
|
|
451
|
-
nlink: 0,
|
|
452
|
-
uid: 0,
|
|
453
|
-
gid: 0,
|
|
454
|
-
rdev: 0,
|
|
455
|
-
ino: 0,
|
|
456
|
-
size: 0,
|
|
457
|
-
blksize: 0,
|
|
458
|
-
blocks: 0,
|
|
459
|
-
flags: 0,
|
|
460
|
-
gen: 0,
|
|
461
|
-
atim: 0,
|
|
462
|
-
mtim: 0,
|
|
463
|
-
ctim: 0,
|
|
464
|
-
birthtim: 0
|
|
465
|
-
}
|
|
414
|
+
const data = new Array(Stats.length)
|
|
466
415
|
|
|
467
416
|
const req = getReq()
|
|
468
417
|
|
|
469
418
|
req.callback = function (err, _) {
|
|
470
419
|
if (err) cb(err, null)
|
|
471
|
-
else cb(null, new Stats(data))
|
|
420
|
+
else cb(null, new Stats(...data))
|
|
472
421
|
}
|
|
473
422
|
|
|
474
423
|
binding.lstat(req.handle, path, data)
|
|
@@ -479,29 +428,12 @@ function lstatSync (path) {
|
|
|
479
428
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
|
|
480
429
|
}
|
|
481
430
|
|
|
482
|
-
const data =
|
|
483
|
-
dev: 0,
|
|
484
|
-
mode: 0,
|
|
485
|
-
nlink: 0,
|
|
486
|
-
uid: 0,
|
|
487
|
-
gid: 0,
|
|
488
|
-
rdev: 0,
|
|
489
|
-
ino: 0,
|
|
490
|
-
size: 0,
|
|
491
|
-
blksize: 0,
|
|
492
|
-
blocks: 0,
|
|
493
|
-
flags: 0,
|
|
494
|
-
gen: 0,
|
|
495
|
-
atim: 0,
|
|
496
|
-
mtim: 0,
|
|
497
|
-
ctim: 0,
|
|
498
|
-
birthtim: 0
|
|
499
|
-
}
|
|
431
|
+
const data = new Array(Stats.length)
|
|
500
432
|
|
|
501
433
|
const res = binding.lstatSync(path, data)
|
|
502
434
|
if (res < 0) throw createError(res)
|
|
503
435
|
|
|
504
|
-
return new Stats(data)
|
|
436
|
+
return new Stats(...data)
|
|
505
437
|
}
|
|
506
438
|
|
|
507
439
|
function fstat (fd, cb) {
|
|
@@ -517,30 +449,13 @@ function fstat (fd, cb) {
|
|
|
517
449
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
|
|
518
450
|
}
|
|
519
451
|
|
|
520
|
-
const data =
|
|
521
|
-
dev: 0,
|
|
522
|
-
mode: 0,
|
|
523
|
-
nlink: 0,
|
|
524
|
-
uid: 0,
|
|
525
|
-
gid: 0,
|
|
526
|
-
rdev: 0,
|
|
527
|
-
ino: 0,
|
|
528
|
-
size: 0,
|
|
529
|
-
blksize: 0,
|
|
530
|
-
blocks: 0,
|
|
531
|
-
flags: 0,
|
|
532
|
-
gen: 0,
|
|
533
|
-
atim: 0,
|
|
534
|
-
mtim: 0,
|
|
535
|
-
ctim: 0,
|
|
536
|
-
birthtim: 0
|
|
537
|
-
}
|
|
452
|
+
const data = new Array(Stats.length)
|
|
538
453
|
|
|
539
454
|
const req = getReq()
|
|
540
455
|
|
|
541
456
|
req.callback = function (err, _) {
|
|
542
457
|
if (err) cb(err, null)
|
|
543
|
-
else cb(null, new Stats(data))
|
|
458
|
+
else cb(null, new Stats(...data))
|
|
544
459
|
}
|
|
545
460
|
|
|
546
461
|
binding.fstat(req.handle, fd, data)
|
|
@@ -555,29 +470,12 @@ function fstatSync (fd) {
|
|
|
555
470
|
throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
|
|
556
471
|
}
|
|
557
472
|
|
|
558
|
-
const data =
|
|
559
|
-
dev: 0,
|
|
560
|
-
mode: 0,
|
|
561
|
-
nlink: 0,
|
|
562
|
-
uid: 0,
|
|
563
|
-
gid: 0,
|
|
564
|
-
rdev: 0,
|
|
565
|
-
ino: 0,
|
|
566
|
-
size: 0,
|
|
567
|
-
blksize: 0,
|
|
568
|
-
blocks: 0,
|
|
569
|
-
flags: 0,
|
|
570
|
-
gen: 0,
|
|
571
|
-
atim: 0,
|
|
572
|
-
mtim: 0,
|
|
573
|
-
ctim: 0,
|
|
574
|
-
birthtim: 0
|
|
575
|
-
}
|
|
473
|
+
const data = new Array(Stats.length)
|
|
576
474
|
|
|
577
475
|
const res = binding.fstatSync(fd, data)
|
|
578
476
|
if (res < 0) throw createError(res)
|
|
579
477
|
|
|
580
|
-
return new Stats(data)
|
|
478
|
+
return new Stats(...data)
|
|
581
479
|
}
|
|
582
480
|
|
|
583
481
|
function ftruncate (fd, len, cb) {
|
|
@@ -770,11 +668,15 @@ function readdir (path, opts, cb) {
|
|
|
770
668
|
if (typeof opts === 'string') opts = { encoding: opts }
|
|
771
669
|
if (!opts) opts = {}
|
|
772
670
|
|
|
671
|
+
const {
|
|
672
|
+
withFileTypes = false
|
|
673
|
+
} = opts
|
|
674
|
+
|
|
773
675
|
opendir(path, opts, async (err, dir) => {
|
|
774
676
|
if (err) return cb(err, null)
|
|
775
677
|
const result = []
|
|
776
678
|
dir
|
|
777
|
-
.on('data', (entry) => result.push(entry))
|
|
679
|
+
.on('data', (entry) => result.push(withFileTypes ? entry : entry.name))
|
|
778
680
|
.on('error', (err) => cb(err, null))
|
|
779
681
|
.on('end', () => cb(null, result))
|
|
780
682
|
})
|
|
@@ -949,27 +851,25 @@ function writeFileSync (path, data, opts) {
|
|
|
949
851
|
}
|
|
950
852
|
|
|
951
853
|
class Stats {
|
|
952
|
-
constructor (
|
|
953
|
-
this.dev =
|
|
954
|
-
this.mode =
|
|
955
|
-
this.nlink =
|
|
956
|
-
this.uid =
|
|
957
|
-
this.gid =
|
|
958
|
-
this.rdev =
|
|
959
|
-
this.
|
|
960
|
-
this.
|
|
961
|
-
this.
|
|
962
|
-
this.blocks =
|
|
963
|
-
this.
|
|
964
|
-
this.
|
|
965
|
-
this.
|
|
966
|
-
this.
|
|
967
|
-
this.
|
|
968
|
-
this.
|
|
969
|
-
this.
|
|
970
|
-
this.
|
|
971
|
-
this.ctime = new Date(props.ctim)
|
|
972
|
-
this.birthtime = new Date(props.birthtim)
|
|
854
|
+
constructor (dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs) {
|
|
855
|
+
this.dev = dev
|
|
856
|
+
this.mode = mode
|
|
857
|
+
this.nlink = nlink
|
|
858
|
+
this.uid = uid
|
|
859
|
+
this.gid = gid
|
|
860
|
+
this.rdev = rdev
|
|
861
|
+
this.blksize = blksize
|
|
862
|
+
this.ino = ino
|
|
863
|
+
this.size = size
|
|
864
|
+
this.blocks = blocks
|
|
865
|
+
this.atimeMs = atimeMs
|
|
866
|
+
this.mtimeMs = mtimeMs
|
|
867
|
+
this.ctimeMs = ctimeMs
|
|
868
|
+
this.birthtimeMs = birthtimeMs
|
|
869
|
+
this.atime = new Date(atimeMs)
|
|
870
|
+
this.mtime = new Date(mtimeMs)
|
|
871
|
+
this.ctime = new Date(ctimeMs)
|
|
872
|
+
this.birthtime = new Date(birthtimeMs)
|
|
973
873
|
}
|
|
974
874
|
|
|
975
875
|
isDirectory () {
|
|
@@ -1148,7 +1048,7 @@ class Dir extends Readable {
|
|
|
1148
1048
|
else this.close(cb)
|
|
1149
1049
|
}
|
|
1150
1050
|
|
|
1151
|
-
close (cb) {
|
|
1051
|
+
close (cb = noop) {
|
|
1152
1052
|
if (this._closed) return
|
|
1153
1053
|
|
|
1154
1054
|
const self = this
|