bare-fs 1.8.0 → 1.9.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/README.md +7 -0
- package/binding.c +255 -166
- package/index.js +96 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ const fs = require('bare-fs')
|
|
|
15
15
|
|
|
16
16
|
fs.chmod
|
|
17
17
|
fs.close
|
|
18
|
+
fs.chmod
|
|
18
19
|
fs.fstat
|
|
19
20
|
fs.ftruncate
|
|
20
21
|
fs.lstat
|
|
@@ -55,12 +56,18 @@ fs.createWriteStream
|
|
|
55
56
|
|
|
56
57
|
fs.chmodSync
|
|
57
58
|
fs.closeSync
|
|
59
|
+
fs.fchmodSync
|
|
58
60
|
fs.fstatSync
|
|
59
61
|
fs.lstatSync
|
|
62
|
+
fs.mkdirSync
|
|
60
63
|
fs.openSync
|
|
61
64
|
fs.readSync
|
|
65
|
+
fs.readlinkSync
|
|
66
|
+
fs.renameSync
|
|
67
|
+
fs.rmdirSync
|
|
62
68
|
fs.statSync
|
|
63
69
|
fs.symlinkSync
|
|
70
|
+
fs.unlinkSync
|
|
64
71
|
fs.writeSync
|
|
65
72
|
|
|
66
73
|
fs.readFileSync
|
package/binding.c
CHANGED
|
@@ -882,6 +882,73 @@ bare_fs_chmod_sync (js_env_t *env, js_callback_info_t *info) {
|
|
|
882
882
|
return NULL;
|
|
883
883
|
}
|
|
884
884
|
|
|
885
|
+
static js_value_t *
|
|
886
|
+
bare_fs_fchmod (js_env_t *env, js_callback_info_t *info) {
|
|
887
|
+
int err;
|
|
888
|
+
|
|
889
|
+
size_t argc = 3;
|
|
890
|
+
js_value_t *argv[3];
|
|
891
|
+
|
|
892
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
893
|
+
assert(err == 0);
|
|
894
|
+
|
|
895
|
+
assert(argc == 3);
|
|
896
|
+
|
|
897
|
+
bare_fs_req_t *req;
|
|
898
|
+
err = js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
|
|
899
|
+
assert(err == 0);
|
|
900
|
+
|
|
901
|
+
uint32_t fd;
|
|
902
|
+
err = js_get_value_uint32(env, argv[1], &fd);
|
|
903
|
+
assert(err == 0);
|
|
904
|
+
|
|
905
|
+
int32_t mode;
|
|
906
|
+
err = js_get_value_int32(env, argv[2], &mode);
|
|
907
|
+
assert(err == 0);
|
|
908
|
+
|
|
909
|
+
uv_loop_t *loop;
|
|
910
|
+
js_get_env_loop(env, &loop);
|
|
911
|
+
|
|
912
|
+
uv_fs_fchmod(loop, (uv_fs_t *) req, fd, mode, on_fs_response);
|
|
913
|
+
|
|
914
|
+
return NULL;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
static js_value_t *
|
|
918
|
+
bare_fs_fchmod_sync (js_env_t *env, js_callback_info_t *info) {
|
|
919
|
+
int err;
|
|
920
|
+
|
|
921
|
+
size_t argc = 2;
|
|
922
|
+
js_value_t *argv[2];
|
|
923
|
+
|
|
924
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
925
|
+
assert(err == 0);
|
|
926
|
+
|
|
927
|
+
assert(argc == 2);
|
|
928
|
+
|
|
929
|
+
uint32_t fd;
|
|
930
|
+
err = js_get_value_uint32(env, argv[0], &fd);
|
|
931
|
+
assert(err == 0);
|
|
932
|
+
|
|
933
|
+
int32_t mode;
|
|
934
|
+
err = js_get_value_int32(env, argv[1], &mode);
|
|
935
|
+
assert(err == 0);
|
|
936
|
+
|
|
937
|
+
uv_loop_t *loop;
|
|
938
|
+
js_get_env_loop(env, &loop);
|
|
939
|
+
|
|
940
|
+
uv_fs_t req;
|
|
941
|
+
uv_fs_fchmod(loop, &req, fd, mode, NULL);
|
|
942
|
+
|
|
943
|
+
if (req.result < 0) {
|
|
944
|
+
js_throw_error(env, uv_err_name(req.result), uv_strerror(req.result));
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
uv_fs_req_cleanup(&req);
|
|
948
|
+
|
|
949
|
+
return NULL;
|
|
950
|
+
}
|
|
951
|
+
|
|
885
952
|
static js_value_t *
|
|
886
953
|
bare_fs_rename (js_env_t *env, js_callback_info_t *info) {
|
|
887
954
|
int err;
|
|
@@ -914,6 +981,41 @@ bare_fs_rename (js_env_t *env, js_callback_info_t *info) {
|
|
|
914
981
|
return NULL;
|
|
915
982
|
}
|
|
916
983
|
|
|
984
|
+
static js_value_t *
|
|
985
|
+
bare_fs_rename_sync (js_env_t *env, js_callback_info_t *info) {
|
|
986
|
+
int err;
|
|
987
|
+
|
|
988
|
+
size_t argc = 2;
|
|
989
|
+
js_value_t *argv[2];
|
|
990
|
+
|
|
991
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
992
|
+
assert(err == 0);
|
|
993
|
+
|
|
994
|
+
assert(argc == 2);
|
|
995
|
+
|
|
996
|
+
bare_fs_path_t src;
|
|
997
|
+
err = js_get_value_string_utf8(env, argv[0], src, sizeof(bare_fs_path_t), NULL);
|
|
998
|
+
assert(err == 0);
|
|
999
|
+
|
|
1000
|
+
bare_fs_path_t dest;
|
|
1001
|
+
err = js_get_value_string_utf8(env, argv[1], dest, sizeof(bare_fs_path_t), NULL);
|
|
1002
|
+
assert(err == 0);
|
|
1003
|
+
|
|
1004
|
+
uv_loop_t *loop;
|
|
1005
|
+
js_get_env_loop(env, &loop);
|
|
1006
|
+
|
|
1007
|
+
uv_fs_t req;
|
|
1008
|
+
uv_fs_rename(loop, &req, (char *) src, (char *) dest, NULL);
|
|
1009
|
+
|
|
1010
|
+
if (req.result < 0) {
|
|
1011
|
+
js_throw_error(env, uv_err_name(req.result), uv_strerror(req.result));
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
uv_fs_req_cleanup(&req);
|
|
1015
|
+
|
|
1016
|
+
return NULL;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
917
1019
|
static js_value_t *
|
|
918
1020
|
bare_fs_mkdir (js_env_t *env, js_callback_info_t *info) {
|
|
919
1021
|
int err;
|
|
@@ -946,6 +1048,41 @@ bare_fs_mkdir (js_env_t *env, js_callback_info_t *info) {
|
|
|
946
1048
|
return NULL;
|
|
947
1049
|
}
|
|
948
1050
|
|
|
1051
|
+
static js_value_t *
|
|
1052
|
+
bare_fs_mkdir_sync (js_env_t *env, js_callback_info_t *info) {
|
|
1053
|
+
int err;
|
|
1054
|
+
|
|
1055
|
+
size_t argc = 2;
|
|
1056
|
+
js_value_t *argv[2];
|
|
1057
|
+
|
|
1058
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
1059
|
+
assert(err == 0);
|
|
1060
|
+
|
|
1061
|
+
assert(argc == 2);
|
|
1062
|
+
|
|
1063
|
+
bare_fs_path_t path;
|
|
1064
|
+
err = js_get_value_string_utf8(env, argv[0], path, sizeof(bare_fs_path_t), NULL);
|
|
1065
|
+
assert(err == 0);
|
|
1066
|
+
|
|
1067
|
+
int32_t mode;
|
|
1068
|
+
err = js_get_value_int32(env, argv[1], &mode);
|
|
1069
|
+
assert(err == 0);
|
|
1070
|
+
|
|
1071
|
+
uv_loop_t *loop;
|
|
1072
|
+
js_get_env_loop(env, &loop);
|
|
1073
|
+
|
|
1074
|
+
uv_fs_t req;
|
|
1075
|
+
uv_fs_mkdir(loop, &req, (char *) path, mode, NULL);
|
|
1076
|
+
|
|
1077
|
+
if (req.result < 0) {
|
|
1078
|
+
js_throw_error(env, uv_err_name(req.result), uv_strerror(req.result));
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
uv_fs_req_cleanup(&req);
|
|
1082
|
+
|
|
1083
|
+
return NULL;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
949
1086
|
static js_value_t *
|
|
950
1087
|
bare_fs_rmdir (js_env_t *env, js_callback_info_t *info) {
|
|
951
1088
|
int err;
|
|
@@ -974,6 +1111,37 @@ bare_fs_rmdir (js_env_t *env, js_callback_info_t *info) {
|
|
|
974
1111
|
return NULL;
|
|
975
1112
|
}
|
|
976
1113
|
|
|
1114
|
+
static js_value_t *
|
|
1115
|
+
bare_fs_rmdir_sync (js_env_t *env, js_callback_info_t *info) {
|
|
1116
|
+
int err;
|
|
1117
|
+
|
|
1118
|
+
size_t argc = 1;
|
|
1119
|
+
js_value_t *argv[1];
|
|
1120
|
+
|
|
1121
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
1122
|
+
assert(err == 0);
|
|
1123
|
+
|
|
1124
|
+
assert(argc == 1);
|
|
1125
|
+
|
|
1126
|
+
bare_fs_path_t path;
|
|
1127
|
+
err = js_get_value_string_utf8(env, argv[0], path, sizeof(bare_fs_path_t), NULL);
|
|
1128
|
+
assert(err == 0);
|
|
1129
|
+
|
|
1130
|
+
uv_loop_t *loop;
|
|
1131
|
+
js_get_env_loop(env, &loop);
|
|
1132
|
+
|
|
1133
|
+
uv_fs_t req;
|
|
1134
|
+
uv_fs_rmdir(loop, &req, (char *) path, NULL);
|
|
1135
|
+
|
|
1136
|
+
if (req.result < 0) {
|
|
1137
|
+
js_throw_error(env, uv_err_name(req.result), uv_strerror(req.result));
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
uv_fs_req_cleanup(&req);
|
|
1141
|
+
|
|
1142
|
+
return NULL;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
977
1145
|
static js_value_t *
|
|
978
1146
|
bare_fs_stat (js_env_t *env, js_callback_info_t *info) {
|
|
979
1147
|
int err;
|
|
@@ -1323,6 +1491,37 @@ bare_fs_unlink (js_env_t *env, js_callback_info_t *info) {
|
|
|
1323
1491
|
return NULL;
|
|
1324
1492
|
}
|
|
1325
1493
|
|
|
1494
|
+
static js_value_t *
|
|
1495
|
+
bare_fs_unlink_sync (js_env_t *env, js_callback_info_t *info) {
|
|
1496
|
+
int err;
|
|
1497
|
+
|
|
1498
|
+
size_t argc = 1;
|
|
1499
|
+
js_value_t *argv[1];
|
|
1500
|
+
|
|
1501
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
1502
|
+
assert(err == 0);
|
|
1503
|
+
|
|
1504
|
+
assert(argc == 1);
|
|
1505
|
+
|
|
1506
|
+
bare_fs_path_t path;
|
|
1507
|
+
err = js_get_value_string_utf8(env, argv[0], path, sizeof(bare_fs_path_t), NULL);
|
|
1508
|
+
assert(err == 0);
|
|
1509
|
+
|
|
1510
|
+
uv_loop_t *loop;
|
|
1511
|
+
js_get_env_loop(env, &loop);
|
|
1512
|
+
|
|
1513
|
+
uv_fs_t req;
|
|
1514
|
+
uv_fs_unlink(loop, &req, (char *) path, NULL);
|
|
1515
|
+
|
|
1516
|
+
if (req.result < 0) {
|
|
1517
|
+
js_throw_error(env, uv_err_name(req.result), uv_strerror(req.result));
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
uv_fs_req_cleanup(&req);
|
|
1521
|
+
|
|
1522
|
+
return NULL;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1326
1525
|
static js_value_t *
|
|
1327
1526
|
bare_fs_readlink (js_env_t *env, js_callback_info_t *info) {
|
|
1328
1527
|
int err;
|
|
@@ -1568,6 +1767,8 @@ bare_fs_closedir (js_env_t *env, js_callback_info_t *info) {
|
|
|
1568
1767
|
|
|
1569
1768
|
static js_value_t *
|
|
1570
1769
|
init (js_env_t *env, js_value_t *exports) {
|
|
1770
|
+
int err;
|
|
1771
|
+
|
|
1571
1772
|
{
|
|
1572
1773
|
js_value_t *val;
|
|
1573
1774
|
js_create_uint32(env, sizeof(bare_fs_t), &val);
|
|
@@ -1598,177 +1799,65 @@ init (js_env_t *env, js_value_t *exports) {
|
|
|
1598
1799
|
js_create_uint32(env, sizeof(bare_fs_path_t), &val);
|
|
1599
1800
|
js_set_named_property(env, exports, "sizeofFSPath", val);
|
|
1600
1801
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
js_create_function(env, "destroy", -1, bare_fs_destroy, NULL, &fn);
|
|
1609
|
-
js_set_named_property(env, exports, "destroy", fn);
|
|
1610
|
-
}
|
|
1611
|
-
{
|
|
1612
|
-
js_value_t *fn;
|
|
1613
|
-
js_create_function(env, "initReq", -1, bare_fs_req_init, NULL, &fn);
|
|
1614
|
-
js_set_named_property(env, exports, "initReq", fn);
|
|
1615
|
-
}
|
|
1616
|
-
{
|
|
1617
|
-
js_value_t *fn;
|
|
1618
|
-
js_create_function(env, "open", -1, bare_fs_open, NULL, &fn);
|
|
1619
|
-
js_set_named_property(env, exports, "open", fn);
|
|
1620
|
-
}
|
|
1621
|
-
{
|
|
1622
|
-
js_value_t *fn;
|
|
1623
|
-
js_create_function(env, "openSync", -1, bare_fs_open_sync, NULL, &fn);
|
|
1624
|
-
js_set_named_property(env, exports, "openSync", fn);
|
|
1625
|
-
}
|
|
1626
|
-
{
|
|
1627
|
-
js_value_t *fn;
|
|
1628
|
-
js_create_function(env, "close", -1, bare_fs_close, NULL, &fn);
|
|
1629
|
-
js_set_named_property(env, exports, "close", fn);
|
|
1630
|
-
}
|
|
1631
|
-
{
|
|
1632
|
-
js_value_t *fn;
|
|
1633
|
-
js_create_function(env, "closeSync", -1, bare_fs_close_sync, NULL, &fn);
|
|
1634
|
-
js_set_named_property(env, exports, "closeSync", fn);
|
|
1635
|
-
}
|
|
1636
|
-
{
|
|
1637
|
-
js_value_t *fn;
|
|
1638
|
-
js_create_function(env, "read", -1, bare_fs_read, NULL, &fn);
|
|
1639
|
-
js_set_named_property(env, exports, "read", fn);
|
|
1640
|
-
}
|
|
1641
|
-
{
|
|
1642
|
-
js_value_t *fn;
|
|
1643
|
-
js_create_function(env, "readSync", -1, bare_fs_read_sync, NULL, &fn);
|
|
1644
|
-
js_set_named_property(env, exports, "readSync", fn);
|
|
1645
|
-
}
|
|
1646
|
-
{
|
|
1647
|
-
js_value_t *fn;
|
|
1648
|
-
js_create_function(env, "readv", -1, bare_fs_readv, NULL, &fn);
|
|
1649
|
-
js_set_named_property(env, exports, "readv", fn);
|
|
1650
|
-
}
|
|
1651
|
-
{
|
|
1652
|
-
js_value_t *fn;
|
|
1653
|
-
js_create_function(env, "write", -1, bare_fs_write, NULL, &fn);
|
|
1654
|
-
js_set_named_property(env, exports, "write", fn);
|
|
1655
|
-
}
|
|
1656
|
-
{
|
|
1657
|
-
js_value_t *fn;
|
|
1658
|
-
js_create_function(env, "writeSync", -1, bare_fs_write_sync, NULL, &fn);
|
|
1659
|
-
js_set_named_property(env, exports, "writeSync", fn);
|
|
1660
|
-
}
|
|
1661
|
-
{
|
|
1662
|
-
js_value_t *fn;
|
|
1663
|
-
js_create_function(env, "writev", -1, bare_fs_writev, NULL, &fn);
|
|
1664
|
-
js_set_named_property(env, exports, "writev", fn);
|
|
1665
|
-
}
|
|
1666
|
-
{
|
|
1667
|
-
js_value_t *fn;
|
|
1668
|
-
js_create_function(env, "ftruncate", -1, bare_fs_ftruncate, NULL, &fn);
|
|
1669
|
-
js_set_named_property(env, exports, "ftruncate", fn);
|
|
1670
|
-
}
|
|
1671
|
-
{
|
|
1672
|
-
js_value_t *fn;
|
|
1673
|
-
js_create_function(env, "chmod", -1, bare_fs_chmod, NULL, &fn);
|
|
1674
|
-
js_set_named_property(env, exports, "chmod", fn);
|
|
1675
|
-
}
|
|
1676
|
-
{
|
|
1677
|
-
js_value_t *fn;
|
|
1678
|
-
js_create_function(env, "chmodSync", -1, bare_fs_chmod_sync, NULL, &fn);
|
|
1679
|
-
js_set_named_property(env, exports, "chmodSync", fn);
|
|
1680
|
-
}
|
|
1681
|
-
{
|
|
1682
|
-
js_value_t *fn;
|
|
1683
|
-
js_create_function(env, "rename", -1, bare_fs_rename, NULL, &fn);
|
|
1684
|
-
js_set_named_property(env, exports, "rename", fn);
|
|
1685
|
-
}
|
|
1686
|
-
{
|
|
1687
|
-
js_value_t *fn;
|
|
1688
|
-
js_create_function(env, "mkdir", -1, bare_fs_mkdir, NULL, &fn);
|
|
1689
|
-
js_set_named_property(env, exports, "mkdir", fn);
|
|
1690
|
-
}
|
|
1691
|
-
{
|
|
1692
|
-
js_value_t *fn;
|
|
1693
|
-
js_create_function(env, "rmdir", -1, bare_fs_rmdir, NULL, &fn);
|
|
1694
|
-
js_set_named_property(env, exports, "rmdir", fn);
|
|
1695
|
-
}
|
|
1696
|
-
{
|
|
1697
|
-
js_value_t *fn;
|
|
1698
|
-
js_create_function(env, "stat", -1, bare_fs_stat, NULL, &fn);
|
|
1699
|
-
js_set_named_property(env, exports, "stat", fn);
|
|
1700
|
-
}
|
|
1701
|
-
{
|
|
1702
|
-
js_value_t *fn;
|
|
1703
|
-
js_create_function(env, "statSync", -1, bare_fs_stat_sync, NULL, &fn);
|
|
1704
|
-
js_set_named_property(env, exports, "statSync", fn);
|
|
1705
|
-
}
|
|
1706
|
-
{
|
|
1707
|
-
js_value_t *fn;
|
|
1708
|
-
js_create_function(env, "lstat", -1, bare_fs_lstat, NULL, &fn);
|
|
1709
|
-
js_set_named_property(env, exports, "lstat", fn);
|
|
1710
|
-
}
|
|
1711
|
-
{
|
|
1712
|
-
js_value_t *fn;
|
|
1713
|
-
js_create_function(env, "lstatSync", -1, bare_fs_lstat_sync, NULL, &fn);
|
|
1714
|
-
js_set_named_property(env, exports, "lstatSync", fn);
|
|
1715
|
-
}
|
|
1716
|
-
{
|
|
1717
|
-
js_value_t *fn;
|
|
1718
|
-
js_create_function(env, "fstat", -1, bare_fs_fstat, NULL, &fn);
|
|
1719
|
-
js_set_named_property(env, exports, "fstat", fn);
|
|
1720
|
-
}
|
|
1721
|
-
{
|
|
1722
|
-
js_value_t *fn;
|
|
1723
|
-
js_create_function(env, "fstatSync", -1, bare_fs_fstat_sync, NULL, &fn);
|
|
1724
|
-
js_set_named_property(env, exports, "fstatSync", fn);
|
|
1725
|
-
}
|
|
1726
|
-
{
|
|
1727
|
-
js_value_t *fn;
|
|
1728
|
-
js_create_function(env, "unlink", -1, bare_fs_unlink, NULL, &fn);
|
|
1729
|
-
js_set_named_property(env, exports, "unlink", fn);
|
|
1730
|
-
}
|
|
1731
|
-
{
|
|
1732
|
-
js_value_t *fn;
|
|
1733
|
-
js_create_function(env, "readlink", -1, bare_fs_readlink, NULL, &fn);
|
|
1734
|
-
js_set_named_property(env, exports, "readlink", fn);
|
|
1735
|
-
}
|
|
1736
|
-
{
|
|
1737
|
-
js_value_t *fn;
|
|
1738
|
-
js_create_function(env, "readlinkSync", -1, bare_fs_readlink_sync, NULL, &fn);
|
|
1739
|
-
js_set_named_property(env, exports, "readlinkSync", fn);
|
|
1740
|
-
}
|
|
1741
|
-
{
|
|
1742
|
-
js_value_t *fn;
|
|
1743
|
-
js_create_function(env, "symlink", -1, bare_fs_symlink, NULL, &fn);
|
|
1744
|
-
js_set_named_property(env, exports, "symlink", fn);
|
|
1745
|
-
}
|
|
1746
|
-
{
|
|
1747
|
-
js_value_t *fn;
|
|
1748
|
-
js_create_function(env, "symlinkSync", -1, bare_fs_symlink_sync, NULL, &fn);
|
|
1749
|
-
js_set_named_property(env, exports, "symlinkSync", fn);
|
|
1750
|
-
}
|
|
1751
|
-
{
|
|
1752
|
-
js_value_t *fn;
|
|
1753
|
-
js_create_function(env, "opendir", -1, bare_fs_opendir, NULL, &fn);
|
|
1754
|
-
js_set_named_property(env, exports, "opendir", fn);
|
|
1755
|
-
}
|
|
1756
|
-
{
|
|
1757
|
-
js_value_t *fn;
|
|
1758
|
-
js_create_function(env, "readdir", -1, bare_fs_readdir, NULL, &fn);
|
|
1759
|
-
js_set_named_property(env, exports, "readdir", fn);
|
|
1760
|
-
}
|
|
1761
|
-
{
|
|
1762
|
-
js_value_t *fn;
|
|
1763
|
-
js_create_function(env, "closedir", -1, bare_fs_closedir, NULL, &fn);
|
|
1764
|
-
js_set_named_property(env, exports, "closedir", fn);
|
|
1802
|
+
#define V(name, fn) \
|
|
1803
|
+
{ \
|
|
1804
|
+
js_value_t *val; \
|
|
1805
|
+
err = js_create_function(env, name, -1, fn, NULL, &val); \
|
|
1806
|
+
assert(err == 0); \
|
|
1807
|
+
js_set_named_property(env, exports, name, val); \
|
|
1808
|
+
assert(err == 0); \
|
|
1765
1809
|
}
|
|
1810
|
+
|
|
1811
|
+
V("init", bare_fs_init)
|
|
1812
|
+
V("destroy", bare_fs_destroy)
|
|
1813
|
+
V("initReq", bare_fs_req_init)
|
|
1814
|
+
V("open", bare_fs_open)
|
|
1815
|
+
V("openSync", bare_fs_open_sync)
|
|
1816
|
+
V("close", bare_fs_close)
|
|
1817
|
+
V("closeSync", bare_fs_close_sync)
|
|
1818
|
+
V("read", bare_fs_read)
|
|
1819
|
+
V("readSync", bare_fs_read_sync)
|
|
1820
|
+
V("readv", bare_fs_readv)
|
|
1821
|
+
V("write", bare_fs_write)
|
|
1822
|
+
V("writeSync", bare_fs_write_sync)
|
|
1823
|
+
V("writev", bare_fs_writev)
|
|
1824
|
+
V("ftruncate", bare_fs_ftruncate)
|
|
1825
|
+
V("chmod", bare_fs_chmod)
|
|
1826
|
+
V("chmodSync", bare_fs_chmod_sync)
|
|
1827
|
+
V("fchmod", bare_fs_fchmod)
|
|
1828
|
+
V("fchmodSync", bare_fs_fchmod_sync)
|
|
1829
|
+
V("rename", bare_fs_rename)
|
|
1830
|
+
V("renameSync", bare_fs_rename_sync)
|
|
1831
|
+
V("mkdir", bare_fs_mkdir)
|
|
1832
|
+
V("mkdirSync", bare_fs_mkdir_sync)
|
|
1833
|
+
V("rmdir", bare_fs_rmdir)
|
|
1834
|
+
V("rmdirSync", bare_fs_rmdir_sync)
|
|
1835
|
+
V("stat", bare_fs_stat)
|
|
1836
|
+
V("statSync", bare_fs_stat_sync)
|
|
1837
|
+
V("lstat", bare_fs_lstat)
|
|
1838
|
+
V("lstatSync", bare_fs_lstat_sync)
|
|
1839
|
+
V("fstat", bare_fs_fstat)
|
|
1840
|
+
V("fstatSync", bare_fs_fstat_sync)
|
|
1841
|
+
V("unlink", bare_fs_unlink)
|
|
1842
|
+
V("unlinkSync", bare_fs_unlink_sync)
|
|
1843
|
+
V("readlink", bare_fs_readlink)
|
|
1844
|
+
V("readlinkSync", bare_fs_readlink_sync)
|
|
1845
|
+
V("symlink", bare_fs_symlink)
|
|
1846
|
+
V("symlinkSync", bare_fs_symlink_sync)
|
|
1847
|
+
V("opendir", bare_fs_opendir)
|
|
1848
|
+
V("readdir", bare_fs_readdir)
|
|
1849
|
+
V("closedir", bare_fs_closedir)
|
|
1850
|
+
#undef V
|
|
1851
|
+
|
|
1766
1852
|
#define V(name) \
|
|
1767
1853
|
{ \
|
|
1768
1854
|
js_value_t *val; \
|
|
1769
|
-
js_create_uint32(env, name, &val); \
|
|
1770
|
-
|
|
1855
|
+
err = js_create_uint32(env, name, &val); \
|
|
1856
|
+
assert(err == 0); \
|
|
1857
|
+
err = js_set_named_property(env, exports, #name, val); \
|
|
1858
|
+
assert(err == 0); \
|
|
1771
1859
|
}
|
|
1860
|
+
|
|
1772
1861
|
V(O_RDWR)
|
|
1773
1862
|
V(O_RDONLY)
|
|
1774
1863
|
V(O_WRONLY)
|
package/index.js
CHANGED
|
@@ -500,6 +500,36 @@ function chmodSync (path, mode) {
|
|
|
500
500
|
binding.chmodSync(path, mode)
|
|
501
501
|
}
|
|
502
502
|
|
|
503
|
+
function fchmod (fd, mode, cb) {
|
|
504
|
+
if (typeof fd !== 'number') {
|
|
505
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (fd < 0 || fd > 0x7fffffff) {
|
|
509
|
+
throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (typeof mode === 'string') mode = modeToNumber(mode)
|
|
513
|
+
|
|
514
|
+
const req = getReq()
|
|
515
|
+
req.callback = cb
|
|
516
|
+
binding.fchmod(req.handle, fd, mode)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function fchmodSync (fd, mode) {
|
|
520
|
+
if (typeof fd !== 'number') {
|
|
521
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (fd < 0 || fd > 0x7fffffff) {
|
|
525
|
+
throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (typeof mode === 'string') mode = modeToNumber(mode)
|
|
529
|
+
|
|
530
|
+
binding.fchmodSync(fd, mode)
|
|
531
|
+
}
|
|
532
|
+
|
|
503
533
|
function mkdirp (path, mode, cb) {
|
|
504
534
|
mkdir(path, { mode }, function (err) {
|
|
505
535
|
if (err === null) return cb(null, 0, null)
|
|
@@ -548,6 +578,38 @@ function mkdir (path, opts, cb) {
|
|
|
548
578
|
binding.mkdir(req.handle, path, mode)
|
|
549
579
|
}
|
|
550
580
|
|
|
581
|
+
function mkdirpSync (path, mode) {
|
|
582
|
+
try {
|
|
583
|
+
mkdirSync(path, { mode })
|
|
584
|
+
} catch (err) {
|
|
585
|
+
if (err.code !== 'ENOENT' && statSync(path).isDirectory()) {
|
|
586
|
+
return
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
while (path.endsWith(sep)) path = path.slice(0, -1)
|
|
590
|
+
const i = path.lastIndexOf(sep)
|
|
591
|
+
if (i <= 0) throw err
|
|
592
|
+
|
|
593
|
+
mkdirpSync(path.slice(0, i), { mode })
|
|
594
|
+
mkdirSync(path, { mode })
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function mkdirSync (path, opts) {
|
|
599
|
+
if (typeof path !== 'string') {
|
|
600
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (typeof opts === 'number') opts = { mode: opts }
|
|
604
|
+
else if (!opts) opts = {}
|
|
605
|
+
|
|
606
|
+
const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
|
|
607
|
+
|
|
608
|
+
if (opts.recursive) return mkdirpSync(path, mode)
|
|
609
|
+
|
|
610
|
+
binding.mkdirSync(path, mode)
|
|
611
|
+
}
|
|
612
|
+
|
|
551
613
|
function rmdir (path, cb) {
|
|
552
614
|
if (typeof path !== 'string') {
|
|
553
615
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
|
|
@@ -562,6 +624,14 @@ function rmdir (path, cb) {
|
|
|
562
624
|
binding.rmdir(req.handle, path)
|
|
563
625
|
}
|
|
564
626
|
|
|
627
|
+
function rmdirSync (path) {
|
|
628
|
+
if (typeof path !== 'string') {
|
|
629
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
binding.rmdirSync(path)
|
|
633
|
+
}
|
|
634
|
+
|
|
565
635
|
function unlink (path, cb) {
|
|
566
636
|
if (typeof path !== 'string') {
|
|
567
637
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
|
|
@@ -576,6 +646,14 @@ function unlink (path, cb) {
|
|
|
576
646
|
binding.unlink(req.handle, path)
|
|
577
647
|
}
|
|
578
648
|
|
|
649
|
+
function unlinkSync (path) {
|
|
650
|
+
if (typeof path !== 'string') {
|
|
651
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
binding.unlinkSync(path)
|
|
655
|
+
}
|
|
656
|
+
|
|
579
657
|
function rename (src, dst, cb) {
|
|
580
658
|
if (typeof src !== 'string') {
|
|
581
659
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof src) + ' (' + src + ')')
|
|
@@ -594,6 +672,18 @@ function rename (src, dst, cb) {
|
|
|
594
672
|
binding.rename(req.handle, src, dst)
|
|
595
673
|
}
|
|
596
674
|
|
|
675
|
+
function renameSync (src, dst) {
|
|
676
|
+
if (typeof src !== 'string') {
|
|
677
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof src) + ' (' + src + ')')
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
if (typeof dst !== 'string') {
|
|
681
|
+
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof dst) + ' (' + dst + ')')
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
binding.renameSync(src, dst)
|
|
685
|
+
}
|
|
686
|
+
|
|
597
687
|
function readlink (path, opts, cb) {
|
|
598
688
|
if (typeof path !== 'string') {
|
|
599
689
|
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
|
|
@@ -1230,6 +1320,7 @@ function noop () {}
|
|
|
1230
1320
|
|
|
1231
1321
|
exports.chmod = chmod
|
|
1232
1322
|
exports.close = close
|
|
1323
|
+
exports.fchmod = fchmod
|
|
1233
1324
|
exports.fstat = fstat
|
|
1234
1325
|
exports.ftruncate = ftruncate
|
|
1235
1326
|
exports.lstat = lstat
|
|
@@ -1252,14 +1343,19 @@ exports.writev = writev
|
|
|
1252
1343
|
|
|
1253
1344
|
exports.chmodSync = chmodSync
|
|
1254
1345
|
exports.closeSync = closeSync
|
|
1346
|
+
exports.fchmodSync = fchmodSync
|
|
1255
1347
|
exports.fstatSync = fstatSync
|
|
1256
1348
|
exports.lstatSync = lstatSync
|
|
1349
|
+
exports.mkdirSync = mkdirSync
|
|
1257
1350
|
exports.openSync = openSync
|
|
1258
1351
|
exports.readFileSync = readFileSync
|
|
1259
1352
|
exports.readSync = readSync
|
|
1260
1353
|
exports.readlinkSync = readlinkSync
|
|
1354
|
+
exports.renameSync = renameSync
|
|
1355
|
+
exports.rmdirSync = rmdirSync
|
|
1261
1356
|
exports.statSync = statSync
|
|
1262
1357
|
exports.symlinkSync = symlinkSync
|
|
1358
|
+
exports.unlinkSync = unlinkSync
|
|
1263
1359
|
exports.writeFileSync = writeFileSync
|
|
1264
1360
|
exports.writeSync = writeSync
|
|
1265
1361
|
|