bare-fs 2.2.3 → 2.3.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 CHANGED
@@ -51,7 +51,7 @@ typedef struct {
51
51
  typedef uv_dirent_t bare_fs_dirent_t;
52
52
 
53
53
  static inline void
54
- on_fs_response (uv_fs_t *uv_req) {
54
+ bare_fs__on_response (uv_fs_t *uv_req) {
55
55
  int err;
56
56
 
57
57
  bare_fs_req_t *req = (bare_fs_req_t *) uv_req;
@@ -110,7 +110,7 @@ on_fs_response (uv_fs_t *uv_req) {
110
110
  }
111
111
 
112
112
  static void
113
- on_fs_stat_response (uv_fs_t *uv_req) {
113
+ bare_fs__on_stat_response (uv_fs_t *uv_req) {
114
114
  int err;
115
115
 
116
116
  bare_fs_req_t *req = (bare_fs_req_t *) uv_req;
@@ -170,11 +170,11 @@ on_fs_stat_response (uv_fs_t *uv_req) {
170
170
  assert(err == 0);
171
171
  }
172
172
 
173
- on_fs_response(uv_req);
173
+ bare_fs__on_response(uv_req);
174
174
  }
175
175
 
176
176
  static void
177
- on_fs_realpath_response (uv_fs_t *uv_req) {
177
+ bare_fs__on_realpath_response (uv_fs_t *uv_req) {
178
178
  int err;
179
179
 
180
180
  bare_fs_req_t *req = (bare_fs_req_t *) uv_req;
@@ -200,11 +200,11 @@ on_fs_realpath_response (uv_fs_t *uv_req) {
200
200
  assert(err == 0);
201
201
  }
202
202
 
203
- on_fs_response(uv_req);
203
+ bare_fs__on_response(uv_req);
204
204
  }
205
205
 
206
206
  static void
207
- on_fs_readlink_response (uv_fs_t *uv_req) {
207
+ bare_fs__on_readlink_response (uv_fs_t *uv_req) {
208
208
  int err;
209
209
 
210
210
  bare_fs_req_t *req = (bare_fs_req_t *) uv_req;
@@ -230,11 +230,11 @@ on_fs_readlink_response (uv_fs_t *uv_req) {
230
230
  assert(err == 0);
231
231
  }
232
232
 
233
- on_fs_response(uv_req);
233
+ bare_fs__on_response(uv_req);
234
234
  }
235
235
 
236
236
  static void
237
- on_fs_opendir_response (uv_fs_t *uv_req) {
237
+ bare_fs__on_opendir_response (uv_fs_t *uv_req) {
238
238
  int err;
239
239
 
240
240
  bare_fs_req_t *req = (bare_fs_req_t *) uv_req;
@@ -260,11 +260,11 @@ on_fs_opendir_response (uv_fs_t *uv_req) {
260
260
  assert(err == 0);
261
261
  }
262
262
 
263
- on_fs_response(uv_req);
263
+ bare_fs__on_response(uv_req);
264
264
  }
265
265
 
266
266
  static void
267
- on_fs_readdir_response (uv_fs_t *uv_req) {
267
+ bare_fs__on_readdir_response (uv_fs_t *uv_req) {
268
268
  int err;
269
269
 
270
270
  bare_fs_req_t *req = (bare_fs_req_t *) uv_req;
@@ -316,11 +316,11 @@ on_fs_readdir_response (uv_fs_t *uv_req) {
316
316
  assert(err == 0);
317
317
  }
318
318
 
319
- on_fs_response(uv_req);
319
+ bare_fs__on_response(uv_req);
320
320
  }
321
321
 
322
322
  static void
323
- on_fs_watcher_event (uv_fs_event_t *handle, const char *filename, int events, int status) {
323
+ bare_fs__on_watcher_event (uv_fs_event_t *handle, const char *filename, int events, int status) {
324
324
  int err;
325
325
 
326
326
  bare_fs_watcher_t *watcher = (bare_fs_watcher_t *) handle;
@@ -381,7 +381,7 @@ on_fs_watcher_event (uv_fs_event_t *handle, const char *filename, int events, in
381
381
  }
382
382
 
383
383
  static void
384
- on_fs_watcher_close (uv_handle_t *handle) {
384
+ bare_fs__on_watcher_close (uv_handle_t *handle) {
385
385
  int err;
386
386
 
387
387
  bare_fs_watcher_t *watcher = (bare_fs_watcher_t *) handle;
@@ -526,7 +526,7 @@ bare_fs_open (js_env_t *env, js_callback_info_t *info) {
526
526
  uv_loop_t *loop;
527
527
  js_get_env_loop(env, &loop);
528
528
 
529
- uv_fs_open(loop, (uv_fs_t *) req, (char *) path, flags, mode, on_fs_response);
529
+ uv_fs_open(loop, (uv_fs_t *) req, (char *) path, flags, mode, bare_fs__on_response);
530
530
 
531
531
  return NULL;
532
532
  }
@@ -598,7 +598,7 @@ bare_fs_close (js_env_t *env, js_callback_info_t *info) {
598
598
  uv_loop_t *loop;
599
599
  js_get_env_loop(env, &loop);
600
600
 
601
- uv_fs_close(loop, (uv_fs_t *) req, fd, on_fs_response);
601
+ uv_fs_close(loop, (uv_fs_t *) req, fd, bare_fs__on_response);
602
602
 
603
603
  return NULL;
604
604
  }
@@ -661,7 +661,7 @@ bare_fs_access (js_env_t *env, js_callback_info_t *info) {
661
661
  uv_loop_t *loop;
662
662
  js_get_env_loop(env, &loop);
663
663
 
664
- uv_fs_access(loop, (uv_fs_t *) req, (char *) path, mode, on_fs_response);
664
+ uv_fs_access(loop, (uv_fs_t *) req, (char *) path, mode, bare_fs__on_response);
665
665
 
666
666
  return NULL;
667
667
  }
@@ -746,7 +746,7 @@ bare_fs_read (js_env_t *env, js_callback_info_t *info) {
746
746
 
747
747
  uv_buf_t buf = uv_buf_init((void *) (data + offset), len);
748
748
 
749
- uv_fs_read(loop, (uv_fs_t *) req, fd, &buf, 1, pos, on_fs_response);
749
+ uv_fs_read(loop, (uv_fs_t *) req, fd, &buf, 1, pos, bare_fs__on_response);
750
750
 
751
751
  return NULL;
752
752
  }
@@ -852,7 +852,7 @@ bare_fs_readv (js_env_t *env, js_callback_info_t *info) {
852
852
  assert(err == 0);
853
853
  }
854
854
 
855
- uv_fs_read(loop, (uv_fs_t *) req, fd, bufs, bufs_len, pos, on_fs_response);
855
+ uv_fs_read(loop, (uv_fs_t *) req, fd, bufs, bufs_len, pos, bare_fs__on_response);
856
856
 
857
857
  free(bufs);
858
858
 
@@ -904,7 +904,7 @@ bare_fs_write (js_env_t *env, js_callback_info_t *info) {
904
904
 
905
905
  uv_buf_t buf = uv_buf_init((void *) (data + offset), len);
906
906
 
907
- uv_fs_write(loop, (uv_fs_t *) req, fd, &buf, 1, pos, on_fs_response);
907
+ uv_fs_write(loop, (uv_fs_t *) req, fd, &buf, 1, pos, bare_fs__on_response);
908
908
 
909
909
  return NULL;
910
910
  }
@@ -1010,7 +1010,7 @@ bare_fs_writev (js_env_t *env, js_callback_info_t *info) {
1010
1010
  assert(err == 0);
1011
1011
  }
1012
1012
 
1013
- uv_fs_write(loop, (uv_fs_t *) req, fd, bufs, bufs_len, pos, on_fs_response);
1013
+ uv_fs_write(loop, (uv_fs_t *) req, fd, bufs, bufs_len, pos, bare_fs__on_response);
1014
1014
 
1015
1015
  free(bufs);
1016
1016
 
@@ -1044,7 +1044,7 @@ bare_fs_ftruncate (js_env_t *env, js_callback_info_t *info) {
1044
1044
  uv_loop_t *loop;
1045
1045
  js_get_env_loop(env, &loop);
1046
1046
 
1047
- uv_fs_ftruncate(loop, (uv_fs_t *) req, fd, len, on_fs_response);
1047
+ uv_fs_ftruncate(loop, (uv_fs_t *) req, fd, len, bare_fs__on_response);
1048
1048
 
1049
1049
  return NULL;
1050
1050
  }
@@ -1076,7 +1076,7 @@ bare_fs_chmod (js_env_t *env, js_callback_info_t *info) {
1076
1076
  uv_loop_t *loop;
1077
1077
  js_get_env_loop(env, &loop);
1078
1078
 
1079
- uv_fs_chmod(loop, (uv_fs_t *) req, (char *) path, mode, on_fs_response);
1079
+ uv_fs_chmod(loop, (uv_fs_t *) req, (char *) path, mode, bare_fs__on_response);
1080
1080
 
1081
1081
  return NULL;
1082
1082
  }
@@ -1143,7 +1143,7 @@ bare_fs_fchmod (js_env_t *env, js_callback_info_t *info) {
1143
1143
  uv_loop_t *loop;
1144
1144
  js_get_env_loop(env, &loop);
1145
1145
 
1146
- uv_fs_fchmod(loop, (uv_fs_t *) req, fd, mode, on_fs_response);
1146
+ uv_fs_fchmod(loop, (uv_fs_t *) req, fd, mode, bare_fs__on_response);
1147
1147
 
1148
1148
  return NULL;
1149
1149
  }
@@ -1210,7 +1210,7 @@ bare_fs_rename (js_env_t *env, js_callback_info_t *info) {
1210
1210
  uv_loop_t *loop;
1211
1211
  js_get_env_loop(env, &loop);
1212
1212
 
1213
- uv_fs_rename(loop, (uv_fs_t *) req, (char *) src, (char *) dest, on_fs_response);
1213
+ uv_fs_rename(loop, (uv_fs_t *) req, (char *) src, (char *) dest, bare_fs__on_response);
1214
1214
 
1215
1215
  return NULL;
1216
1216
  }
@@ -1277,7 +1277,7 @@ bare_fs_mkdir (js_env_t *env, js_callback_info_t *info) {
1277
1277
  uv_loop_t *loop;
1278
1278
  js_get_env_loop(env, &loop);
1279
1279
 
1280
- uv_fs_mkdir(loop, (uv_fs_t *) req, (char *) path, mode, on_fs_response);
1280
+ uv_fs_mkdir(loop, (uv_fs_t *) req, (char *) path, mode, bare_fs__on_response);
1281
1281
 
1282
1282
  return NULL;
1283
1283
  }
@@ -1340,7 +1340,7 @@ bare_fs_rmdir (js_env_t *env, js_callback_info_t *info) {
1340
1340
  uv_loop_t *loop;
1341
1341
  js_get_env_loop(env, &loop);
1342
1342
 
1343
- uv_fs_rmdir(loop, (uv_fs_t *) req, (char *) path, on_fs_response);
1343
+ uv_fs_rmdir(loop, (uv_fs_t *) req, (char *) path, bare_fs__on_response);
1344
1344
 
1345
1345
  return NULL;
1346
1346
  }
@@ -1402,7 +1402,7 @@ bare_fs_stat (js_env_t *env, js_callback_info_t *info) {
1402
1402
  uv_loop_t *loop;
1403
1403
  js_get_env_loop(env, &loop);
1404
1404
 
1405
- uv_fs_stat(loop, (uv_fs_t *) req, (char *) path, on_fs_stat_response);
1405
+ uv_fs_stat(loop, (uv_fs_t *) req, (char *) path, bare_fs__on_stat_response);
1406
1406
 
1407
1407
  return NULL;
1408
1408
  }
@@ -1509,7 +1509,7 @@ bare_fs_lstat (js_env_t *env, js_callback_info_t *info) {
1509
1509
  uv_loop_t *loop;
1510
1510
  js_get_env_loop(env, &loop);
1511
1511
 
1512
- uv_fs_lstat(loop, (uv_fs_t *) req, (char *) path, on_fs_stat_response);
1512
+ uv_fs_lstat(loop, (uv_fs_t *) req, (char *) path, bare_fs__on_stat_response);
1513
1513
 
1514
1514
  return NULL;
1515
1515
  }
@@ -1616,7 +1616,7 @@ bare_fs_fstat (js_env_t *env, js_callback_info_t *info) {
1616
1616
  uv_loop_t *loop;
1617
1617
  js_get_env_loop(env, &loop);
1618
1618
 
1619
- uv_fs_fstat(loop, (uv_fs_t *) req, fd, on_fs_stat_response);
1619
+ uv_fs_fstat(loop, (uv_fs_t *) req, fd, bare_fs__on_stat_response);
1620
1620
 
1621
1621
  return NULL;
1622
1622
  }
@@ -1720,7 +1720,7 @@ bare_fs_unlink (js_env_t *env, js_callback_info_t *info) {
1720
1720
  uv_loop_t *loop;
1721
1721
  js_get_env_loop(env, &loop);
1722
1722
 
1723
- uv_fs_unlink(loop, (uv_fs_t *) req, (char *) path, on_fs_response);
1723
+ uv_fs_unlink(loop, (uv_fs_t *) req, (char *) path, bare_fs__on_response);
1724
1724
 
1725
1725
  return NULL;
1726
1726
  }
@@ -1782,7 +1782,7 @@ bare_fs_realpath (js_env_t *env, js_callback_info_t *info) {
1782
1782
  uv_loop_t *loop;
1783
1783
  js_get_env_loop(env, &loop);
1784
1784
 
1785
- uv_fs_realpath(loop, (uv_fs_t *) req, (char *) path, on_fs_realpath_response);
1785
+ uv_fs_realpath(loop, (uv_fs_t *) req, (char *) path, bare_fs__on_realpath_response);
1786
1786
 
1787
1787
  return NULL;
1788
1788
  }
@@ -1852,7 +1852,7 @@ bare_fs_readlink (js_env_t *env, js_callback_info_t *info) {
1852
1852
  uv_loop_t *loop;
1853
1853
  js_get_env_loop(env, &loop);
1854
1854
 
1855
- uv_fs_readlink(loop, (uv_fs_t *) req, (char *) path, on_fs_readlink_response);
1855
+ uv_fs_readlink(loop, (uv_fs_t *) req, (char *) path, bare_fs__on_readlink_response);
1856
1856
 
1857
1857
  return NULL;
1858
1858
  }
@@ -1925,7 +1925,7 @@ bare_fs_symlink (js_env_t *env, js_callback_info_t *info) {
1925
1925
  uv_loop_t *loop;
1926
1926
  js_get_env_loop(env, &loop);
1927
1927
 
1928
- uv_fs_symlink(loop, (uv_fs_t *) req, (char *) target, (char *) path, flags, on_fs_response);
1928
+ uv_fs_symlink(loop, (uv_fs_t *) req, (char *) target, (char *) path, flags, bare_fs__on_response);
1929
1929
 
1930
1930
  return NULL;
1931
1931
  }
@@ -1995,7 +1995,7 @@ bare_fs_opendir (js_env_t *env, js_callback_info_t *info) {
1995
1995
  uv_loop_t *loop;
1996
1996
  js_get_env_loop(env, &loop);
1997
1997
 
1998
- uv_fs_opendir(loop, (uv_fs_t *) req, (char *) path, on_fs_opendir_response);
1998
+ uv_fs_opendir(loop, (uv_fs_t *) req, (char *) path, bare_fs__on_opendir_response);
1999
1999
 
2000
2000
  return NULL;
2001
2001
  }
@@ -2073,7 +2073,7 @@ bare_fs_readdir (js_env_t *env, js_callback_info_t *info) {
2073
2073
  dir->dir->dirents = dirents;
2074
2074
  dir->dir->nentries = dirents_len / sizeof(bare_fs_dirent_t);
2075
2075
 
2076
- uv_fs_readdir(loop, (uv_fs_t *) req, dir->dir, on_fs_readdir_response);
2076
+ uv_fs_readdir(loop, (uv_fs_t *) req, dir->dir, bare_fs__on_readdir_response);
2077
2077
 
2078
2078
  return NULL;
2079
2079
  }
@@ -2172,7 +2172,7 @@ bare_fs_closedir (js_env_t *env, js_callback_info_t *info) {
2172
2172
  uv_loop_t *loop;
2173
2173
  js_get_env_loop(env, &loop);
2174
2174
 
2175
- uv_fs_closedir(loop, (uv_fs_t *) req, dir->dir, on_fs_response);
2175
+ uv_fs_closedir(loop, (uv_fs_t *) req, dir->dir, bare_fs__on_response);
2176
2176
 
2177
2177
  return NULL;
2178
2178
  }
@@ -2245,7 +2245,7 @@ bare_fs_watcher_init (js_env_t *env, js_callback_info_t *info) {
2245
2245
  return NULL;
2246
2246
  }
2247
2247
 
2248
- err = uv_fs_event_start(&watcher->handle, on_fs_watcher_event, (char *) path, recursive ? UV_FS_EVENT_RECURSIVE : 0);
2248
+ err = uv_fs_event_start(&watcher->handle, bare_fs__on_watcher_event, (char *) path, recursive ? UV_FS_EVENT_RECURSIVE : 0);
2249
2249
 
2250
2250
  if (err < 0) {
2251
2251
  js_throw_error(env, uv_err_name(err), uv_strerror(err));
@@ -2286,7 +2286,7 @@ bare_fs_watcher_close (js_env_t *env, js_callback_info_t *info) {
2286
2286
  err = uv_fs_event_stop(&watcher->handle);
2287
2287
  assert(err == 0);
2288
2288
 
2289
- uv_close((uv_handle_t *) &watcher->handle, on_fs_watcher_close);
2289
+ uv_close((uv_handle_t *) &watcher->handle, bare_fs__on_watcher_close);
2290
2290
 
2291
2291
  return NULL;
2292
2292
  }
@@ -2334,7 +2334,7 @@ bare_fs_watcher_unref (js_env_t *env, js_callback_info_t *info) {
2334
2334
  }
2335
2335
 
2336
2336
  static js_value_t *
2337
- init (js_env_t *env, js_value_t *exports) {
2337
+ bare_fs_exports (js_env_t *env, js_value_t *exports) {
2338
2338
  int err;
2339
2339
 
2340
2340
  {
@@ -2367,12 +2367,13 @@ init (js_env_t *env, js_value_t *exports) {
2367
2367
  js_create_uint32(env, sizeof(bare_fs_path_t), &val);
2368
2368
  js_set_named_property(env, exports, "sizeofFSPath", val);
2369
2369
  }
2370
+
2370
2371
  #define V(name, fn) \
2371
2372
  { \
2372
2373
  js_value_t *val; \
2373
2374
  err = js_create_function(env, name, -1, fn, NULL, &val); \
2374
2375
  assert(err == 0); \
2375
- js_set_named_property(env, exports, name, val); \
2376
+ err = js_set_named_property(env, exports, name, val); \
2376
2377
  assert(err == 0); \
2377
2378
  }
2378
2379
 
@@ -2519,4 +2520,4 @@ init (js_env_t *env, js_value_t *exports) {
2519
2520
  return exports;
2520
2521
  }
2521
2522
 
2522
- BARE_MODULE(bare_fs, init)
2523
+ BARE_MODULE(bare_fs, bare_fs_exports)
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* global Bare */
2
2
  const EventEmitter = require('bare-events')
3
3
  const path = require('bare-path')
4
- const { Readable, Writable } = require('streamx')
4
+ const { Readable, Writable } = require('bare-stream')
5
5
  const binding = require('./binding')
6
6
 
7
7
  const isWindows = Bare.platform === 'win32'
@@ -340,7 +340,7 @@ function readv (fd, buffers, pos, cb) {
340
340
  binding.readv(req.handle, fd, buffers, pos)
341
341
  }
342
342
 
343
- function write (fd, buffer, offset, len, pos, cb) {
343
+ function write (fd, data, offset, len, pos, cb) {
344
344
  if (typeof fd !== 'number') {
345
345
  throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
346
346
  }
@@ -349,19 +349,45 @@ function write (fd, buffer, offset, len, pos, cb) {
349
349
  throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
350
350
  }
351
351
 
352
- if (!Buffer.isBuffer(buffer) && !ArrayBuffer.isView(buffer)) {
353
- throw typeError('ERR_INVALID_ARG_TYPE', 'Buffer must be a buffer. Received type ' + (typeof buffer) + ' (' + buffer + ')')
352
+ if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
353
+ throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
354
354
  }
355
355
 
356
- if (typeof cb !== 'function') {
356
+ if (typeof data === 'string') {
357
+ let encoding = len
358
+ cb = pos
359
+ pos = offset
360
+
361
+ if (typeof cb !== 'function') {
362
+ if (typeof pos === 'function') {
363
+ cb = pos
364
+ pos = -1
365
+ encoding = 'utf8'
366
+ } else if (typeof encoding === 'function') {
367
+ cb = encoding
368
+ encoding = 'utf8'
369
+ } else {
370
+ throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
371
+ }
372
+ }
373
+
374
+ if (typeof pos === 'string') {
375
+ encoding = pos
376
+ pos = -1
377
+ }
378
+
379
+ data = Buffer.from(data, encoding)
380
+ offset = 0
381
+ len = data.byteLength
382
+ } else if (typeof cb !== 'function') {
357
383
  if (typeof offset === 'function') {
358
384
  cb = offset
359
385
  offset = 0
360
- len = buffer.byteLength
386
+ len = data.byteLength
361
387
  pos = -1
362
388
  } else if (typeof len === 'function') {
363
389
  cb = len
364
- len = buffer.byteLength - offset
390
+ len = data.byteLength - offset
365
391
  pos = -1
366
392
  } else if (typeof pos === 'function') {
367
393
  cb = pos
@@ -375,10 +401,10 @@ function write (fd, buffer, offset, len, pos, cb) {
375
401
 
376
402
  const req = getReq()
377
403
  req.callback = cb
378
- binding.write(req.handle, fd, buffer, offset, len, pos)
404
+ binding.write(req.handle, fd, data, offset, len, pos)
379
405
  }
380
406
 
381
- function writeSync (fd, buffer, offset = 0, len = buffer.byteLength - offset, pos = -1) {
407
+ function writeSync (fd, data, offset = 0, len, pos) {
382
408
  if (typeof fd !== 'number') {
383
409
  throw typeError('ERR_INVALID_ARG_TYPE', 'File descriptor must be a number. Received type ' + (typeof fd) + ' (' + fd + ')')
384
410
  }
@@ -387,11 +413,17 @@ function writeSync (fd, buffer, offset = 0, len = buffer.byteLength - offset, po
387
413
  throw typeError('ERR_OUT_OF_RANGE', 'File descriptor is out of range. It must be >= 0 && <= 2147483647. Received ' + fd)
388
414
  }
389
415
 
390
- if (!Buffer.isBuffer(buffer) && !ArrayBuffer.isView(buffer)) {
391
- throw typeError('ERR_INVALID_ARG_TYPE', 'Buffer must be a buffer. Received type ' + (typeof buffer) + ' (' + buffer + ')')
416
+ if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
417
+ throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
392
418
  }
393
419
 
394
- return binding.writeSync(fd, buffer, offset, len, pos)
420
+ if (typeof data === 'string') data = Buffer.from(data)
421
+
422
+ if (typeof len !== 'number') len = data.byteLength - offset
423
+
424
+ if (typeof pos !== 'number') pos = -1
425
+
426
+ return binding.writeSync(fd, data, offset, len, pos)
395
427
  }
396
428
 
397
429
  function writev (fd, buffers, pos, cb) {
@@ -1255,7 +1287,7 @@ function writeFile (filepath, data, opts, cb) {
1255
1287
  }
1256
1288
 
1257
1289
  if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
1258
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data) + ' (' + data + ')')
1290
+ throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
1259
1291
  }
1260
1292
 
1261
1293
  if (typeof opts === 'function') {
@@ -1302,7 +1334,7 @@ function writeFileSync (filepath, data, opts) {
1302
1334
  }
1303
1335
 
1304
1336
  if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
1305
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data) + ' (' + data + ')')
1337
+ throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
1306
1338
  }
1307
1339
 
1308
1340
  if (typeof opts === 'string') opts = { encoding: opts }
@@ -1332,7 +1364,7 @@ function appendFile (filepath, data, opts, cb) {
1332
1364
  }
1333
1365
 
1334
1366
  if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
1335
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data) + ' (' + data + ')')
1367
+ throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
1336
1368
  }
1337
1369
 
1338
1370
  if (typeof opts === 'function') {
@@ -1358,7 +1390,7 @@ function appendFileSync (filepath, data, opts) {
1358
1390
  }
1359
1391
 
1360
1392
  if (typeof data !== 'string' && !Buffer.isBuffer(data) && !ArrayBuffer.isView(data)) {
1361
- throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data) + ' (' + data + ')')
1393
+ throw typeError('ERR_INVALID_ARG_TYPE', 'Data must be a string or buffer. Received type ' + (typeof data))
1362
1394
  }
1363
1395
 
1364
1396
  if (typeof opts === 'string') opts = { encoding: opts }
@@ -1625,13 +1657,13 @@ class FileWriteStream extends Writable {
1625
1657
  })
1626
1658
  }
1627
1659
 
1628
- _writev (datas, cb) {
1629
- writev(this.fd, datas, cb)
1660
+ _writev (batch, cb) {
1661
+ writev(this.fd, batch.map(({ chunk }) => chunk), cb)
1630
1662
  }
1631
1663
 
1632
- _destroy (cb) {
1633
- if (!this.fd) return cb(null)
1634
- close(this.fd, () => cb(null))
1664
+ _destroy (err, cb) {
1665
+ if (!this.fd) return cb(err)
1666
+ close(this.fd, () => cb(err))
1635
1667
  }
1636
1668
  }
1637
1669
 
@@ -1678,20 +1710,20 @@ class FileReadStream extends Readable {
1678
1710
  })
1679
1711
  }
1680
1712
 
1681
- _read (cb) {
1713
+ _read (size) {
1682
1714
  if (!this._missing) {
1683
1715
  this.push(null)
1684
- return cb(null)
1716
+ return
1685
1717
  }
1686
1718
 
1687
- const data = Buffer.allocUnsafe(Math.min(this._missing, 65536))
1719
+ const data = Buffer.allocUnsafe(Math.min(this._missing, size))
1688
1720
 
1689
1721
  read(this.fd, data, 0, data.byteLength, this._offset, (err, read) => {
1690
- if (err) return cb(err)
1722
+ if (err) return this.destroy(err)
1691
1723
 
1692
1724
  if (!read) {
1693
1725
  this.push(null)
1694
- return cb(null)
1726
+ return
1695
1727
  }
1696
1728
 
1697
1729
  if (this._missing < read) read = this._missing
@@ -1699,14 +1731,12 @@ class FileReadStream extends Readable {
1699
1731
  this._missing -= read
1700
1732
  this._offset += read
1701
1733
  if (!this._missing) this.push(null)
1702
-
1703
- cb(null)
1704
1734
  })
1705
1735
  }
1706
1736
 
1707
- _destroy (cb) {
1708
- if (!this.fd) return cb(null)
1709
- close(this.fd, () => cb(null))
1737
+ _destroy (err, cb) {
1738
+ if (!this.fd) return cb(err)
1739
+ close(this.fd, () => cb(err))
1710
1740
  }
1711
1741
  }
1712
1742
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "2.2.3",
3
+ "version": "2.3.1",
4
4
  "description": "Native file system for Javascript",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "bare-events": "^2.0.0",
30
30
  "bare-path": "^2.0.0",
31
- "streamx": "^2.13.0"
31
+ "bare-stream": "^2.0.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "brittle": "^3.1.1",
Binary file
Binary file
Binary file
Binary file
Binary file