@e-mc/file-manager 0.8.0 → 0.8.2

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/LICENSE CHANGED
@@ -1,11 +1,11 @@
1
- Copyright 2023 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
-
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
1
+ Copyright 2023 An Pham
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
11
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ### @e-mc/file-manager
2
2
 
3
+ https://e-mc.readthedocs.io
4
+
3
5
  ### LICENSE
4
6
 
5
7
  BSD 3-Clause
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { FileManagerConstructor } from '../types/lib';
2
- import type { ExternalAsset } from '../types/lib/asset';
3
-
4
- declare const FileManager: FileManagerConstructor<ExternalAsset>;
5
-
1
+ import type { FileManagerConstructor } from '../types/lib';
2
+ import type { ExternalAsset } from '../types/lib/asset';
3
+
4
+ declare const FileManager: FileManagerConstructor<ExternalAsset>;
5
+
6
6
  export = FileManager;
package/index.js CHANGED
@@ -173,7 +173,7 @@ 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;
@@ -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);
@@ -921,19 +936,8 @@ class FileManager extends core_1.Host {
921
936
  if (item.tasks) {
922
937
  this.taskAssets.push(item);
923
938
  }
924
- if (encoding) {
925
- switch (encoding) {
926
- case 'utf-8':
927
- break;
928
- case 'utf-16':
929
- case 'utf-16be':
930
- case 'utf-16le':
931
- item.encoding = 'utf16le';
932
- break;
933
- default:
934
- item.encoding = (0, types_1.getEncoding)(encoding);
935
- break;
936
- }
939
+ if (encoding && encoding !== 'utf8' && encoding !== 'utf-8') {
940
+ item.encoding = encoding === 'utf-16be' ? 'utf16le' : (0, types_1.getEncoding)(encoding);
937
941
  }
938
942
  if ((0, types_1.usingFlag)(item.flags)) {
939
943
  (targeted || (targeted = [])).push(item);
@@ -1730,12 +1734,15 @@ class FileManager extends core_1.Host {
1730
1734
  }
1731
1735
  return sourceUTF8;
1732
1736
  }
1733
- getBuffer(file) {
1737
+ getBuffer(file, minStreamSize) {
1734
1738
  if (file.buffer) {
1735
- return file.buffer;
1739
+ return (typeof minStreamSize === 'number' ? Promise.resolve(file.buffer) : file.buffer);
1736
1740
  }
1737
1741
  const uri = file.localUri;
1738
1742
  if (uri) {
1743
+ if (typeof minStreamSize === 'number') {
1744
+ return core_1.Host.streamFile(uri, { minStreamSize, cache: false, signal: this.signal });
1745
+ }
1739
1746
  try {
1740
1747
  return fs.readFileSync(uri);
1741
1748
  }
@@ -1743,7 +1750,8 @@ class FileManager extends core_1.Host {
1743
1750
  this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, 32 /* LOG_TYPE.FILE */);
1744
1751
  }
1745
1752
  }
1746
- return file.base64 ? Buffer.from(file.base64, 'base64') : null;
1753
+ const result = file.base64 ? Buffer.from(file.base64, 'base64') : null;
1754
+ return (typeof minStreamSize === 'number' ? Promise.resolve(result) : result);
1747
1755
  }
1748
1756
  getCacheDir(url, createDir = true) {
1749
1757
  if (typeof url === 'string') {
@@ -2920,9 +2928,10 @@ class FileManager extends core_1.Host {
2920
2928
  if (!cached) {
2921
2929
  setBuffer(item);
2922
2930
  }
2923
- if (core_1.Host.isPath(localUri) && (!item.checksumOutput || checkHash(localUri, false, item.checksumOutput))) {
2931
+ const checksumOutput = item.checksumOutput;
2932
+ if (core_1.Host.isPath(localUri) && (!checksumOutput || checkHash(localUri, false, checksumOutput))) {
2924
2933
  item.flags |= 128 /* ASSET_FLAG.EXISTS */;
2925
- if (!etag || item.fetchType !== 1 /* FETCH_TYPE.HTTP */) {
2934
+ if (!etag || item.fetchType !== 1 /* FETCH_TYPE.HTTP */ || checksumOutput) {
2926
2935
  if (!(0, types_1.isEmpty)(bundleId) && bundleIndex === 0) {
2927
2936
  assets.filter(child => child.bundleId === bundleId && child.bundleIndex > 0).forEach(child => {
2928
2937
  setBuffer(child);
@@ -2943,8 +2952,10 @@ class FileManager extends core_1.Host {
2943
2952
  if (item.willChange && Buffer.isBuffer(buffer)) {
2944
2953
  item.buffer = buffer;
2945
2954
  }
2946
- this.performAsyncTask();
2947
- fileReceived(item, localUri, null, true);
2955
+ if (!(checksumOutput && (0, types_1.isEmpty)(bundleId) && checkHash(buffer, true, checksumOutput))) {
2956
+ this.performAsyncTask();
2957
+ fileReceived(item, localUri, null, true);
2958
+ }
2948
2959
  continue;
2949
2960
  }
2950
2961
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
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.8.0",
24
- "@e-mc/compress": "0.8.0",
25
- "@e-mc/core": "0.8.0",
26
- "@e-mc/document": "0.8.0",
27
- "@e-mc/image": "0.8.0",
28
- "@e-mc/request": "0.8.0",
29
- "@e-mc/task": "0.8.0",
30
- "@e-mc/types": "0.8.0",
31
- "@e-mc/watch": "0.8.0",
23
+ "@e-mc/cloud": "0.8.2",
24
+ "@e-mc/compress": "0.8.2",
25
+ "@e-mc/core": "0.8.2",
26
+ "@e-mc/document": "0.8.2",
27
+ "@e-mc/image": "0.8.2",
28
+ "@e-mc/request": "0.8.2",
29
+ "@e-mc/task": "0.8.2",
30
+ "@e-mc/types": "0.8.2",
31
+ "@e-mc/watch": "0.8.2",
32
32
  "picomatch": "^3.0.1"
33
33
  }
34
34
  }