@e-mc/file-manager 0.7.1 → 0.8.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.
Files changed (2) hide show
  1. package/index.js +172 -146
  2. package/package.json +10 -10
package/index.js CHANGED
@@ -173,13 +173,13 @@ function checkHash(data, fromBuffer, options) {
173
173
  return false;
174
174
  }
175
175
  }
176
- return value === core_1.Host.asHash(data, { algorithm, digest });
176
+ return value.toLowerCase() === core_1.Host.asHash(data, { algorithm, digest });
177
177
  }
178
178
  }
179
179
  return true;
180
180
  }
181
181
  function validatePaths(values, patterns, include, dot) {
182
- const items = patterns.map(value => !value.startsWith('*') && /[\\/]/.test(value) ? [core_1.Permission.toPosix(path.resolve(value)), { nocase: PLATFORM_WIN32, dot }] : [value.replace(/\\/g, '/'), { matchBase: true, nocase: PLATFORM_WIN32, dot }]);
182
+ const items = patterns.map(value => !value.startsWith('*') && /[\\/]/.test(value) ? [core_1.Permission.toPosix(path.resolve(value)), { nocase: PLATFORM_WIN32, dot }] : [value.replace(/(?:^\\|\\+)/g, '/'), { matchBase: true, nocase: PLATFORM_WIN32, dot }]);
183
183
  return values.filter(value => {
184
184
  for (const [pattern, options] of items) {
185
185
  if (pm.isMatch(core_1.Permission.toPosix(value), pattern, options)) {
@@ -231,7 +231,7 @@ function observeFile(instance) {
231
231
  if (PLATFORM_WIN32) {
232
232
  value = value.toLowerCase();
233
233
  }
234
- if (value[value.length - 1] !== path.sep) {
234
+ if (!value.endsWith(path.sep)) {
235
235
  value += path.sep;
236
236
  }
237
237
  for (const name of this.files) {
@@ -560,44 +560,44 @@ class FileManager extends core_1.Host {
560
560
  return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
561
561
  }
562
562
  static loadSettings(settings, permission, password) {
563
- if (super.loadSettings(settings, permission, password)) {
564
- const { download, request, error, logger } = settings;
565
- if ((0, types_1.isPlainObject)(request)) {
566
- let { timeout, disk, buffer, connect } = request;
567
- if ((timeout = (0, util_1.fromSeconds)(timeout)) >= 0) {
568
- HTTP_CLIENT.timeout = timeout;
569
- }
570
- if (disk) {
571
- this.defineHttpCache(disk, true);
572
- }
573
- if (buffer) {
574
- this.defineHttpCache(buffer);
575
- }
576
- if (connect) {
577
- this.defineHttpConnect(connect);
578
- }
579
- request_1.default.loadSettings({ process: settings.process, request, download }, password);
563
+ if (!super.loadSettings(settings, permission, password)) {
564
+ return false;
565
+ }
566
+ const { download, request, error, logger } = settings;
567
+ if ((0, types_1.isPlainObject)(request)) {
568
+ let { timeout, disk, buffer, connect } = request;
569
+ if ((timeout = (0, util_1.fromSeconds)(timeout)) >= 0) {
570
+ HTTP_CLIENT.timeout = timeout;
580
571
  }
581
- if (error) {
582
- const value = (0, util_1.asInt)(error.recursion_limit);
583
- if (value >= 0 && value < Infinity) {
584
- RECURSION_LIMIT = value;
585
- }
572
+ if (disk) {
573
+ this.defineHttpCache(disk, true);
586
574
  }
587
- if (logger) {
588
- let value = logger.session_id;
589
- if (value === true) {
590
- SESSION_LIMIT = 1000;
591
- }
592
- else if (value && (value = +value) > 0) {
593
- SESSION_LIMIT = Math.pow(10, value);
594
- }
575
+ if (buffer) {
576
+ this.defineHttpCache(buffer);
595
577
  }
596
- LOG_TIMEELAPSED = this.hasLogType(128 /* LOG_TYPE.TIME_ELAPSED */);
597
- LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
598
- return true;
578
+ if (connect) {
579
+ this.defineHttpConnect(connect);
580
+ }
581
+ request_1.default.loadSettings({ process: settings.process, request, download }, password);
599
582
  }
600
- return false;
583
+ if (error) {
584
+ const value = (0, util_1.asInt)(error.recursion_limit);
585
+ if (value >= 0 && value < Infinity) {
586
+ RECURSION_LIMIT = value;
587
+ }
588
+ }
589
+ if (logger) {
590
+ let value = logger.session_id;
591
+ if (value === true) {
592
+ SESSION_LIMIT = 1000;
593
+ }
594
+ else if (value && (value = +value) > 0) {
595
+ SESSION_LIMIT = Math.pow(10, value);
596
+ }
597
+ }
598
+ LOG_TIMEELAPSED = this.hasLogType(128 /* LOG_TYPE.TIME_ELAPSED */);
599
+ LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
600
+ return true;
601
601
  }
602
602
  static sanitizeAssets(assets, exclusions = []) {
603
603
  assets.forEach(item => {
@@ -661,7 +661,7 @@ class FileManager extends core_1.Host {
661
661
  if (recursive === 1 && path.basename(pathname) === filename) {
662
662
  continue;
663
663
  }
664
- const current = await this.readHash(pathname, { algorithm, digest }) + ' ' + (path.sep === '\\' ? pathname.replace(/\\/g, '/') : pathname).substring(root.length).replace(/^\//, '');
664
+ const current = await this.readHash(pathname, { algorithm, digest }) + ' ' + (path.sep === '\\' ? pathname.replace(/(?:^\\|\\+)/g, '/') : pathname).substring(root.length).replace(/^\//, '');
665
665
  if (verbose) {
666
666
  process.stdout.write(current + '\n');
667
667
  }
@@ -697,9 +697,24 @@ class FileManager extends core_1.Host {
697
697
  else {
698
698
  options || (options = {});
699
699
  }
700
- const { algorithm, digest, sortBy = 0, recursive = false, ignore = [], include, exclude, verbose = true, joinRoot } = options;
700
+ const { digest, sortBy = 0, recursive = false, ignore = [], include, exclude, verbose = true, joinRoot } = options;
701
701
  const parent = recursive === 1 && typeof verbose !== 'number';
702
+ let algorithm = options.algorithm;
702
703
  from || (from = checksumFile(algorithm));
704
+ if (!algorithm) {
705
+ switch (algorithm = path.extname(from).substring(1).toLowerCase()) {
706
+ case 'md5':
707
+ case 'sha1':
708
+ case 'sha224':
709
+ case 'sha256':
710
+ case 'sha384':
711
+ case 'sha512':
712
+ break;
713
+ default:
714
+ algorithm = undefined;
715
+ break;
716
+ }
717
+ }
703
718
  let fail = [], missing = [];
704
719
  try {
705
720
  const filename = path.basename(from);
@@ -734,7 +749,7 @@ class FileManager extends core_1.Host {
734
749
  const nested = files.filter(value => path.basename(value) === filename);
735
750
  if (nested.length) {
736
751
  const current = items.map(item => item[1]);
737
- const tasks = nested.map(pathname => this.verifyChecksum(path.dirname(pathname), filename, { ...options, ignore: current, joinRoot: true, verbose: (verbose ? 1 : 0) }));
752
+ const tasks = nested.map(async (pathname) => this.verifyChecksum(path.dirname(pathname), filename, { ...options, ignore: current, joinRoot: true, verbose: (verbose ? 1 : 0) }));
738
753
  await Promise.all(tasks).then(group => {
739
754
  for (const item of group) {
740
755
  if (item) {
@@ -773,9 +788,12 @@ class FileManager extends core_1.Host {
773
788
  missing = Array.from(new Set(missing));
774
789
  }
775
790
  }
776
- if (verbose === true) {
791
+ if (verbose === true) { // eslint-disable-line @typescript-eslint/no-unnecessary-boolean-literal-compare
777
792
  const max = Math.max(...fail.concat(missing).map(item => item.length));
778
- const writeLog = (items, symbol) => items.forEach((value, index) => process.stdout.write(`${symbol} ${value.padEnd(max)} (${(index + 1).toString()})\n`));
793
+ const writeLog = (items, symbol) => {
794
+ const [bg, fg] = symbol === "-" /* SUMDIR_STATUS.FAIL */ ? ['\x1b[31m', '\x1b[89m'] : ['\x1b[33m', '\x1b[89m'];
795
+ items.forEach((value, index) => process.stdout.write(bg + symbol + ` ${value.padEnd(max)} (${(index + 1).toString()})${fg}\n`));
796
+ };
779
797
  writeLog(fail, "-" /* SUMDIR_STATUS.FAIL */);
780
798
  writeLog(missing, "?" /* SUMDIR_STATUS.MISSING */);
781
799
  }
@@ -1053,9 +1071,9 @@ class FileManager extends core_1.Host {
1053
1071
  get size() {
1054
1072
  return this.files.size;
1055
1073
  }
1056
- abort() {
1057
- this.Request.abort();
1058
- super.abort();
1074
+ abort(reason) {
1075
+ this.Request.abort(reason);
1076
+ super.abort(reason);
1059
1077
  }
1060
1078
  willAbort(value) {
1061
1079
  if ((0, types_1.isObject)(value)) {
@@ -1344,81 +1362,82 @@ class FileManager extends core_1.Host {
1344
1362
  else {
1345
1363
  ({ origin, pathname, href: value } = value);
1346
1364
  }
1347
- if (value) {
1348
- const isSame = (a, b) => a === b || decodeURIComponent(a) === decodeURIComponent(b);
1349
- const result = (assets || this.assets).filter(item => {
1350
- let { uri, flags } = item;
1351
- if (uri && (!instance || this.hasDocument(instance, item.document)) && (!item.invalid || assets || (0, types_1.mainFlag)(flags) || (0, types_1.usingFlag)(flags) || (0, types_1.cloneFlag)(flags) || (0, types_1.watchFlag)(flags))) {
1352
- if (origin) {
1353
- if (!item.url) {
1354
- try {
1355
- if ((item.url = new URL(uri)).href === value) {
1356
- return true;
1357
- }
1358
- }
1359
- catch {
1365
+ if (!(0, types_1.isString)(value)) {
1366
+ return;
1367
+ }
1368
+ const isSame = (a, b) => a === b || decodeURIComponent(a) === decodeURIComponent(b);
1369
+ const result = (assets || this.assets).filter(item => {
1370
+ let { uri, flags } = item;
1371
+ if (uri && (!instance || this.hasDocument(instance, item.document)) && (!item.invalid || assets || (0, types_1.mainFlag)(flags) || (0, types_1.usingFlag)(flags) || (0, types_1.cloneFlag)(flags) || (0, types_1.watchFlag)(flags))) {
1372
+ if (origin) {
1373
+ if (!item.url) {
1374
+ try {
1375
+ if ((item.url = new URL(uri)).href === value) {
1376
+ return true;
1360
1377
  }
1361
1378
  }
1362
- else if (item.url.href === value) {
1363
- return true;
1379
+ catch {
1364
1380
  }
1365
1381
  }
1366
- if (isSame(uri, value)) {
1382
+ else if (item.url.href === value) {
1367
1383
  return true;
1368
1384
  }
1369
- const indexA = uri.indexOf('#');
1370
- const indexB = value.indexOf('#');
1371
- if (indexA !== -1 || indexB !== -1) {
1372
- if (indexA !== -1) {
1373
- uri = uri.substring(0, indexA);
1374
- }
1375
- if (indexB !== -1) {
1376
- value = value.substring(0, indexB);
1377
- }
1378
- return isSame(uri, value);
1379
- }
1380
1385
  }
1381
- return false;
1382
- });
1383
- if (replaced) {
1384
- const map = this[kReplaceMap];
1385
- const target = pathname || core_1.Host.toPosix(value);
1386
- const found = [];
1387
- for (const relative in map) {
1388
- const item = map[relative];
1389
- if (origin && item.url && item.url.origin !== origin) {
1390
- continue;
1391
- }
1392
- if (path.basename(relative) === path.basename(target) && path.dirname(target).endsWith(path.dirname(relative))) {
1393
- found.push([item, relative]);
1394
- }
1386
+ if (isSame(uri, value)) {
1387
+ return true;
1395
1388
  }
1396
- if (found.length) {
1397
- if (result.length === 0) {
1398
- return found.sort((a, b) => b[1].length - a[1].length)[0][0];
1389
+ const indexA = uri.indexOf('#');
1390
+ const indexB = value.indexOf('#');
1391
+ if (indexA !== -1 || indexB !== -1) {
1392
+ if (indexA !== -1) {
1393
+ uri = uri.substring(0, indexA);
1394
+ }
1395
+ if (indexB !== -1) {
1396
+ value = value.substring(0, indexB);
1399
1397
  }
1400
- result.push(...found.map(item => item[0]));
1398
+ return isSame(uri, value);
1401
1399
  }
1402
1400
  }
1403
- return result.sort((a, b) => {
1404
- if ((a.content || a.base64) && !b.content && !b.base64 || a.uri === value && b.uri !== value) {
1405
- return -1;
1406
- }
1407
- if ((b.content || b.base64) && !a.content && !a.base64 || b.uri === value && a.uri !== value) {
1408
- return 1;
1401
+ return false;
1402
+ });
1403
+ if (replaced) {
1404
+ const map = this[kReplaceMap];
1405
+ const target = pathname || core_1.Host.toPosix(value);
1406
+ const found = [];
1407
+ for (const relative in map) {
1408
+ const item = map[relative];
1409
+ if (origin && item.url && item.url.origin !== origin) {
1410
+ continue;
1409
1411
  }
1410
- const bundleId = a.bundleId;
1411
- if (((0, types_1.isEmpty)(bundleId) || a.bundleIndex === 0) && ((0, types_1.isEmpty)(b.bundleId) || b.bundleIndex === 0)) {
1412
- if (a.id && b.id) {
1413
- return a.id < b.id ? -1 : 1;
1414
- }
1412
+ if (path.basename(relative) === path.basename(target) && path.dirname(target).endsWith(path.dirname(relative))) {
1413
+ found.push([item, relative]);
1415
1414
  }
1416
- else if (!(0, types_1.isEmpty)(bundleId) && bundleId === b.bundleId) {
1417
- return a.bundleIndex < b.bundleIndex ? -1 : 1;
1415
+ }
1416
+ if (found.length) {
1417
+ if (result.length === 0) {
1418
+ return found.sort((a, b) => b[1].length - a[1].length)[0][0];
1418
1419
  }
1419
- return 0;
1420
- })[0];
1420
+ result.push(...found.map(item => item[0]));
1421
+ }
1421
1422
  }
1423
+ return result.sort((a, b) => {
1424
+ if ((a.content || a.base64) && !b.content && !b.base64 || a.uri === value && b.uri !== value) {
1425
+ return -1;
1426
+ }
1427
+ if ((b.content || b.base64) && !a.content && !a.base64 || b.uri === value && a.uri !== value) {
1428
+ return 1;
1429
+ }
1430
+ const bundleId = a.bundleId;
1431
+ if (((0, types_1.isEmpty)(bundleId) || a.bundleIndex === 0) && ((0, types_1.isEmpty)(b.bundleId) || b.bundleIndex === 0)) {
1432
+ if (a.id && b.id) {
1433
+ return a.id < b.id ? -1 : 1;
1434
+ }
1435
+ }
1436
+ else if (!(0, types_1.isEmpty)(bundleId) && bundleId === b.bundleId) {
1437
+ return a.bundleIndex < b.bundleIndex ? -1 : 1;
1438
+ }
1439
+ return 0;
1440
+ })[0];
1422
1441
  }
1423
1442
  removeAsset(file) {
1424
1443
  const localUri = file.localUri;
@@ -1577,10 +1596,10 @@ class FileManager extends core_1.Host {
1577
1596
  const errors = collectErrors.call(this);
1578
1597
  const files = Array.from(this.files).sort((a, b) => {
1579
1598
  const sep = path.sep;
1580
- if (a.indexOf(sep) !== -1 && b.indexOf(sep) === -1) {
1599
+ if (a.includes(sep) && !b.includes(sep)) {
1581
1600
  return -1;
1582
1601
  }
1583
- if (a.indexOf(sep) === -1 && b.indexOf(sep) !== -1) {
1602
+ if (!a.includes(sep) && b.includes(sep)) {
1584
1603
  return 1;
1585
1604
  }
1586
1605
  return a < b ? -1 : 1;
@@ -1726,12 +1745,15 @@ class FileManager extends core_1.Host {
1726
1745
  }
1727
1746
  return sourceUTF8;
1728
1747
  }
1729
- getBuffer(file) {
1748
+ getBuffer(file, minStreamSize) {
1730
1749
  if (file.buffer) {
1731
- return file.buffer;
1750
+ return (typeof minStreamSize === 'number' ? Promise.resolve(file.buffer) : file.buffer);
1732
1751
  }
1733
1752
  const uri = file.localUri;
1734
1753
  if (uri) {
1754
+ if (typeof minStreamSize === 'number') {
1755
+ return core_1.Host.streamFile(uri, { minStreamSize, cache: false, signal: this.signal });
1756
+ }
1735
1757
  try {
1736
1758
  return fs.readFileSync(uri);
1737
1759
  }
@@ -1739,7 +1761,8 @@ class FileManager extends core_1.Host {
1739
1761
  this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, 32 /* LOG_TYPE.FILE */);
1740
1762
  }
1741
1763
  }
1742
- return file.base64 ? Buffer.from(file.base64, 'base64') : null;
1764
+ const result = file.base64 ? Buffer.from(file.base64, 'base64') : null;
1765
+ return (typeof minStreamSize === 'number' ? Promise.resolve(result) : result);
1743
1766
  }
1744
1767
  getCacheDir(url, createDir = true) {
1745
1768
  if (typeof url === 'string') {
@@ -1936,7 +1959,7 @@ class FileManager extends core_1.Host {
1936
1959
  }
1937
1960
  return mimeType;
1938
1961
  }
1939
- compressFile(file, overwrite = true) {
1962
+ async compressFile(file, overwrite = true) {
1940
1963
  const { localUri, compress } = file;
1941
1964
  const instance = this.Compress;
1942
1965
  if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file.flags))) {
@@ -1990,7 +2013,7 @@ class FileManager extends core_1.Host {
1990
2013
  return Promise.all(tasks);
1991
2014
  }
1992
2015
  }
1993
- return Promise.resolve([]);
2016
+ return [];
1994
2017
  }
1995
2018
  async transformAsset(data, parent) {
1996
2019
  const file = data.file;
@@ -2041,29 +2064,27 @@ class FileManager extends core_1.Host {
2041
2064
  const handler = this.Image.get(mimeType) || this.Image.get('handler');
2042
2065
  if (handler) {
2043
2066
  const { instance, constructor } = handler;
2044
- if (instance.using || constructor.using) {
2045
- for (const command of file.commands) {
2046
- if (withinSizeRange(localUri, command, constructor.REGEXP_SIZERANGE) && !data.aborted) {
2047
- try {
2048
- if (instance.threadable) {
2049
- if (this.openThread(instance, data, this.getProcessTimeout(handler))) {
2050
- (instance.using ? instance.using(data, command) : constructor.using.call(this, instance, data, command))
2051
- .then(() => this.closeThread(instance, data))
2052
- .catch(err => {
2053
- this.closeThread(instance, data);
2054
- errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
2055
- });
2056
- }
2057
- }
2058
- else if (!this.aborted) {
2059
- this.addProcessTimeout(instance, file, this.getProcessTimeout(handler));
2060
- await (instance.using ? instance.using(data, command) : constructor.using.call(this, instance, data, command));
2067
+ for (const command of file.commands) {
2068
+ if (withinSizeRange(localUri, command, constructor.REGEXP_SIZERANGE) && (instance.using || constructor.using) && !data.aborted) {
2069
+ try {
2070
+ if (instance.threadable) {
2071
+ if (this.openThread(instance, data, this.getProcessTimeout(handler))) {
2072
+ (instance.using ? instance.using(data, command) : constructor.using.call(this, instance, data, command))
2073
+ .then(() => this.closeThread(instance, data))
2074
+ .catch(err => {
2075
+ this.closeThread(instance, data);
2076
+ errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
2077
+ });
2061
2078
  }
2062
2079
  }
2063
- catch (err) {
2064
- errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
2080
+ else if (!this.aborted) {
2081
+ this.addProcessTimeout(instance, file, this.getProcessTimeout(handler));
2082
+ await (instance.using ? instance.using(data, command) : constructor.using.call(this, instance, data, command));
2065
2083
  }
2066
2084
  }
2085
+ catch (err) {
2086
+ errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
2087
+ }
2067
2088
  }
2068
2089
  }
2069
2090
  }
@@ -2072,7 +2093,7 @@ class FileManager extends core_1.Host {
2072
2093
  else if (file.document) {
2073
2094
  for (const handler of this.Document) {
2074
2095
  const { instance, constructor } = handler;
2075
- if ((instance.using || constructor.using) && this.hasDocument(instance, file.document) && !data.aborted) {
2096
+ if (this.hasDocument(instance, file.document) && (instance.using || constructor.using) && !data.aborted) {
2076
2097
  try {
2077
2098
  if (instance.threadable) {
2078
2099
  if (this.openThread(instance, data, this.getProcessTimeout(handler))) {
@@ -2211,14 +2232,14 @@ class FileManager extends core_1.Host {
2211
2232
  getDownload(type = 0) {
2212
2233
  return this[kDownloadStats][type];
2213
2234
  }
2214
- fetchObject(uri, options) {
2235
+ async fetchObject(uri, options) {
2215
2236
  if (!(0, types_1.isObject)(options)) {
2216
2237
  options = { format: options };
2217
2238
  }
2218
2239
  options.format || (options.format = 'json');
2219
2240
  return this.fetchBuffer(uri, options).then(data => typeof data === 'object' ? data : null).catch(() => null);
2220
2241
  }
2221
- fetchBuffer(uri, options) {
2242
+ async fetchBuffer(uri, options) {
2222
2243
  if (options) {
2223
2244
  options.format = undefined;
2224
2245
  }
@@ -2236,14 +2257,14 @@ class FileManager extends core_1.Host {
2236
2257
  return buffer;
2237
2258
  });
2238
2259
  }
2239
- fetchFiles(uri, options) {
2260
+ async fetchFiles(uri, options) {
2240
2261
  if (!(0, types_1.isObject)(options)) {
2241
2262
  options = { pathname: options };
2242
2263
  }
2243
2264
  options.pathname || (options.pathname = this.baseDirectory);
2244
2265
  return this.Request.aria2c(uri, options);
2245
2266
  }
2246
- start(emptyDir) {
2267
+ async start(emptyDir) {
2247
2268
  const listener = (resolve) => {
2248
2269
  const callback = (files, errors, status) => {
2249
2270
  if (!this.restarting) {
@@ -2335,7 +2356,7 @@ class FileManager extends core_1.Host {
2335
2356
  const length = arguments.length;
2336
2357
  const args = new Array(length);
2337
2358
  for (let i = 0; i < length; ++i) {
2338
- args[i] = arguments[i];
2359
+ args[i] = arguments[i]; // eslint-disable-line prefer-rest-params
2339
2360
  }
2340
2361
  if (this.joinQueue({ args })) {
2341
2362
  this.finalizeState = 4 /* FINALIZE_STATE.QUEUED */;
@@ -2376,7 +2397,7 @@ class FileManager extends core_1.Host {
2376
2397
  file.invalid = true;
2377
2398
  const localUri = file.localUri;
2378
2399
  if (expired) {
2379
- data.abort();
2400
+ data.abort(new Error("Timeout was exceeded" /* ERR_MESSAGE.TIMEOUT */));
2380
2401
  if (localUri) {
2381
2402
  this.deleteFile(localUri, { id: file.id, emptyDir: true, all: true });
2382
2403
  }
@@ -2624,7 +2645,7 @@ class FileManager extends core_1.Host {
2624
2645
  if (!fs.existsSync(baseDir)) {
2625
2646
  fs.mkdirSync(baseDir);
2626
2647
  }
2627
- tempFile = path.join(baseDir, (0, types_1.generateUUID)());
2648
+ tempFile = path.join(baseDir, (0, types_1.incrementUUID)());
2628
2649
  options.pipeTo = tempFile;
2629
2650
  }
2630
2651
  catch {
@@ -2918,9 +2939,10 @@ class FileManager extends core_1.Host {
2918
2939
  if (!cached) {
2919
2940
  setBuffer(item);
2920
2941
  }
2921
- if (core_1.Host.isPath(localUri) && (!item.checksumOutput || checkHash(localUri, false, item.checksumOutput))) {
2942
+ const checksumOutput = item.checksumOutput;
2943
+ if (core_1.Host.isPath(localUri) && (!checksumOutput || checkHash(localUri, false, checksumOutput))) {
2922
2944
  item.flags |= 128 /* ASSET_FLAG.EXISTS */;
2923
- if (!etag || item.fetchType !== 1 /* FETCH_TYPE.HTTP */) {
2945
+ if (!etag || item.fetchType !== 1 /* FETCH_TYPE.HTTP */ || checksumOutput) {
2924
2946
  if (!(0, types_1.isEmpty)(bundleId) && bundleIndex === 0) {
2925
2947
  assets.filter(child => child.bundleId === bundleId && child.bundleIndex > 0).forEach(child => {
2926
2948
  setBuffer(child);
@@ -2941,8 +2963,10 @@ class FileManager extends core_1.Host {
2941
2963
  if (item.willChange && Buffer.isBuffer(buffer)) {
2942
2964
  item.buffer = buffer;
2943
2965
  }
2944
- this.performAsyncTask();
2945
- fileReceived(item, localUri, null, true);
2966
+ if (!(checksumOutput && (0, types_1.isEmpty)(bundleId) && checkHash(buffer, true, checksumOutput))) {
2967
+ this.performAsyncTask();
2968
+ fileReceived(item, localUri, null, true);
2969
+ }
2946
2970
  continue;
2947
2971
  }
2948
2972
  }
@@ -3316,7 +3340,7 @@ class FileManager extends core_1.Host {
3316
3340
  }
3317
3341
  async finalizeCompress(assets) {
3318
3342
  const compress = this.Compress;
3319
- if (!(compress && assets.length)) {
3343
+ if (!(assets.length && compress)) {
3320
3344
  return;
3321
3345
  }
3322
3346
  const tasks = [];
@@ -3382,9 +3406,11 @@ class FileManager extends core_1.Host {
3382
3406
  }
3383
3407
  }
3384
3408
  }
3385
- finalizeCloud() {
3409
+ async finalizeCloud() {
3386
3410
  const cloud = this.Cloud;
3387
- return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64 /* LOG_TYPE.CLOUD */)) : Promise.resolve();
3411
+ if (cloud) {
3412
+ return cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64 /* LOG_TYPE.CLOUD */));
3413
+ }
3388
3414
  }
3389
3415
  async finalizeCleanup() {
3390
3416
  if (this.emptyDir.size) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
4
4
  "description": "FileManager constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,15 +20,15 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "0.7.1",
24
- "@e-mc/compress": "0.7.1",
25
- "@e-mc/core": "0.7.1",
26
- "@e-mc/document": "0.7.1",
27
- "@e-mc/image": "0.7.1",
28
- "@e-mc/request": "0.7.1",
29
- "@e-mc/task": "0.7.1",
30
- "@e-mc/types": "0.7.1",
31
- "@e-mc/watch": "0.7.1",
23
+ "@e-mc/cloud": "0.8.1",
24
+ "@e-mc/compress": "0.8.1",
25
+ "@e-mc/core": "0.8.1",
26
+ "@e-mc/document": "0.8.1",
27
+ "@e-mc/image": "0.8.1",
28
+ "@e-mc/request": "0.8.1",
29
+ "@e-mc/task": "0.8.1",
30
+ "@e-mc/types": "0.8.1",
31
+ "@e-mc/watch": "0.8.1",
32
32
  "picomatch": "^3.0.1"
33
33
  }
34
34
  }