bare-fs 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.c +24 -22
- 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)
|
|
@@ -208,12 +208,14 @@ on_fs_readdir_response (uv_fs_t *uv_req) {
|
|
|
208
208
|
err = js_set_element(env, data, i, entry);
|
|
209
209
|
assert(err == 0);
|
|
210
210
|
|
|
211
|
+
size_t name_len = strlen(dirent->name);
|
|
212
|
+
|
|
211
213
|
js_value_t *name;
|
|
212
214
|
void *data;
|
|
213
|
-
err = js_create_arraybuffer(env,
|
|
215
|
+
err = js_create_arraybuffer(env, name_len, &data, &name);
|
|
214
216
|
assert(err == 0);
|
|
215
217
|
|
|
216
|
-
|
|
218
|
+
memcpy(data, dirent->name, name_len);
|
|
217
219
|
|
|
218
220
|
err = js_set_named_property(env, entry, "name", name);
|
|
219
221
|
assert(err == 0);
|
|
@@ -924,13 +926,15 @@ bare_fs_stat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
924
926
|
uv_fs_stat(loop, &req, (char *) path, NULL);
|
|
925
927
|
|
|
926
928
|
if (req.result == 0) {
|
|
929
|
+
uint32_t i = 0;
|
|
930
|
+
|
|
927
931
|
#define V(property) \
|
|
928
932
|
{ \
|
|
929
933
|
js_value_t *value; \
|
|
930
934
|
err = js_create_int64(env, req.statbuf.st_##property, &value); \
|
|
931
935
|
assert(err == 0); \
|
|
932
936
|
\
|
|
933
|
-
err =
|
|
937
|
+
err = js_set_element(env, data, i++, value); \
|
|
934
938
|
assert(err == 0); \
|
|
935
939
|
}
|
|
936
940
|
V(dev)
|
|
@@ -939,12 +943,10 @@ bare_fs_stat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
939
943
|
V(uid)
|
|
940
944
|
V(gid)
|
|
941
945
|
V(rdev)
|
|
946
|
+
V(blksize)
|
|
942
947
|
V(ino)
|
|
943
948
|
V(size)
|
|
944
|
-
V(blksize)
|
|
945
949
|
V(blocks)
|
|
946
|
-
V(flags)
|
|
947
|
-
V(gen)
|
|
948
950
|
#undef V
|
|
949
951
|
|
|
950
952
|
#define V(property) \
|
|
@@ -955,7 +957,7 @@ bare_fs_stat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
955
957
|
err = js_create_int64(env, time.tv_sec * 1e3 + time.tv_nsec / 1e6, &value); \
|
|
956
958
|
assert(err == 0); \
|
|
957
959
|
\
|
|
958
|
-
err =
|
|
960
|
+
err = js_set_element(env, data, i++, value); \
|
|
959
961
|
assert(err == 0); \
|
|
960
962
|
}
|
|
961
963
|
V(atim)
|
|
@@ -1030,13 +1032,15 @@ bare_fs_lstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1030
1032
|
uv_fs_lstat(loop, &req, (char *) path, NULL);
|
|
1031
1033
|
|
|
1032
1034
|
if (req.result == 0) {
|
|
1035
|
+
uint32_t i = 0;
|
|
1036
|
+
|
|
1033
1037
|
#define V(property) \
|
|
1034
1038
|
{ \
|
|
1035
1039
|
js_value_t *value; \
|
|
1036
1040
|
err = js_create_int64(env, req.statbuf.st_##property, &value); \
|
|
1037
1041
|
assert(err == 0); \
|
|
1038
1042
|
\
|
|
1039
|
-
err =
|
|
1043
|
+
err = js_set_element(env, data, i++, value); \
|
|
1040
1044
|
assert(err == 0); \
|
|
1041
1045
|
}
|
|
1042
1046
|
V(dev)
|
|
@@ -1045,12 +1049,10 @@ bare_fs_lstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1045
1049
|
V(uid)
|
|
1046
1050
|
V(gid)
|
|
1047
1051
|
V(rdev)
|
|
1052
|
+
V(blksize)
|
|
1048
1053
|
V(ino)
|
|
1049
1054
|
V(size)
|
|
1050
|
-
V(blksize)
|
|
1051
1055
|
V(blocks)
|
|
1052
|
-
V(flags)
|
|
1053
|
-
V(gen)
|
|
1054
1056
|
#undef V
|
|
1055
1057
|
|
|
1056
1058
|
#define V(property) \
|
|
@@ -1061,7 +1063,7 @@ bare_fs_lstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1061
1063
|
err = js_create_int64(env, time.tv_sec * 1e3 + time.tv_nsec / 1e6, &value); \
|
|
1062
1064
|
assert(err == 0); \
|
|
1063
1065
|
\
|
|
1064
|
-
err =
|
|
1066
|
+
err = js_set_element(env, data, i++, value); \
|
|
1065
1067
|
assert(err == 0); \
|
|
1066
1068
|
}
|
|
1067
1069
|
V(atim)
|
|
@@ -1136,13 +1138,15 @@ bare_fs_fstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1136
1138
|
uv_fs_fstat(loop, &req, fd, NULL);
|
|
1137
1139
|
|
|
1138
1140
|
if (req.result == 0) {
|
|
1141
|
+
uint32_t i = 0;
|
|
1142
|
+
|
|
1139
1143
|
#define V(property) \
|
|
1140
1144
|
{ \
|
|
1141
1145
|
js_value_t *value; \
|
|
1142
1146
|
err = js_create_int64(env, req.statbuf.st_##property, &value); \
|
|
1143
1147
|
assert(err == 0); \
|
|
1144
1148
|
\
|
|
1145
|
-
err =
|
|
1149
|
+
err = js_set_element(env, data, i++, value); \
|
|
1146
1150
|
assert(err == 0); \
|
|
1147
1151
|
}
|
|
1148
1152
|
V(dev)
|
|
@@ -1151,12 +1155,10 @@ bare_fs_fstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1151
1155
|
V(uid)
|
|
1152
1156
|
V(gid)
|
|
1153
1157
|
V(rdev)
|
|
1158
|
+
V(blksize)
|
|
1154
1159
|
V(ino)
|
|
1155
1160
|
V(size)
|
|
1156
|
-
V(blksize)
|
|
1157
1161
|
V(blocks)
|
|
1158
|
-
V(flags)
|
|
1159
|
-
V(gen)
|
|
1160
1162
|
#undef V
|
|
1161
1163
|
|
|
1162
1164
|
#define V(property) \
|
|
@@ -1167,7 +1169,7 @@ bare_fs_fstat_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
1167
1169
|
err = js_create_int64(env, time.tv_sec * 1e3 + time.tv_nsec / 1e6, &value); \
|
|
1168
1170
|
assert(err == 0); \
|
|
1169
1171
|
\
|
|
1170
|
-
err =
|
|
1172
|
+
err = js_set_element(env, data, i++, value); \
|
|
1171
1173
|
assert(err == 0); \
|
|
1172
1174
|
}
|
|
1173
1175
|
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
|