@xen-orchestra/fs 3.1.0 → 3.3.0

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/dist/abstract.js CHANGED
@@ -4,121 +4,93 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _legacy = _interopRequireDefault(require("@xen-orchestra/async-map/legacy"));
9
-
10
8
  var _assert = _interopRequireDefault(require("assert"));
11
-
12
9
  var _getStream = _interopRequireDefault(require("get-stream"));
13
-
14
10
  var _coalesceCalls = require("@vates/coalesce-calls");
15
-
16
11
  var _log = require("@xen-orchestra/log");
17
-
18
12
  var _promiseToolbox = require("promise-toolbox");
19
-
20
13
  var _limitConcurrencyDecorator = require("limit-concurrency-decorator");
21
-
22
14
  var _xoRemoteParser = require("xo-remote-parser");
23
-
24
15
  var _stream = require("stream");
25
-
26
16
  var _crypto = require("crypto");
27
-
28
17
  var _decoratorSynchronized = require("decorator-synchronized");
29
-
30
18
  var _path = require("./path");
31
-
32
19
  var _checksum = require("./checksum");
33
-
34
20
  var _encryptor = require("./_encryptor");
35
-
36
21
  var _dec, _dec2, _class;
37
-
38
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
-
40
23
  function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
41
-
42
24
  const {
43
25
  info,
44
26
  warn
45
27
  } = (0, _log.createLogger)('@xen-orchestra:fs');
46
-
47
28
  const checksumFile = file => file + '.checksum';
48
-
49
29
  const computeRate = (hrtime, size) => {
50
30
  const seconds = hrtime[0] + hrtime[1] / 1e9;
51
31
  return size / seconds;
52
32
  };
53
-
54
33
  const DEFAULT_TIMEOUT = 6e5;
55
34
  const DEFAULT_MAX_PARALLEL_OPERATIONS = 10;
56
35
  const ENCRYPTION_DESC_FILENAME = 'encryption.json';
57
36
  const ENCRYPTION_METADATA_FILENAME = 'metadata.json';
58
-
59
37
  const ignoreEnoent = error => {
60
38
  if (error == null || error.code !== 'ENOENT') {
61
39
  throw error;
62
40
  }
63
41
  };
64
-
65
42
  const noop = Function.prototype;
66
-
67
43
  class PrefixWrapper {
68
44
  constructor(handler, prefix) {
69
45
  this._prefix = prefix;
70
46
  this._handler = handler;
71
47
  }
72
-
73
48
  get type() {
74
49
  return this._handler.type;
75
50
  }
76
51
 
77
52
  async list(dir, opts) {
78
53
  const entries = await this._handler.list(this._resolve(dir), opts);
79
-
80
54
  if (opts != null && opts.prependDir) {
81
55
  const n = this._prefix.length;
82
56
  entries.forEach((entry, i, entries) => {
83
57
  entries[i] = entry.slice(n);
84
58
  });
85
59
  }
86
-
87
60
  return entries;
88
61
  }
89
-
90
62
  rename(oldPath, newPath) {
91
63
  return this._handler.rename(this._resolve(oldPath), this._resolve(newPath));
92
64
  }
93
-
94
65
  _resolve(path) {
95
66
  return this._prefix + (0, _path.normalize)(path);
96
67
  }
97
-
98
68
  }
99
-
100
69
  let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(), _dec2 = (0, _decoratorSynchronized.synchronized)(), (_class = class RemoteHandlerAbstract {
101
- _encryptor;
102
-
70
+ #encryptor;
71
+ get _encryptor() {
72
+ if (this.#encryptor === undefined) {
73
+ throw new Error(`Can't access to encryptor before remote synchronization`);
74
+ }
75
+ return this.#encryptor;
76
+ }
103
77
  constructor(remote, options = {}) {
104
78
  if (remote.url === 'test://') {
105
79
  this._remote = remote;
106
80
  } else {
107
- this._remote = { ...remote,
81
+ this._remote = {
82
+ ...remote,
108
83
  ...(0, _xoRemoteParser.parse)(remote.url)
109
84
  };
110
-
111
85
  if (this._remote.type !== this.type) {
112
86
  throw new Error('Incorrect remote type');
113
87
  }
114
88
  }
115
-
116
89
  ;
117
90
  ({
118
91
  highWaterMark: this._highWaterMark,
119
92
  timeout: this._timeout = DEFAULT_TIMEOUT
120
93
  } = options);
121
- this._encryptor = (0, _encryptor._getEncryptor)(this._remote.encryptionKey);
122
94
  const sharedLimit = (0, _limitConcurrencyDecorator.limitConcurrency)(options.maxParallelOperations ?? DEFAULT_MAX_PARALLEL_OPERATIONS);
123
95
  this.closeFile = sharedLimit(this.closeFile);
124
96
  this.copy = sharedLimit(this.copy);
@@ -143,16 +115,13 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
143
115
  get type() {
144
116
  throw new Error('Not implemented');
145
117
  }
146
-
147
118
  addPrefix(prefix) {
148
119
  prefix = (0, _path.normalize)(prefix);
149
120
  return prefix === '/' ? this : new PrefixWrapper(this, prefix);
150
121
  }
151
-
152
122
  async closeFile(fd) {
153
123
  await this.__closeFile(fd);
154
124
  }
155
-
156
125
  async createReadStream(file, {
157
126
  checksum = false,
158
127
  ignoreMissingChecksum = false,
@@ -161,16 +130,15 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
161
130
  if (options.end !== undefined || options.start !== undefined) {
162
131
  _assert.default.strictEqual(this.isEncrypted, false, `Can't read part of a file when encryption is active ${file}`);
163
132
  }
164
-
165
133
  if (typeof file === 'string') {
166
134
  file = (0, _path.normalize)(file);
167
135
  }
168
-
169
- let stream = await _promiseToolbox.timeout.call(this._createReadStream(file, { ...options,
136
+ let stream = await _promiseToolbox.timeout.call(this._createReadStream(file, {
137
+ ...options,
170
138
  highWaterMark: this._highWaterMark
171
139
  }), this._timeout);
172
- await (0, _promiseToolbox.fromEvent)(stream, 'readable');
173
140
 
141
+ await (0, _promiseToolbox.fromEvent)(stream, 'readable');
174
142
  if (checksum) {
175
143
  try {
176
144
  const path = typeof file === 'string' ? file : file.path;
@@ -188,14 +156,14 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
188
156
  }
189
157
  }
190
158
  }
191
-
192
159
  if (this.isEncrypted) {
193
160
  stream = this._encryptor.decryptStream(stream);
194
161
  } else {
195
162
  if (stream.length === undefined && options.end === undefined && options.start === undefined) {
196
163
  try {
197
164
  stream.length = await this._getSize(file);
198
- } catch (error) {}
165
+ } catch (error) {
166
+ }
199
167
  }
200
168
  }
201
169
 
@@ -210,18 +178,15 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
210
178
  path = (0, _path.normalize)(path);
211
179
  let checksumStream;
212
180
  input = this._encryptor.encryptStream(input);
213
-
214
181
  if (checksum) {
215
182
  checksumStream = (0, _checksum.createChecksumStream)();
216
183
  (0, _stream.pipeline)(input, checksumStream, noop);
217
184
  input = checksumStream;
218
185
  }
219
-
220
186
  await this._outputStream(path, input, {
221
187
  dirMode,
222
188
  validator
223
189
  });
224
-
225
190
  if (checksum) {
226
191
  await this._outputFile(checksumFile(path), await checksumStream.checksum, {
227
192
  dirMode,
@@ -233,18 +198,15 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
233
198
  async forget() {
234
199
  await this._forget();
235
200
  }
236
-
237
201
  async getInfo() {
238
202
  return _promiseToolbox.timeout.call(this._getInfo(), this._timeout);
239
203
  }
240
204
 
241
205
  async getSize(file) {
242
206
  _assert.default.strictEqual(this.isEncrypted, false, `Can't compute size of an encrypted file ${file}`);
243
-
244
207
  const size = await _promiseToolbox.timeout.call(this._getSize(typeof file === 'string' ? (0, _path.normalize)(file) : file), this._timeout);
245
208
  return size - this._encryptor.ivLength;
246
209
  }
247
-
248
210
  async list(dir, {
249
211
  filter,
250
212
  ignoreMissing = false,
@@ -254,34 +216,28 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
254
216
  const virtualDir = (0, _path.normalize)(dir);
255
217
  dir = (0, _path.normalize)(dir);
256
218
  let entries = await _promiseToolbox.timeout.call(this._list(dir), this._timeout);
257
-
258
219
  if (filter !== undefined) {
259
220
  entries = entries.filter(filter);
260
221
  }
261
-
262
222
  if (prependDir) {
263
223
  entries.forEach((entry, i) => {
264
224
  entries[i] = virtualDir + '/' + entry;
265
225
  });
266
226
  }
267
-
268
227
  return entries;
269
228
  } catch (error) {
270
229
  if (ignoreMissing && (error === null || error === void 0 ? void 0 : error.code) === 'ENOENT') {
271
230
  return [];
272
231
  }
273
-
274
232
  throw error;
275
233
  }
276
234
  }
277
-
278
235
  async lock(path) {
279
236
  path = (0, _path.normalize)(path);
280
237
  return {
281
238
  dispose: await this._lock(path)
282
239
  };
283
240
  }
284
-
285
241
  async mkdir(dir, {
286
242
  mode
287
243
  } = {}) {
@@ -289,7 +245,6 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
289
245
  mode
290
246
  });
291
247
  }
292
-
293
248
  async mktree(dir, {
294
249
  mode
295
250
  } = {}) {
@@ -297,29 +252,23 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
297
252
  mode
298
253
  });
299
254
  }
300
-
301
255
  openFile(path, flags) {
302
256
  return this.__openFile(path, flags);
303
257
  }
304
-
305
258
  async outputFile(file, data, {
306
259
  dirMode,
307
260
  flags = 'wx'
308
261
  } = {}) {
309
262
  const encryptedData = this._encryptor.encryptData(data);
310
-
311
263
  await this._outputFile((0, _path.normalize)(file), encryptedData, {
312
264
  dirMode,
313
265
  flags
314
266
  });
315
267
  }
316
-
317
268
  async read(file, buffer, position) {
318
269
  _assert.default.strictEqual(this.isEncrypted, false, `Can't read part of an encrypted file ${file}`);
319
-
320
270
  return this._read(typeof file === 'string' ? (0, _path.normalize)(file) : file, buffer, position);
321
271
  }
322
-
323
272
  async readFile(file, {
324
273
  flags = 'r'
325
274
  } = {}) {
@@ -328,48 +277,52 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
328
277
  });
329
278
  return this._encryptor.decryptData(data);
330
279
  }
331
-
332
- async rename(oldPath, newPath, {
280
+ async #rename(oldPath, newPath, {
281
+ checksum
282
+ }, createTree = true) {
283
+ try {
284
+ let p = _promiseToolbox.timeout.call(this._rename(oldPath, newPath), this._timeout);
285
+ if (checksum) {
286
+ p = Promise.all([p, this._rename(checksumFile(oldPath), checksumFile(newPath))]);
287
+ }
288
+ await p;
289
+ } catch (error) {
290
+ if (error.code === 'ENOENT' && createTree) {
291
+ await this._mktree((0, _path.dirname)(newPath));
292
+ return this.#rename(oldPath, newPath, {
293
+ checksum
294
+ }, false);
295
+ }
296
+ throw error;
297
+ }
298
+ }
299
+ rename(oldPath, newPath, {
333
300
  checksum = false
334
301
  } = {}) {
335
- oldPath = (0, _path.normalize)(oldPath);
336
- newPath = (0, _path.normalize)(newPath);
337
-
338
- let p = _promiseToolbox.timeout.call(this._rename(oldPath, newPath), this._timeout);
339
-
340
- if (checksum) {
341
- p = Promise.all([p, this._rename(checksumFile(oldPath), checksumFile(newPath))]);
342
- }
343
-
344
- return p;
302
+ return this.#rename((0, _path.normalize)(oldPath), (0, _path.normalize)(newPath), {
303
+ checksum
304
+ });
345
305
  }
346
-
347
306
  async copy(oldPath, newPath, {
348
307
  checksum = false
349
308
  } = {}) {
350
309
  oldPath = (0, _path.normalize)(oldPath);
351
310
  newPath = (0, _path.normalize)(newPath);
352
-
353
311
  let p = _promiseToolbox.timeout.call(this._copy(oldPath, newPath), this._timeout);
354
-
355
312
  if (checksum) {
356
313
  p = Promise.all([p, this._copy(checksumFile(oldPath), checksumFile(newPath))]);
357
314
  }
358
-
359
315
  return p;
360
316
  }
361
-
362
317
  async rmdir(dir) {
363
318
  await _promiseToolbox.timeout.call(this._rmdir((0, _path.normalize)(dir)).catch(ignoreEnoent), this._timeout);
364
319
  }
365
-
366
320
  async rmtree(dir) {
367
321
  await this._rmtree((0, _path.normalize)(dir));
368
322
  }
369
323
 
370
324
  async sync() {
371
325
  await this._sync();
372
-
373
326
  try {
374
327
  await this._checkMetadata();
375
328
  } catch (error) {
@@ -377,56 +330,62 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
377
330
  throw error;
378
331
  }
379
332
  }
380
-
381
333
  async _canWriteMetadata() {
382
334
  const list = await this.list('/', {
383
335
  filter: e => !e.startsWith('.') && e !== ENCRYPTION_DESC_FILENAME && e !== ENCRYPTION_METADATA_FILENAME
384
336
  });
385
337
  return list.length === 0;
386
338
  }
387
-
388
339
  async _createMetadata() {
340
+ const encryptionAlgorithm = this._remote.encryptionKey === undefined ? 'none' : _encryptor.DEFAULT_ENCRYPTION_ALGORITHM;
341
+ this.#encryptor = (0, _encryptor._getEncryptor)(encryptionAlgorithm, this._remote.encryptionKey);
389
342
  await Promise.all([this._writeFile((0, _path.normalize)(ENCRYPTION_DESC_FILENAME), JSON.stringify({
390
- algorithm: this._encryptor.algorithm
343
+ algorithm: encryptionAlgorithm
391
344
  }), {
392
345
  flags: 'w'
393
- }), this.writeFile(ENCRYPTION_METADATA_FILENAME, `{"random":"${(0, _crypto.randomUUID)()}"}`, {
346
+ }),
347
+ this.writeFile(ENCRYPTION_METADATA_FILENAME, `{"random":"${(0, _crypto.randomUUID)()}"}`, {
394
348
  flags: 'w'
395
349
  })]);
396
350
  }
397
351
 
398
352
  async _checkMetadata() {
353
+ let encryptionAlgorithm = 'none';
354
+ let data;
399
355
  try {
400
- const data = await this._readFile((0, _path.normalize)(ENCRYPTION_DESC_FILENAME));
401
- JSON.parse(data);
356
+ data = await this._readFile((0, _path.normalize)(ENCRYPTION_DESC_FILENAME), 'utf-8');
357
+ const json = JSON.parse(data);
358
+ encryptionAlgorithm = json.algorithm;
402
359
  } catch (error) {
403
360
  if (error.code !== 'ENOENT') {
404
361
  throw error;
405
362
  }
363
+ encryptionAlgorithm = this._remote.encryptionKey === undefined ? 'none' : _encryptor.DEFAULT_ENCRYPTION_ALGORITHM;
406
364
  }
407
-
408
365
  try {
409
- const data = await this.readFile(ENCRYPTION_METADATA_FILENAME);
366
+ this.#encryptor = (0, _encryptor._getEncryptor)(encryptionAlgorithm, this._remote.encryptionKey);
367
+ const data = await this.readFile(ENCRYPTION_METADATA_FILENAME, 'utf-8');
410
368
  JSON.parse(data);
411
369
  } catch (error) {
412
- if (error.code === 'ENOENT' || (await this._canWriteMetadata())) {
413
- info('will update metadata of this remote');
414
- return this._createMetadata();
370
+ if (encryptionAlgorithm !== 'none') {
371
+ if (await this._canWriteMetadata()) {
372
+
373
+ info('will update metadata of this remote');
374
+ return this._createMetadata();
375
+ } else {
376
+ warn(`The encryptionKey settings of this remote does not match the key used to create it. You won't be able to read any data from this remote`, {
377
+ error
378
+ });
379
+ throw error;
380
+ }
415
381
  }
416
-
417
- warn(`The encryptionKey settings of this remote does not match the key used to create it. You won't be able to read any data from this remote`, {
418
- error
419
- });
420
- throw error;
421
382
  }
422
383
  }
423
-
424
384
  async test() {
425
385
  const SIZE = 1024 * 1024 * 10;
426
386
  const testFileName = (0, _path.normalize)(`${Date.now()}.test`);
427
387
  const data = await (0, _promiseToolbox.fromCallback)(_crypto.randomBytes, SIZE);
428
388
  let step = 'write';
429
-
430
389
  try {
431
390
  const writeStart = process.hrtime();
432
391
  await this._outputFile(testFileName, data, {
@@ -439,11 +398,9 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
439
398
  flags: 'r'
440
399
  });
441
400
  const readDuration = process.hrtime(readStart);
442
-
443
401
  if (!data.equals(read)) {
444
402
  throw new Error('output and input did not match');
445
403
  }
446
-
447
404
  return {
448
405
  success: true,
449
406
  writeRate: computeRate(writeDuration, SIZE),
@@ -463,34 +420,26 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
463
420
  _promiseToolbox.ignoreErrors.call(this._unlink(testFileName));
464
421
  }
465
422
  }
466
-
467
423
  async truncate(file, len) {
468
424
  await this._truncate(file, len);
469
425
  }
470
-
471
426
  async unlink(file, {
472
427
  checksum = true
473
428
  } = {}) {
474
429
  file = (0, _path.normalize)(file);
475
-
476
430
  if (checksum) {
477
431
  _promiseToolbox.ignoreErrors.call(this._unlink(checksumFile(file)));
478
432
  }
479
-
480
433
  await this._unlink(file).catch(ignoreEnoent);
481
434
  }
482
-
483
435
  async write(file, buffer, position) {
484
436
  _assert.default.strictEqual(this.isEncrypted, false, `Can't write part of a file with encryption ${file}`);
485
-
486
437
  await this._write(typeof file === 'string' ? (0, _path.normalize)(file) : file, buffer, position);
487
438
  }
488
-
489
439
  async writeFile(file, data, {
490
440
  flags = 'wx'
491
441
  } = {}) {
492
442
  const encryptedData = this._encryptor.encryptData(data);
493
-
494
443
  await this._writeFile((0, _path.normalize)(file), encryptedData, {
495
444
  flags
496
445
  });
@@ -499,7 +448,6 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
499
448
  async __closeFile(fd) {
500
449
  await _promiseToolbox.timeout.call(this._closeFile(fd.fd), this._timeout);
501
450
  }
502
-
503
451
  async __mkdir(dir, {
504
452
  mode
505
453
  } = {}) {
@@ -515,7 +463,6 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
515
463
  await this._list(dir);
516
464
  }
517
465
  }
518
-
519
466
  async __openFile(path, flags) {
520
467
  path = (0, _path.normalize)(path);
521
468
  return {
@@ -527,17 +474,16 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
527
474
  useVhdDirectory() {
528
475
  return this._remote.useVhdDirectory ?? false;
529
476
  }
530
-
531
477
  async _closeFile(fd) {
532
478
  throw new Error('Not implemented');
533
479
  }
534
-
535
480
  async _createOutputStream(file, {
536
481
  dirMode,
537
482
  ...options
538
483
  } = {}) {
539
484
  try {
540
- return await this._createWriteStream(file, { ...options,
485
+ return await this._createWriteStream(file, {
486
+ ...options,
541
487
  highWaterMark: this._highWaterMark
542
488
  });
543
489
  } catch (error) {
@@ -545,13 +491,11 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
545
491
  throw error;
546
492
  }
547
493
  }
548
-
549
494
  await this._mktree((0, _path.dirname)(file), {
550
495
  mode: dirMode
551
496
  });
552
497
  return this._createOutputStream(file, options);
553
498
  }
554
-
555
499
  async _createReadStream(file, options) {
556
500
  throw new Error('Not implemented');
557
501
  }
@@ -561,27 +505,21 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
561
505
  }
562
506
 
563
507
  async _forget() {}
564
-
565
508
  async _getInfo() {
566
509
  return {};
567
510
  }
568
-
569
511
  async _lock(path) {
570
512
  return () => Promise.resolve();
571
513
  }
572
-
573
514
  async _getSize(file) {
574
515
  throw new Error('Not implemented');
575
516
  }
576
-
577
517
  async _list(dir) {
578
518
  throw new Error('Not implemented');
579
519
  }
580
-
581
520
  async _mkdir(dir) {
582
521
  throw new Error('Not implemented');
583
522
  }
584
-
585
523
  async _mktree(dir, {
586
524
  mode
587
525
  } = {}) {
@@ -594,7 +532,6 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
594
532
  throw error;
595
533
  }
596
534
  }
597
-
598
535
  await this._mktree((0, _path.dirname)(dir), {
599
536
  mode
600
537
  });
@@ -602,11 +539,9 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
602
539
  mode
603
540
  });
604
541
  }
605
-
606
542
  async _openFile(path, flags) {
607
543
  throw new Error('Not implemented');
608
544
  }
609
-
610
545
  async _outputFile(file, data, {
611
546
  dirMode,
612
547
  flags
@@ -620,7 +555,6 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
620
555
  throw error;
621
556
  }
622
557
  }
623
-
624
558
  await this._mktree((0, _path.dirname)(file), {
625
559
  mode: dirMode
626
560
  });
@@ -628,7 +562,6 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
628
562
  flags
629
563
  });
630
564
  }
631
-
632
565
  async _outputStream(path, input, {
633
566
  dirMode,
634
567
  validator
@@ -638,43 +571,35 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
638
571
  dirMode,
639
572
  flags: 'wx'
640
573
  }), this._timeout);
641
-
642
574
  try {
643
575
  await (0, _promiseToolbox.fromCallback)(_stream.pipeline, input, output);
644
-
645
576
  if (validator !== undefined) {
646
577
  await validator.call(this, tmpPath);
647
578
  }
648
-
649
579
  await this.rename(tmpPath, path);
650
580
  } catch (error) {
651
581
  await this.unlink(tmpPath);
652
582
  throw error;
653
583
  }
654
584
  }
655
-
656
585
  _read(file, buffer, position) {
657
586
  throw new Error('Not implemented');
658
587
  }
659
-
660
588
  _readFile(file, options) {
661
- return this._createReadStream(file, { ...options,
589
+ return this._createReadStream(file, {
590
+ ...options,
662
591
  highWaterMark: this._highWaterMark
663
592
  }).then(_getStream.default.buffer);
664
593
  }
665
-
666
594
  async _rename(oldPath, newPath) {
667
595
  throw new Error('Not implemented');
668
596
  }
669
-
670
597
  async _copy(oldPath, newPath) {
671
598
  throw new Error('Not implemented');
672
599
  }
673
-
674
600
  async _rmdir(dir) {
675
601
  throw new Error('Not implemented');
676
602
  }
677
-
678
603
  async _rmtree(dir) {
679
604
  try {
680
605
  return await this._rmdir(dir);
@@ -683,31 +608,25 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
683
608
  throw error;
684
609
  }
685
610
  }
686
-
687
611
  const files = await this._list(dir);
688
612
  await (0, _legacy.default)(files, file => this._unlink(`${dir}/${file}`).catch(error => {
689
613
  if (error.code === 'EISDIR' || error.code === 'EPERM') {
690
614
  return this._rmtree(`${dir}/${file}`);
691
615
  }
692
-
693
616
  throw error;
694
617
  }));
695
618
  return this._rmtree(dir);
696
619
  }
697
620
 
698
621
  async _sync() {}
699
-
700
622
  async _unlink(file) {
701
623
  throw new Error('Not implemented');
702
624
  }
703
-
704
625
  async _write(file, buffer, position) {
705
626
  const isPath = typeof file === 'string';
706
-
707
627
  if (isPath) {
708
628
  file = await this.__openFile(file, 'r+');
709
629
  }
710
-
711
630
  try {
712
631
  return await this._writeFd(file, buffer, position);
713
632
  } finally {
@@ -716,22 +635,17 @@ let RemoteHandlerAbstract = (_dec = (0, _decoratorSynchronized.synchronized)(),
716
635
  }
717
636
  }
718
637
  }
719
-
720
638
  async _writeFd(fd, buffer, position) {
721
639
  throw new Error('Not implemented');
722
640
  }
723
-
724
641
  async _writeFile(file, data, options) {
725
642
  throw new Error('Not implemented');
726
643
  }
727
-
728
644
  get isEncrypted() {
729
645
  return this._encryptor.id !== 'NULL_ENCRYPTOR';
730
646
  }
731
-
732
647
  }, (_applyDecoratedDescriptor(_class.prototype, "forget", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "forget"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "sync", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "sync"), _class.prototype)), _class));
733
648
  exports.default = RemoteHandlerAbstract;
734
-
735
649
  function createPrefixWrapperMethods() {
736
650
  const pPw = PrefixWrapper.prototype;
737
651
  const pRha = RemoteHandlerAbstract.prototype;
@@ -744,24 +658,18 @@ function createPrefixWrapperMethods() {
744
658
  } = Object;
745
659
  Object.getOwnPropertyNames(pRha).forEach(name => {
746
660
  let descriptor, value;
747
-
748
661
  if (hasOwnProperty.call(pPw, name) || name[0] === '_' || typeof (value = (descriptor = getOwnPropertyDescriptor(pRha, name)).value) !== 'function') {
749
662
  return;
750
663
  }
751
-
752
664
  descriptor.value = function () {
753
665
  let path;
754
-
755
666
  if (arguments.length !== 0 && typeof (path = arguments[0]) === 'string') {
756
667
  arguments[0] = this._resolve(path);
757
668
  }
758
-
759
669
  return value.apply(this._handler, arguments);
760
670
  };
761
-
762
671
  defineProperty(pPw, name, descriptor);
763
672
  });
764
673
  }
765
-
766
674
  createPrefixWrapperMethods();
767
675
  //# sourceMappingURL=abstract.js.map