bare-fs 1.5.3 → 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 +32 -119
  2. package/index.js +0 -71
  3. package/package.json +1 -1
package/binding.c CHANGED
@@ -3,6 +3,7 @@
3
3
  #include <stdint.h>
4
4
  #include <stdlib.h>
5
5
  #include <string.h>
6
+ #include <utf.h>
6
7
  #include <uv.h>
7
8
 
8
9
  typedef struct {
@@ -70,6 +71,13 @@ copy_ptr_address (uv_fs_t *req, uv_buf_t *buf) {
70
71
  memcpy(buf->base, &req->ptr, buf->len);
71
72
  }
72
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
+
73
81
  static void
74
82
  on_fs_response (uv_fs_t *req) {
75
83
  bare_fs_req_t *p = (bare_fs_req_t *) req;
@@ -107,23 +115,7 @@ static void
107
115
  on_fs_readlink_response (uv_fs_t *req) {
108
116
  bare_fs_req_t *p = (bare_fs_req_t *) req;
109
117
 
110
- copy_ptr(req, &p->buf);
111
-
112
- on_fs_response(req);
113
- }
114
-
115
- static void
116
- on_fs_opendir_response (uv_fs_t *req) {
117
- bare_fs_req_t *p = (bare_fs_req_t *) req;
118
-
119
- copy_ptr_address(req, &p->buf);
120
-
121
- on_fs_response(req);
122
- }
123
-
124
- static void
125
- on_fs_readdir_response (uv_fs_t *req) {
126
- bare_fs_req_t *p = (bare_fs_req_t *) req;
118
+ copy_ptr_string(req, &p->buf);
127
119
 
128
120
  on_fs_response(req);
129
121
  }
@@ -188,7 +180,7 @@ bare_fs_open (js_env_t *env, js_callback_info_t *info) {
188
180
  bare_fs_req_t *req;
189
181
  js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
190
182
 
191
- char path[4097];
183
+ utf8_t path[4097];
192
184
  js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
193
185
 
194
186
  int32_t flags;
@@ -202,7 +194,7 @@ bare_fs_open (js_env_t *env, js_callback_info_t *info) {
202
194
 
203
195
  req->env = env;
204
196
 
205
- uv_fs_open(loop, (uv_fs_t *) req, path, flags, mode, on_fs_response);
197
+ uv_fs_open(loop, (uv_fs_t *) req, (char *) path, flags, mode, on_fs_response);
206
198
 
207
199
  return NULL;
208
200
  }
@@ -214,7 +206,7 @@ bare_fs_open_sync (js_env_t *env, js_callback_info_t *info) {
214
206
 
215
207
  js_get_callback_info(env, info, &argc, argv, NULL, NULL);
216
208
 
217
- char path[4097];
209
+ utf8_t path[4097];
218
210
  js_get_value_string_utf8(env, argv[0], path, 4096, NULL);
219
211
 
220
212
  int32_t flags;
@@ -227,7 +219,7 @@ bare_fs_open_sync (js_env_t *env, js_callback_info_t *info) {
227
219
  js_get_env_loop(env, &loop);
228
220
 
229
221
  uv_fs_t req;
230
- uv_fs_open(loop, &req, path, flags, mode, NULL);
222
+ uv_fs_open(loop, &req, (char *) path, flags, mode, NULL);
231
223
 
232
224
  js_value_t *res;
233
225
  js_create_int32(env, req.result, &res);
@@ -556,10 +548,10 @@ bare_fs_rename (js_env_t *env, js_callback_info_t *info) {
556
548
  bare_fs_req_t *req;
557
549
  js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
558
550
 
559
- char src[4097];
551
+ utf8_t src[4097];
560
552
  js_get_value_string_utf8(env, argv[1], src, 4096, NULL);
561
553
 
562
- char dest[4097];
554
+ utf8_t dest[4097];
563
555
  js_get_value_string_utf8(env, argv[2], dest, 4096, NULL);
564
556
 
565
557
  uv_loop_t *loop;
@@ -567,7 +559,7 @@ bare_fs_rename (js_env_t *env, js_callback_info_t *info) {
567
559
 
568
560
  req->env = env;
569
561
 
570
- uv_fs_rename(loop, (uv_fs_t *) req, src, dest, on_fs_response);
562
+ uv_fs_rename(loop, (uv_fs_t *) req, (char *) src, (char *) dest, on_fs_response);
571
563
 
572
564
  return NULL;
573
565
  }
@@ -582,7 +574,7 @@ bare_fs_mkdir (js_env_t *env, js_callback_info_t *info) {
582
574
  bare_fs_req_t *req;
583
575
  js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
584
576
 
585
- char path[4097];
577
+ utf8_t path[4097];
586
578
  js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
587
579
 
588
580
  int32_t mode;
@@ -593,7 +585,7 @@ bare_fs_mkdir (js_env_t *env, js_callback_info_t *info) {
593
585
 
594
586
  req->env = env;
595
587
 
596
- uv_fs_mkdir(loop, (uv_fs_t *) req, path, mode, on_fs_response);
588
+ uv_fs_mkdir(loop, (uv_fs_t *) req, (char *) path, mode, on_fs_response);
597
589
 
598
590
  return NULL;
599
591
  }
@@ -608,7 +600,7 @@ bare_fs_rmdir (js_env_t *env, js_callback_info_t *info) {
608
600
  bare_fs_req_t *req;
609
601
  js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
610
602
 
611
- char path[4097];
603
+ utf8_t path[4097];
612
604
  js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
613
605
 
614
606
  uv_loop_t *loop;
@@ -616,7 +608,7 @@ bare_fs_rmdir (js_env_t *env, js_callback_info_t *info) {
616
608
 
617
609
  req->env = env;
618
610
 
619
- uv_fs_rmdir(loop, (uv_fs_t *) req, path, on_fs_response);
611
+ uv_fs_rmdir(loop, (uv_fs_t *) req, (char *) path, on_fs_response);
620
612
 
621
613
  return NULL;
622
614
  }
@@ -631,7 +623,7 @@ bare_fs_stat (js_env_t *env, js_callback_info_t *info) {
631
623
  bare_fs_req_t *req;
632
624
  js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
633
625
 
634
- char path[4097];
626
+ utf8_t path[4097];
635
627
  js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
636
628
 
637
629
  void *data;
@@ -644,7 +636,7 @@ bare_fs_stat (js_env_t *env, js_callback_info_t *info) {
644
636
  req->env = env;
645
637
  req->buf = uv_buf_init(data, data_len);
646
638
 
647
- uv_fs_stat(loop, (uv_fs_t *) req, path, on_fs_stat_response);
639
+ uv_fs_stat(loop, (uv_fs_t *) req, (char *) path, on_fs_stat_response);
648
640
 
649
641
  return NULL;
650
642
  }
@@ -656,7 +648,7 @@ bare_fs_stat_sync (js_env_t *env, js_callback_info_t *info) {
656
648
 
657
649
  js_get_callback_info(env, info, &argc, argv, NULL, NULL);
658
650
 
659
- char path[4097];
651
+ utf8_t path[4097];
660
652
  js_get_value_string_utf8(env, argv[0], path, 4096, NULL);
661
653
 
662
654
  void *data;
@@ -667,7 +659,7 @@ bare_fs_stat_sync (js_env_t *env, js_callback_info_t *info) {
667
659
  js_get_env_loop(env, &loop);
668
660
 
669
661
  uv_fs_t req;
670
- uv_fs_stat(loop, &req, path, NULL);
662
+ uv_fs_stat(loop, &req, (char *) path, NULL);
671
663
 
672
664
  js_value_t *res;
673
665
  js_create_int32(env, req.result, &res);
@@ -690,7 +682,7 @@ bare_fs_lstat (js_env_t *env, js_callback_info_t *info) {
690
682
  bare_fs_req_t *req;
691
683
  js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
692
684
 
693
- char path[4097];
685
+ utf8_t path[4097];
694
686
  js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
695
687
 
696
688
  void *data;
@@ -703,7 +695,7 @@ bare_fs_lstat (js_env_t *env, js_callback_info_t *info) {
703
695
  req->env = env;
704
696
  req->buf = uv_buf_init((char *) data, data_len);
705
697
 
706
- uv_fs_lstat(loop, (uv_fs_t *) req, path, on_fs_stat_response);
698
+ uv_fs_lstat(loop, (uv_fs_t *) req, (char *) path, on_fs_stat_response);
707
699
 
708
700
  return NULL;
709
701
  }
@@ -715,7 +707,7 @@ bare_fs_lstat_sync (js_env_t *env, js_callback_info_t *info) {
715
707
 
716
708
  js_get_callback_info(env, info, &argc, argv, NULL, NULL);
717
709
 
718
- char path[4097];
710
+ utf8_t path[4097];
719
711
  js_get_value_string_utf8(env, argv[0], path, 4096, NULL);
720
712
 
721
713
  void *data;
@@ -726,7 +718,7 @@ bare_fs_lstat_sync (js_env_t *env, js_callback_info_t *info) {
726
718
  js_get_env_loop(env, &loop);
727
719
 
728
720
  uv_fs_t req;
729
- uv_fs_lstat(loop, &req, path, NULL);
721
+ uv_fs_lstat(loop, &req, (char *) path, NULL);
730
722
 
731
723
  js_value_t *res;
732
724
  js_create_int32(env, req.result, &res);
@@ -808,7 +800,7 @@ bare_fs_unlink (js_env_t *env, js_callback_info_t *info) {
808
800
  bare_fs_req_t *req;
809
801
  js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
810
802
 
811
- char path[4097];
803
+ utf8_t path[4097];
812
804
  js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
813
805
 
814
806
  uv_loop_t *loop;
@@ -816,7 +808,7 @@ bare_fs_unlink (js_env_t *env, js_callback_info_t *info) {
816
808
 
817
809
  req->env = env;
818
810
 
819
- uv_fs_unlink(loop, (uv_fs_t *) req, path, on_fs_response);
811
+ uv_fs_unlink(loop, (uv_fs_t *) req, (char *) path, on_fs_response);
820
812
 
821
813
  return NULL;
822
814
  }
@@ -831,7 +823,7 @@ bare_fs_readlink (js_env_t *env, js_callback_info_t *info) {
831
823
  bare_fs_req_t *req;
832
824
  js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
833
825
 
834
- char path[4097];
826
+ utf8_t path[4097];
835
827
  js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
836
828
 
837
829
  void *data;
@@ -844,75 +836,11 @@ bare_fs_readlink (js_env_t *env, js_callback_info_t *info) {
844
836
  req->env = env;
845
837
  req->buf = uv_buf_init((char *) data, data_len);
846
838
 
847
- uv_fs_readlink(loop, (uv_fs_t *) req, path, on_fs_readlink_response);
839
+ uv_fs_readlink(loop, (uv_fs_t *) req, (char *) path, on_fs_readlink_response);
848
840
 
849
841
  return NULL;
850
842
  }
851
843
 
852
- static js_value_t *
853
- bare_fs_opendir (js_env_t *env, js_callback_info_t *info) {
854
- size_t argc = 3;
855
- js_value_t *argv[3];
856
-
857
- js_get_callback_info(env, info, &argc, argv, NULL, NULL);
858
-
859
- bare_fs_req_t *req;
860
- js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
861
-
862
- char path[4097];
863
- js_get_value_string_utf8(env, argv[1], path, 4096, NULL);
864
-
865
- void *data;
866
- size_t data_len;
867
- js_get_typedarray_info(env, argv[2], NULL, &data, &data_len, NULL, NULL);
868
-
869
- uv_loop_t *loop;
870
- js_get_env_loop(env, &loop);
871
-
872
- req->env = env;
873
- req->buf = uv_buf_init((char *) data, data_len);
874
-
875
- uv_fs_opendir(loop, (uv_fs_t *) req, path, on_fs_opendir_response);
876
-
877
- return NULL;
878
- }
879
-
880
- static js_value_t *
881
- bare_fs_readdir (js_env_t *env, js_callback_info_t *info) {
882
- size_t argc = 3;
883
- js_value_t *argv[3];
884
-
885
- js_get_callback_info(env, info, &argc, argv, NULL, NULL);
886
-
887
- bare_fs_req_t *req;
888
- js_get_typedarray_info(env, argv[0], NULL, (void **) &req, NULL, NULL, NULL);
889
-
890
- uv_dir_t **dir;
891
- js_get_typedarray_info(env, argv[1], NULL, (void **) &dir, NULL, NULL, NULL);
892
-
893
- void *data;
894
- size_t data_len;
895
- js_get_typedarray_info(env, argv[2], NULL, &data, &data_len, NULL, NULL);
896
-
897
- uv_loop_t *loop;
898
- js_get_env_loop(env, &loop);
899
-
900
- req->env = env;
901
- req->buf = uv_buf_init((char *) data, data_len);
902
-
903
- (*dir)->dirents = data;
904
- (*dir)->nentries = data_len / sizeof(uv_dirent_t);
905
-
906
- uv_fs_readdir(loop, (uv_fs_t *) req, *dir, on_fs_readdir_response);
907
-
908
- return NULL;
909
- }
910
-
911
- static js_value_t *
912
- bare_fs_to_dirent (js_env_t *env, js_callback_info_t *info) {
913
- return NULL;
914
- }
915
-
916
844
  static js_value_t *
917
845
  init (js_env_t *env, js_value_t *exports) {
918
846
  {
@@ -1065,21 +993,6 @@ init (js_env_t *env, js_value_t *exports) {
1065
993
  js_create_function(env, "readlink", -1, bare_fs_readlink, NULL, &fn);
1066
994
  js_set_named_property(env, exports, "readlink", fn);
1067
995
  }
1068
- {
1069
- js_value_t *fn;
1070
- js_create_function(env, "opendir", -1, bare_fs_opendir, NULL, &fn);
1071
- js_set_named_property(env, exports, "opendir", fn);
1072
- }
1073
- {
1074
- js_value_t *fn;
1075
- js_create_function(env, "readdir", -1, bare_fs_readdir, NULL, &fn);
1076
- js_set_named_property(env, exports, "readdir", fn);
1077
- }
1078
- {
1079
- js_value_t *fn;
1080
- js_create_function(env, "toDirent", -1, bare_fs_to_dirent, NULL, &fn);
1081
- js_set_named_property(env, exports, "toDirent", fn);
1082
- }
1083
996
  {
1084
997
  js_value_t *val;
1085
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.3",
3
+ "version": "1.5.5",
4
4
  "description": "Native file system for Javascript",
5
5
  "main": "index.js",
6
6
  "files": [