@e-mc/file-manager 0.8.0 → 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.
- package/LICENSE +10 -10
- package/index.d.ts +5 -5
- package/index.js +31 -9
- package/package.json +10 -10
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/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 {
|
|
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);
|
|
@@ -1730,12 +1745,15 @@ class FileManager extends core_1.Host {
|
|
|
1730
1745
|
}
|
|
1731
1746
|
return sourceUTF8;
|
|
1732
1747
|
}
|
|
1733
|
-
getBuffer(file) {
|
|
1748
|
+
getBuffer(file, minStreamSize) {
|
|
1734
1749
|
if (file.buffer) {
|
|
1735
|
-
return file.buffer;
|
|
1750
|
+
return (typeof minStreamSize === 'number' ? Promise.resolve(file.buffer) : file.buffer);
|
|
1736
1751
|
}
|
|
1737
1752
|
const uri = file.localUri;
|
|
1738
1753
|
if (uri) {
|
|
1754
|
+
if (typeof minStreamSize === 'number') {
|
|
1755
|
+
return core_1.Host.streamFile(uri, { minStreamSize, cache: false, signal: this.signal });
|
|
1756
|
+
}
|
|
1739
1757
|
try {
|
|
1740
1758
|
return fs.readFileSync(uri);
|
|
1741
1759
|
}
|
|
@@ -1743,7 +1761,8 @@ class FileManager extends core_1.Host {
|
|
|
1743
1761
|
this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, 32 /* LOG_TYPE.FILE */);
|
|
1744
1762
|
}
|
|
1745
1763
|
}
|
|
1746
|
-
|
|
1764
|
+
const result = file.base64 ? Buffer.from(file.base64, 'base64') : null;
|
|
1765
|
+
return (typeof minStreamSize === 'number' ? Promise.resolve(result) : result);
|
|
1747
1766
|
}
|
|
1748
1767
|
getCacheDir(url, createDir = true) {
|
|
1749
1768
|
if (typeof url === 'string') {
|
|
@@ -2920,9 +2939,10 @@ class FileManager extends core_1.Host {
|
|
|
2920
2939
|
if (!cached) {
|
|
2921
2940
|
setBuffer(item);
|
|
2922
2941
|
}
|
|
2923
|
-
|
|
2942
|
+
const checksumOutput = item.checksumOutput;
|
|
2943
|
+
if (core_1.Host.isPath(localUri) && (!checksumOutput || checkHash(localUri, false, checksumOutput))) {
|
|
2924
2944
|
item.flags |= 128 /* ASSET_FLAG.EXISTS */;
|
|
2925
|
-
if (!etag || item.fetchType !== 1 /* FETCH_TYPE.HTTP */) {
|
|
2945
|
+
if (!etag || item.fetchType !== 1 /* FETCH_TYPE.HTTP */ || checksumOutput) {
|
|
2926
2946
|
if (!(0, types_1.isEmpty)(bundleId) && bundleIndex === 0) {
|
|
2927
2947
|
assets.filter(child => child.bundleId === bundleId && child.bundleIndex > 0).forEach(child => {
|
|
2928
2948
|
setBuffer(child);
|
|
@@ -2943,8 +2963,10 @@ class FileManager extends core_1.Host {
|
|
|
2943
2963
|
if (item.willChange && Buffer.isBuffer(buffer)) {
|
|
2944
2964
|
item.buffer = buffer;
|
|
2945
2965
|
}
|
|
2946
|
-
|
|
2947
|
-
|
|
2966
|
+
if (!(checksumOutput && (0, types_1.isEmpty)(bundleId) && checkHash(buffer, true, checksumOutput))) {
|
|
2967
|
+
this.performAsyncTask();
|
|
2968
|
+
fileReceived(item, localUri, null, true);
|
|
2969
|
+
}
|
|
2948
2970
|
continue;
|
|
2949
2971
|
}
|
|
2950
2972
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.8.
|
|
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.8.
|
|
24
|
-
"@e-mc/compress": "0.8.
|
|
25
|
-
"@e-mc/core": "0.8.
|
|
26
|
-
"@e-mc/document": "0.8.
|
|
27
|
-
"@e-mc/image": "0.8.
|
|
28
|
-
"@e-mc/request": "0.8.
|
|
29
|
-
"@e-mc/task": "0.8.
|
|
30
|
-
"@e-mc/types": "0.8.
|
|
31
|
-
"@e-mc/watch": "0.8.
|
|
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
|
}
|