@e-mc/file-manager 0.14.2 → 0.14.3

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 (3) hide show
  1. package/README.md +11 -10
  2. package/index.js +20 -5
  3. package/package.json +10 -10
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.14.2/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.14.3/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { ChecksumValue, DataSource, IncrementalMatch, TaskAction } from "./squared";
@@ -51,6 +51,7 @@ interface IFileManager extends IHost, Set<string> {
51
51
  readonly emptyDir: Set<string>;
52
52
  readonly cacheToDisk: IHttpDiskCache<ExternalAsset>;
53
53
  readonly cacheToMemory: IHttpMemoryCache<ExternalAsset>;
54
+ [Symbol.asyncIterator](): IteratorObject<[string, Buffer, BufferEncoding?], BuiltinIteratorReturn>;
54
55
  install(name: "document", handler: string, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
55
56
  install(name: "document", target: DocumentConstructor, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
56
57
  install(name: "task", handler: string, module?: TaskModule, ...args: unknown[]): ITask | undefined;
@@ -297,15 +298,15 @@ NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-
297
298
 
298
299
  ## References
299
300
 
300
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/squared.d.ts
301
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/asset.d.ts
302
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/core.d.ts
303
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/filemanager.d.ts
304
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/logger.d.ts
305
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/module.d.ts
306
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/node.d.ts
307
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/request.d.ts
308
- - https://www.unpkg.com/@e-mc/types@0.14.2/lib/settings.d.ts
301
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/squared.d.ts
302
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/asset.d.ts
303
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/core.d.ts
304
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/filemanager.d.ts
305
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/logger.d.ts
306
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/module.d.ts
307
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/node.d.ts
308
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/request.d.ts
309
+ - https://www.unpkg.com/@e-mc/types@0.14.3/lib/settings.d.ts
309
310
 
310
311
  * https://www.npmjs.com/package/@types/node
311
312
 
package/index.js CHANGED
@@ -294,7 +294,7 @@ function processCacheHeaders(headers, noCache, noStore) {
294
294
  const maxAge = cacheControl.find(value => value.startsWith('max-age='));
295
295
  if (maxAge && (!noCache || cacheControl.includes('public') || cacheControl.includes('must-revalidate'))) {
296
296
  const age = parseHeader(headers, 'age');
297
- let result = parseInt(maxAge.split('=').pop()) * 1000;
297
+ let result = parseInt(maxAge.split('=').at(-1)) * 1000;
298
298
  if (age) {
299
299
  result -= age;
300
300
  if (result < 0 && noCache) {
@@ -1731,6 +1731,20 @@ class FileManager extends Host {
1731
1731
  yield file;
1732
1732
  }
1733
1733
  }
1734
+ *[Symbol.asyncIterator]() {
1735
+ for (const file of this.files) {
1736
+ const asset = this._assets.find(item => item.localUri === file);
1737
+ try {
1738
+ const buffer = asset && this.getBuffer(asset) || fs.readFileSync(file);
1739
+ if (buffer) {
1740
+ yield [file, buffer, asset?.encoding];
1741
+ }
1742
+ }
1743
+ catch (err) {
1744
+ this.addLog(3, err, { source: file });
1745
+ }
1746
+ }
1747
+ }
1734
1748
  add(value, parent, type = FILE_TYPE.TRANSFORM) {
1735
1749
  const file = this.removeCwd(value);
1736
1750
  if (file) {
@@ -2471,7 +2485,7 @@ class FileManager extends Host {
2471
2485
  }
2472
2486
  let filename = file.filename;
2473
2487
  if (!filename && !file.document && !isDownloadAll(type)) {
2474
- filename = url.pathname.split('/').pop();
2488
+ filename = url.pathname.split('/').at(-1);
2475
2489
  if (filename.includes('.')) {
2476
2490
  const mimeType = file.mimeType || Host.lookupMime(filename);
2477
2491
  if (mimeType) {
@@ -2552,7 +2566,7 @@ class FileManager extends Host {
2552
2566
  if (file.buffer) {
2553
2567
  return (typeof minStreamSize === 'number' ? Promise.resolve(file.buffer) : file.buffer);
2554
2568
  }
2555
- let { base64, localUri } = file;
2569
+ let { base64, sourceUTF8, localUri } = file;
2556
2570
  if (localUri) {
2557
2571
  if (typeof minStreamSize === 'number') {
2558
2572
  return Host.streamFile(localUri, { minStreamSize, cache: false, signal: this.signal });
@@ -2561,13 +2575,14 @@ class FileManager extends Host {
2561
2575
  return fs.readFileSync(localUri);
2562
2576
  }
2563
2577
  catch (err) {
2564
- if (!(base64 && isErrorCode(err, 'ENOENT', 'EACCES'))) {
2578
+ if (!(isErrorCode(err, 'ENOENT', 'EACCES') && (sourceUTF8 || base64))) {
2565
2579
  this.writeFail(["Unable to read file", path.basename(localUri)], err, 32);
2580
+ sourceUTF8 = undefined;
2566
2581
  base64 = undefined;
2567
2582
  }
2568
2583
  }
2569
2584
  }
2570
- const result = base64 ? Buffer.from(base64, 'base64') : null;
2585
+ const result = sourceUTF8 ? Buffer.from(sourceUTF8, file.encoding) : base64 ? Buffer.from(base64, 'base64') : null;
2571
2586
  return (typeof minStreamSize === 'number' ? Promise.resolve(result) : result);
2572
2587
  }
2573
2588
  getCacheDir(url, createDir = true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "description": "FileManager constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -16,15 +16,15 @@
16
16
  "license": "BSD-3-Clause",
17
17
  "homepage": "https://github.com/anpham6/e-mc#readme",
18
18
  "dependencies": {
19
- "@e-mc/cloud": "0.14.2",
20
- "@e-mc/compress": "0.14.2",
21
- "@e-mc/core": "0.14.2",
22
- "@e-mc/document": "0.14.2",
23
- "@e-mc/image": "0.14.2",
24
- "@e-mc/request": "0.14.2",
25
- "@e-mc/task": "0.14.2",
26
- "@e-mc/types": "0.14.2",
27
- "@e-mc/watch": "0.14.2",
19
+ "@e-mc/cloud": "0.14.3",
20
+ "@e-mc/compress": "0.14.3",
21
+ "@e-mc/core": "0.14.3",
22
+ "@e-mc/document": "0.14.3",
23
+ "@e-mc/image": "0.14.3",
24
+ "@e-mc/request": "0.14.3",
25
+ "@e-mc/task": "0.14.3",
26
+ "@e-mc/types": "0.14.3",
27
+ "@e-mc/watch": "0.14.3",
28
28
  "chalk": "4.1.2",
29
29
  "diff": "^9.0.0",
30
30
  "picomatch": "^4.0.4"