@e-mc/module 0.8.3 → 0.8.5
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 +4 -8
- package/README.md +4 -4
- package/index.js +13 -20
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 Mile Square Park
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
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.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -588,11 +588,11 @@ function formatPercent(value, precision = 3) {
|
|
|
588
588
|
return (value * 100).toPrecision(precision) + '%';
|
|
589
589
|
}
|
|
590
590
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
591
|
-
const asFile = (value) => value instanceof URL
|
|
591
|
+
const asFile = (value) => (0, types_1.isString)(value) ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
592
592
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
593
593
|
const isFunction = (value) => typeof value === 'function';
|
|
594
594
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
595
|
-
const sanitizePath = (value) =>
|
|
595
|
+
const sanitizePath = (value) => value ? path.resolve(value) : '';
|
|
596
596
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
597
597
|
const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
|
|
598
598
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
@@ -623,7 +623,7 @@ class Module extends EventEmitter {
|
|
|
623
623
|
this[_f] = new AbortController();
|
|
624
624
|
this[_g] = null;
|
|
625
625
|
}
|
|
626
|
-
static get VERSION() { return "0.8.
|
|
626
|
+
static get VERSION() { return "0.8.5" /* INTERNAL.VERSION */; }
|
|
627
627
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
628
628
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
629
629
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -1184,10 +1184,7 @@ class Module extends EventEmitter {
|
|
|
1184
1184
|
const { algorithm, digest, chunkSize = 2097152000 /* HASH_OUTPUT.CHUNK_SIZE */ } = options;
|
|
1185
1185
|
const hash = crypto.createHash(algorithm || "sha256" /* HASH_OUTPUT.ALGORITHM */);
|
|
1186
1186
|
try {
|
|
1187
|
-
|
|
1188
|
-
if ((0, types_1.isString)(minStreamSize)) {
|
|
1189
|
-
minStreamSize = (0, types_1.formatSize)(minStreamSize);
|
|
1190
|
-
}
|
|
1187
|
+
const minStreamSize = (0, types_1.alignSize)(options.minStreamSize);
|
|
1191
1188
|
if (fs.statSync(value).size <= Math.min(minStreamSize > 0 ? minStreamSize : Infinity, 2097152000 /* HASH_OUTPUT.CHUNK_SIZE */)) {
|
|
1192
1189
|
return hash.update(fs.readFileSync(value)).digest(digest || "hex" /* HASH_OUTPUT.DIGEST */);
|
|
1193
1190
|
}
|
|
@@ -1437,17 +1434,18 @@ class Module extends EventEmitter {
|
|
|
1437
1434
|
return false;
|
|
1438
1435
|
}
|
|
1439
1436
|
static removeDir(value, empty = false, recursive = true) {
|
|
1440
|
-
|
|
1437
|
+
const outDir = sanitizePath(value = asFile(value));
|
|
1438
|
+
if (outDir) {
|
|
1441
1439
|
try {
|
|
1442
1440
|
if (typeof empty === 'number' && empty <= 0) {
|
|
1443
1441
|
empty = true;
|
|
1444
1442
|
}
|
|
1445
|
-
if (this.isDir(
|
|
1446
|
-
return tryRemoveDir(
|
|
1443
|
+
if (this.isDir(outDir)) {
|
|
1444
|
+
return tryRemoveDir(outDir, empty, !!recursive).length === 0;
|
|
1447
1445
|
}
|
|
1448
|
-
if (!fs.existsSync(
|
|
1446
|
+
if (!fs.existsSync(outDir)) {
|
|
1449
1447
|
if (empty && typeof empty !== 'number') {
|
|
1450
|
-
this.createDir(
|
|
1448
|
+
this.createDir(outDir);
|
|
1451
1449
|
}
|
|
1452
1450
|
return true;
|
|
1453
1451
|
}
|
|
@@ -1623,12 +1621,9 @@ class Module extends EventEmitter {
|
|
|
1623
1621
|
({ minStreamSize = 0, encoding, signal, cache } = options);
|
|
1624
1622
|
}
|
|
1625
1623
|
return new Promise(async (resolve) => {
|
|
1626
|
-
if ((0, types_1.isString)(minStreamSize)) {
|
|
1627
|
-
minStreamSize = (0, types_1.formatSize)(minStreamSize);
|
|
1628
|
-
}
|
|
1629
1624
|
const fileSize = fs.statSync(src).size;
|
|
1630
1625
|
let data;
|
|
1631
|
-
if (fileSize >= minStreamSize || fileSize >= 2097152000 /* HASH_OUTPUT.CHUNK_SIZE */) {
|
|
1626
|
+
if (fileSize >= (0, types_1.alignSize)(minStreamSize) || fileSize >= 2097152000 /* HASH_OUTPUT.CHUNK_SIZE */) {
|
|
1632
1627
|
const readable = fs.createReadStream(src, { signal });
|
|
1633
1628
|
const chunks = [];
|
|
1634
1629
|
for await (const chunk of readable) {
|
|
@@ -2567,10 +2562,8 @@ class Module extends EventEmitter {
|
|
|
2567
2562
|
result || (result = (encoding ? getCacheItem(CACHE_READTEXT, outSrc) : getCacheItem(CACHE_READBUFFER, outSrc)));
|
|
2568
2563
|
}
|
|
2569
2564
|
try {
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
}
|
|
2573
|
-
if (typeof minStreamSize === 'number' || promises && fs.statSync(outSrc).size >= 2097152000 /* HASH_OUTPUT.CHUNK_SIZE */) {
|
|
2565
|
+
minStreamSize = (0, types_1.alignSize)(minStreamSize);
|
|
2566
|
+
if (!isNaN(minStreamSize) || promises && fs.statSync(outSrc).size >= 2097152000 /* HASH_OUTPUT.CHUNK_SIZE */) {
|
|
2574
2567
|
if (result) {
|
|
2575
2568
|
return Promise.resolve(result);
|
|
2576
2569
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/types": "0.8.5",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|