bare-fs 1.5.4 → 1.5.5

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.
Files changed (3) hide show
  1. package/binding.c +8 -96
  2. package/index.js +0 -71
  3. package/package.json +1 -1
package/binding.c CHANGED
@@ -71,6 +71,13 @@ copy_ptr_address (uv_fs_t *req, uv_buf_t *buf) {
71
71
  memcpy(buf->base, &req->ptr, buf->len);
72
72
  }
73
73
 
74
+ static inline void
75
+ copy_ptr_string (uv_fs_t *req, uv_buf_t *buf) {
76
+ if (req->result != 0) return;
77
+
78
+ strncpy(buf->base, req->ptr, buf->len);
79
+ }
80
+
74
81
  static void
75
82
  on_fs_response (uv_fs_t *req) {
76
83
  bare_fs_req_t *p = (bare_fs_req_t *) req;
@@ -108,23 +115,7 @@ static void
108
115
  on_fs_readlink_response (uv_fs_t *req) {
109
116
  bare_fs_req_t *p = (bare_fs_req_t *) req;
110
117
 
111
- copy_ptr(req, &p->buf);
112
-
113
- on_fs_response(req);
114
- }
115
-
116
- static void
117
- on_fs_opendir_response (uv_fs_t *req) {
118
- bare_fs_req_t *p = (bare_fs_req_t *) req;
119
-
120
- copy_ptr_address(req, &p->buf);
121
-
122
- on_fs_response(req);
123
- }
124
-
125
- static void
126
- on_fs_readdir_response (uv_fs_t *req) {
127
- bare_fs_req_t *p = (bare_fs_req_t *) req;
118
+ copy_ptr_string(req, &p->buf);
128
119
 
129
120
  on_fs_response(req);
130
121
  }
@@ -850,70 +841,6 @@ bare_fs_readlink (js_env_t *env, js_callback_info_t *info) {
850
841
  return NULL;
851
842
  }
852
843
 
853
- static js_value_t *
854
- bare_fs_opendir (js_env_t *env, js_callback_info_t *info) {
855
- size_t argc = 3;
856
- js_value_t *argv[3];
857
-
858
- js_get_callback_info(env, info, &argc, argv, NULL, NULL);
859
-
860
- bare_fs_req_t *req;
861
- js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
862
-
863
- utf8_t path[4097];
864
- js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
865
-
866
- void *data;
867
- size_t data_len;
868
- js_get_typedarray_info(env, argv[2], NULL, &data, &data_len, NULL, NULL);
869
-
870
- uv_loop_t *loop;
871
- js_get_env_loop(env, &loop);
872
-
873
- req->env = env;
874
- req->buf = uv_buf_init((char *) data, data_len);
875
-
876
- uv_fs_opendir(loop, (uv_fs_t *) req, (char *) path, on_fs_opendir_response);
877
-
878
- return NULL;
879
- }
880
-
881
- static js_value_t *
882
- bare_fs_readdir (js_env_t *env, js_callback_info_t *info) {
883
- size_t argc = 3;
884
- js_value_t *argv[3];
885
-
886
- js_get_callback_info(env, info, &argc, argv, NULL, NULL);
887
-
888
- bare_fs_req_t *req;
889
- js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
890
-
891
- uv_dir_t **dir;
892
- js_get_typedarray_info(env, argv[1], NULL, (void **) &dir, NULL, NULL, NULL);
893
-
894
- void *data;
895
- size_t data_len;
896
- js_get_typedarray_info(env, argv[2], NULL, &data, &data_len, NULL, NULL);
897
-
898
- uv_loop_t *loop;
899
- js_get_env_loop(env, &loop);
900
-
901
- req->env = env;
902
- req->buf = uv_buf_init((char *) data, data_len);
903
-
904
- (*dir)->dirents = data;
905
- (*dir)->nentries = data_len / sizeof(uv_dirent_t);
906
-
907
- uv_fs_readdir(loop, (uv_fs_t *) req, *dir, on_fs_readdir_response);
908
-
909
- return NULL;
910
- }
911
-
912
- static js_value_t *
913
- bare_fs_to_dirent (js_env_t *env, js_callback_info_t *info) {
914
- return NULL;
915
- }
916
-
917
844
  static js_value_t *
918
845
  init (js_env_t *env, js_value_t *exports) {
919
846
  {
@@ -1066,21 +993,6 @@ init (js_env_t *env, js_value_t *exports) {
1066
993
  js_create_function(env, "readlink", -1, bare_fs_readlink, NULL, &fn);
1067
994
  js_set_named_property(env, exports, "readlink", fn);
1068
995
  }
1069
- {
1070
- js_value_t *fn;
1071
- js_create_function(env, "opendir", -1, bare_fs_opendir, NULL, &fn);
1072
- js_set_named_property(env, exports, "opendir", fn);
1073
- }
1074
- {
1075
- js_value_t *fn;
1076
- js_create_function(env, "readdir", -1, bare_fs_readdir, NULL, &fn);
1077
- js_set_named_property(env, exports, "readdir", fn);
1078
- }
1079
- {
1080
- js_value_t *fn;
1081
- js_create_function(env, "toDirent", -1, bare_fs_to_dirent, NULL, &fn);
1082
- js_set_named_property(env, exports, "toDirent", fn);
1083
- }
1084
996
  {
1085
997
  js_value_t *val;
1086
998
  js_create_uint32(env, O_RDWR, &val);
package/index.js CHANGED
@@ -469,58 +469,6 @@ function readlink (path, opts, cb) {
469
469
  binding.readlink(req.handle, path, req.buffer)
470
470
  }
471
471
 
472
- function opendir (path, opts, cb) {
473
- if (typeof opts === 'function') return opendir(path, null, opts)
474
- if (typeof cb !== 'function') throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function')
475
- if (typeof opts === 'string') opts = { encoding: opts }
476
- if (!opts) opts = {}
477
-
478
- const {
479
- encoding = 'utf8'
480
- } = opts
481
-
482
- const req = getReq()
483
-
484
- req.buffer = Buffer.allocUnsafe(binding.sizeofFSDir)
485
-
486
- req.callback = function (err, _, buf) {
487
- if (err) return cb(err, null)
488
- cb(null, new Dir(buf, encoding))
489
- }
490
-
491
- binding.opendir(req.handle, path, req.buffer)
492
- }
493
-
494
- function readdir (dir, opts, cb) {
495
- if (typeof opts === 'function') return readdir(dir, null, opts)
496
- if (typeof cb !== 'function') throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function')
497
- if (typeof opts === 'string') opts = { encoding: opts }
498
- if (!opts) opts = {}
499
-
500
- if (typeof dir === 'string') {
501
- return opendir(dir, opts, (err, dir) => {
502
- if (err) return cb(err, null)
503
- return readdir(dir, opts, cb)
504
- })
505
- }
506
-
507
- const {
508
- encoding = 'utf8',
509
- bufferSize = 32
510
- } = opts
511
-
512
- const req = getReq()
513
-
514
- req.buffer = Buffer.allocUnsafe(binding.sizeofFSDirent * bufferSize)
515
-
516
- req.callback = function (err, _, buf) {
517
- if (err) return cb(err, null)
518
- binding.toDirent(dir._handle)
519
- }
520
-
521
- binding.readdir(req.handle, dir._handle, req.buffer)
522
- }
523
-
524
472
  function readFile (path, opts, cb) {
525
473
  if (typeof opts === 'function') return readFile(path, null, opts)
526
474
  if (typeof cb !== 'function') throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function')
@@ -754,19 +702,6 @@ class FileReadStream extends Readable {
754
702
  }
755
703
  }
756
704
 
757
- class Dir extends Readable {
758
- constructor (handle, encoding) {
759
- super()
760
-
761
- this._handle = handle
762
- this._encoding = encoding
763
- }
764
-
765
- _read (cb) {
766
- cb(null)
767
- }
768
- }
769
-
770
705
  exports.promises = {}
771
706
 
772
707
  function typeError (code, message) {
@@ -826,12 +761,6 @@ exports.promises.lstat = promisify(lstat)
826
761
  exports.readlink = readlink
827
762
  exports.promises.readlink = promisify(readlink)
828
763
 
829
- exports.opendir = opendir
830
- exports.promises.opendir = promisify(opendir)
831
-
832
- exports.readdir = readdir
833
- exports.promises.readdir = promisify(readdir)
834
-
835
764
  exports.ReadStream = FileReadStream
836
765
  exports.createReadStream = (path, options) => new FileReadStream(path, options)
837
766
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "1.5.4",
3
+ "version": "1.5.5",
4
4
  "description": "Native file system for Javascript",
5
5
  "main": "index.js",
6
6
  "files": [