@e-mc/file-manager 0.9.9 → 0.9.11

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 (5) hide show
  1. package/LICENSE +10 -10
  2. package/README.md +302 -302
  3. package/index.d.ts +5 -5
  4. package/index.js +30 -31
  5. package/package.json +35 -35
package/LICENSE CHANGED
@@ -1,11 +1,11 @@
1
- Copyright 2024 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 2024 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,303 +1,303 @@
1
- # @e-mc/file-manager
2
-
3
- * NodeJS 16
4
- * ES2020
5
-
6
- ## General Usage
7
-
8
- * [Read the Docs](https://e-mc.readthedocs.io)
9
-
10
- ## Interface
11
-
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.9/lib/index.d.ts)
13
-
14
- ```typescript
15
- import type { DataSource, IncrementalMatch, TaskAction } from "./squared";
16
-
17
- import type { DocumentConstructor, HostConstructor, ICloud, ICompress, IDocument, IHost, IImage, IModule, IRequest, ITask, ImageConstructor, TaskConstructor, WatchInstance } from "./index";
18
- import type { ExternalAsset, FileCommand, FileData, IFileThread, OutputFinalize } from "./asset";
19
- import type { IPermission, PermissionReadWrite } from "./core";
20
- import type { AssetContentOptions, ChecksumOptions, DeleteFileAddendum, FileOutput, FinalizeResult, FindAssetOptions, IHttpDiskCache, IHttpMemoryCache, ImageMimeMap, InstallData, PostFinalizeCallback, ReplaceOptions } from "./filemanager";
21
- import type { ExecCommand } from "./logger";
22
- import type { CopyFileOptions, CreateDirOptions, DeleteFileOptions, MoveFileOptions, ReadFileOptions, RemoveDirOptions, WriteFileOptions } from "./module";
23
- import type { RequestData, Settings } from "./node";
24
- import type { Aria2Options, BufferFormat, OpenOptions } from "./request";
25
- import type { CloudModule, CompressModule, DbModule, DocumentModule, HttpConnectSettings, HttpMemorySettings, ImageModule, RequestModule, TaskModule, WatchModule } from "./settings";
26
-
27
- import type { SpawnOptions } from "child_process";
28
- import type { NoParamCallback } from "fs";
29
-
30
- interface IFileManager extends IHost, Set<string> {
31
- processTimeout: number;
32
- cacheToDisk: IHttpDiskCache<ExternalAsset>;
33
- cacheToMemory: IHttpMemoryCache<ExternalAsset>;
34
- Request: IRequest<RequestModule>;
35
- Document: InstallData<IDocument<IFileManager, ExternalAsset>, DocumentConstructor<IFileManager, ExternalAsset>>[];
36
- Task: InstallData<ITask, TaskConstructor>[];
37
- Image: Map<ImageMimeMap> | null;
38
- Cloud: ICloud | null;
39
- Watch: WatchInstance<ExternalAsset> | null;
40
- Compress: ICompress<CompressModule> | null;
41
- readonly documentAssets: ExternalAsset[];
42
- readonly taskAssets: (ExternalAsset & Required<TaskAction>)[];
43
- readonly dataSourceItems: DataSource[];
44
- readonly files: Set<string>;
45
- readonly filesQueued: Set<string>;
46
- readonly filesToRemove: Set<string>;
47
- readonly filesToCompare: Map<ExternalAsset, string[]>;
48
- readonly contentToAppend: Map<string, string[]>;
49
- readonly contentToReplace: Map<string, string[]>;
50
- readonly processing: IFileThread[];
51
- readonly fetchedAssets: ExternalAsset[];
52
- readonly copiedAssets: ExternalAsset[];
53
- readonly emptyDir: Set<string>;
54
- install(name: "document", handler: string, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
55
- install(name: "document", target: DocumentConstructor, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
56
- install(name: "task", handler: string, module?: TaskModule, ...args: unknown[]): ITask | undefined;
57
- install(name: "task", target: TaskConstructor, module?: TaskModule, ...args: unknown[]): ITask | undefined;
58
- install(name: "cloud", handler: string, module?: CloudModule, ...args: unknown[]): ICloud | undefined;
59
- install(name: "cloud", module?: CloudModule, ...args: unknown[]): ICloud | undefined;
60
- install(name: "image", handler: string, module?: ImageModule, ...args: unknown[]): IImage | undefined;
61
- install(name: "image", target: ImageConstructor, module?: ImageModule, ...args: unknown[]): IImage | undefined;
62
- install(name: "image", targets: Map<string, ImageConstructor>, module?: ImageModule): void;
63
- install(name: "watch", module: WatchModule): WatchInstance<ExternalAsset> | undefined;
64
- install(name: "watch", interval?: number | string, port?: number | string, securePort?: number | string, extensions?: unknown[]): WatchInstance<ExternalAsset> | undefined;
65
- install(name: "compress", module?: CompressModule): ICompress<CompressModule> | undefined;
66
- install(name: string, ...args: unknown[]): IModule | undefined;
67
- using(...items: ExternalAsset[] | [boolean, ...ExternalAsset[]]): this;
68
- contains(item: ExternalAsset, condition?: (target: ExternalAsset) => boolean): boolean;
69
- removeCwd(value: unknown): string;
70
- findAsset(value: string | URL, instance?: IModule | FindAssetOptions<ExternalAsset>): ExternalAsset | undefined;
71
- removeAsset(file: ExternalAsset): boolean;
72
- replace(file: ExternalAsset, replaceWith: string, mimeType: Undef<string>): boolean;
73
- replace(file: ExternalAsset, replaceWith: string, options?: ReplaceOptions): boolean;
74
- rename(file: ExternalAsset, value: string): boolean;
75
- performAsyncTask(): void;
76
- removeAsyncTask(): void;
77
- completeAsyncTask(err?: unknown, uri?: string, parent?: ExternalAsset, type?: number): void;
78
- performFinalize(override?: boolean): void;
79
- hasDocument(instance: IModule, document: string | string[] | undefined): boolean;
80
- getDocumentAssets(instance: IModule, condition?: (target: ExternalAsset) => boolean): ExternalAsset[];
81
- getDataSourceItems(instance: IModule, condition?: (target: DataSource) => boolean): DataSource[];
82
- setLocalUri(file: ExternalAsset, replace?: boolean): FileOutput;
83
- getLocalUri(data: FileData<ExternalAsset>): string;
84
- getMimeType(data: FileData<ExternalAsset>): string;
85
- openThread(instance: IModule, data: IFileThread, timeout?: number): boolean;
86
- closeThread(instance: IModule | null, data: IFileThread, callback?: (...args: unknown[]) => void): boolean;
87
- addProcessTimeout(instance: IModule, file: ExternalAsset, timeout: number): void;
88
- removeProcessTimeout(instance: IModule, file: ExternalAsset): void;
89
- getProcessTimeout(handler: InstallData): number;
90
- clearProcessTimeout(): void;
91
- scheduleTask(url: string | URL, data: unknown, priority: number): Promise<unknown>;
92
- scheduleTask(url: string | URL, data: unknown, thenCallback?: (...args: unknown[]) => unknown, catchCallback?: (...args: unknown[]) => unknown, priority?: number): Promise<unknown>;
93
- setTaskLimit(value: number): void;
94
- addDownload(value: number | Buffer | string, encoding: BufferEncoding): number;
95
- addDownload(value: number | Buffer | string, type?: number | BufferEncoding, encoding?: BufferEncoding): number;
96
- getDownload(type?: number): [number, number];
97
- transformAsset(data: IFileThread, parent?: ExternalAsset, override?: boolean): Promise<boolean>;
98
- addCopy(data: FileCommand<ExternalAsset>, saveAs?: string, replace?: boolean): string | undefined;
99
- findMime(file: ExternalAsset, rename?: boolean): Promise<string>;
100
- getUTF8String(file: ExternalAsset, uri?: string): string;
101
- getBuffer(file: ExternalAsset, minStreamSize?: number): Promise<Buffer | null> | Buffer | null;
102
- getCacheDir(url: string | URL, createDir?: boolean): string;
103
- setAssetContent(file: ExternalAsset, content: string, options?: AssetContentOptions): string;
104
- getAssetContent(file: ExternalAsset, content?: string): string | undefined;
105
- writeBuffer(file: ExternalAsset, options?: WriteFileOptions): Buffer | null;
106
- writeImage(document: string | string[], output: OutputFinalize<ExternalAsset>): boolean;
107
- compressFile(file: ExternalAsset, overwrite?: boolean): Promise<unknown>;
108
- fetchObject(uri: string | URL, format: BufferFormat): Promise<object | null>;
109
- fetchObject(uri: string | URL, options?: OpenOptions): Promise<object | null>;
110
- fetchBuffer(uri: string | URL, options?: OpenOptions): Promise<Buffer | string | null>;
111
- fetchFiles(uri: string | URL, pathname: string): Promise<string[]>;
112
- fetchFiles(uri: string | URL, options?: Aria2Options): Promise<string[]>;
113
- updateProgress(name: "request", id: number | string, receivedBytes: number, totalBytes: number, dataTime?: HighResolutionTime): void;
114
- start(emptyDir?: boolean): Promise<FinalizeResult>;
115
- processAssets(emptyDir?: boolean, using?: ExternalAsset[]): void;
116
- deleteFile(src: string, promises: boolean): Promise<void>;
117
- deleteFile(src: string, options: DeleteFileOptions & DeleteFileAddendum, promises: boolean): Promise<void>;
118
- deleteFile(src: string, callback?: NoParamCallback): unknown;
119
- deleteFile(src: string, options: DeleteFileOptions & DeleteFileAddendum, callback?: NoParamCallback): unknown;
120
- restart(recursive?: boolean | "abort", emptyDir?: boolean): void;
121
- restart(recursive?: boolean | "abort", exclusions?: string[], emptyDir?: boolean): void;
122
- finalizeCompress(assets: ExternalAsset[]): Promise<unknown>;
123
- finalizeDocument(): Promise<unknown>;
124
- finalizeTask(assets: (ExternalAsset & Required<TaskAction>)[]): Promise<unknown>;
125
- finalizeCloud(): Promise<unknown>;
126
- finalizeCleanup(): Promise<unknown>;
127
- finalize(): Promise<void>;
128
- close(): void;
129
- reset(): boolean;
130
- get baseDirectory(): string;
131
- get config(): RequestData;
132
- get assets(): ExternalAsset[];
133
- get incremental(): IncrementalMatch;
134
- set restarting(value);
135
- get restarting(): boolean;
136
- get delayed(): number;
137
- set cleared(value);
138
- get cleared(): boolean;
139
- set finalizeState(value);
140
- get finalizeState(): number;
141
-
142
- /* Set */
143
- add(value: string, parent?: ExternalAsset, type?: number): this;
144
- delete(value: string, emptyDir?: boolean): boolean;
145
- has(value: unknown): value is string;
146
-
147
- /* EventEmitter */
148
- on(event: "end", listener: PostFinalizeCallback): this;
149
- on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
150
- on(event: "error", listener: (err: Error) => void): this;
151
- on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
152
- on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
153
- on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
154
- on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
155
- on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
156
- on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
157
- on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
158
- once(event: "end", listener: PostFinalizeCallback): this;
159
- once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
160
- once(event: "error", listener: (err: Error) => void): this;
161
- once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
162
- once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
163
- once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
164
- once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
165
- once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
166
- once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
167
- once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
168
- emit(event: "end", result: FinalizeResult): boolean;
169
- emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
170
- emit(event: "error", err: Error): boolean;
171
- emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
172
- emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
173
- emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
174
- emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
175
- emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
176
- emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
177
- emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
178
- }
179
-
180
- interface FileManagerConstructor extends HostConstructor {
181
- purgeMemory(percent?: number, limit?: number | boolean, parent?: number | boolean): Promise<number>;
182
- loadSettings(settings: Settings, password?: string): boolean;
183
- loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
184
- sanitizeAssets(assets: ExternalAsset[], exclusions?: string[]): ExternalAsset[];
185
- writeChecksum(root: string, options: ChecksumOptions): Promise<string[]>;
186
- writeChecksum(root: string, to?: string, options?: ChecksumOptions): Promise<string[] | null>;
187
- verifyChecksum(root: string, options: ChecksumOptions): Promise<[string[], string[], number] | null>;
188
- verifyChecksum(root: string, from?: string, options?: ChecksumOptions): Promise<[string[], string[], number] | null>;
189
- createFileThread(host: IFileManager, file: ExternalAsset): IFileThread;
190
- setTimeout(options: Record<string, number | string>): void;
191
- defineHttpCache(options: HttpMemorySettings, disk?: boolean): void;
192
- defineHttpConnect(options: HttpConnectSettings): void;
193
- readonly prototype: IFileManager;
194
- new(baseDirectory: string, config: RequestData, postFinalize?: PostFinalizeCallback): IFileManager;
195
- new(baseDirectory: string, config: RequestData, permission?: IPermission | null, postFinalize?: PostFinalizeCallback): IFileManager;
196
- }
197
- ```
198
-
199
- ## Settings
200
-
201
- ```typescript
202
- interface ProcessModule {
203
- thread?: {
204
- sub_limit?: number;
205
- };
206
- }
207
-
208
- interface RequestModule {
209
- timeout?: number | string;
210
- disk?: {
211
- enabled?: boolean;
212
- expires?: number | string;
213
- limit?: number | string;
214
- include?: string[];
215
- exclude?: string[];
216
- };
217
- buffer?: {
218
- enabled?: boolean;
219
- expires?: number | string;
220
- limit?: number | string;
221
- include?: string[];
222
- exclude?: string[];
223
- limit_all?: number | string;
224
- purge_amount?: number | string;
225
- to_disk?: number | string | [number | string, (number | string)?];
226
- };
227
- connect?: {
228
- timeout?: number | string;
229
- retry_wait?: number | string;
230
- retry_after?: number | string;
231
- retry_limit?: number;
232
- redirect_limit?: number;
233
- };
234
- }
235
-
236
- interface ErrorModule {
237
- recursion_limit?: number;
238
- }
239
-
240
- interface LoggerModule {
241
- session_id?: boolean | number;
242
- }
243
- ```
244
-
245
- ### Example usage
246
-
247
- ```javascript
248
- const FileManager = require("@e-mc/file-manager");
249
-
250
- FileManager.loadSettings({ // Global
251
- process: {
252
- thread: { sub_limit: 16 }
253
- },
254
- request: {
255
- timeout: "15s",
256
- disk: {
257
- enabled: true,
258
- limit: "1gb", // Content-Length
259
- expires: "1d",
260
- exclude: ["https://github.com", "zip"]
261
- },
262
- buffer: {
263
- enabled: true,
264
- limit: "64mb",
265
- limit_all: "512mb",
266
- expires: "1h",
267
- purge_amount: 0.25 // When limit_all exceeded
268
- }
269
- },
270
- permission: {
271
- disk_read: ["**/*"],
272
- disk_write: ["/tmp/**"]
273
- }
274
- });
275
-
276
- const assets = [
277
- { pathname: "output", filename: "image1.png", uri: "http://hostname/path/document1.png" },
278
- { pathname: "output", filename: "image2.png", uri: "http://hostname/path/document2.png" }
279
- ];
280
-
281
- const instance = new FileManager("/path/workspace", { assets, incremental: "etag" }, { disk_write: ["/path/workspace/output/**"] });
282
- await instance.start();
283
- ```
284
-
285
- NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-mc/core) and [Module](https://www.npmjs.com/package/@e-mc/module). Their ``loadSettings`` will be called as well which uses a combined [Settings](https://e-mc.readthedocs.io/en/latest/references.html#references-e-mc-types-lib-node) object.
286
-
287
- ## References
288
-
289
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/squared.d.ts
290
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/asset.d.ts
291
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/core.d.ts
292
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/filemanager.d.ts
293
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/logger.d.ts
294
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/module.d.ts
295
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/node.d.ts
296
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/request.d.ts
297
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/settings.d.ts
298
-
299
- * https://www.npmjs.com/package/@types/node
300
-
301
- ## LICENSE
302
-
1
+ # @e-mc/file-manager
2
+
3
+ * NodeJS 16
4
+ * ES2020
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.11/lib/index.d.ts)
13
+
14
+ ```typescript
15
+ import type { DataSource, IncrementalMatch, TaskAction } from "./squared";
16
+
17
+ import type { DocumentConstructor, HostConstructor, ICloud, ICompress, IDocument, IHost, IImage, IModule, IRequest, ITask, ImageConstructor, TaskConstructor, WatchInstance } from "./index";
18
+ import type { ExternalAsset, FileCommand, FileData, IFileThread, OutputFinalize } from "./asset";
19
+ import type { IPermission, PermissionReadWrite } from "./core";
20
+ import type { AssetContentOptions, ChecksumOptions, DeleteFileAddendum, FileOutput, FinalizeResult, FindAssetOptions, IHttpDiskCache, IHttpMemoryCache, ImageMimeMap, InstallData, PostFinalizeCallback, ReplaceOptions } from "./filemanager";
21
+ import type { ExecCommand } from "./logger";
22
+ import type { CopyFileOptions, CreateDirOptions, DeleteFileOptions, MoveFileOptions, ReadFileOptions, RemoveDirOptions, WriteFileOptions } from "./module";
23
+ import type { RequestData, Settings } from "./node";
24
+ import type { Aria2Options, BufferFormat, OpenOptions } from "./request";
25
+ import type { CloudModule, CompressModule, DbModule, DocumentModule, HttpConnectSettings, HttpMemorySettings, ImageModule, RequestModule, TaskModule, WatchModule } from "./settings";
26
+
27
+ import type { SpawnOptions } from "child_process";
28
+ import type { NoParamCallback } from "fs";
29
+
30
+ interface IFileManager extends IHost, Set<string> {
31
+ processTimeout: number;
32
+ cacheToDisk: IHttpDiskCache<ExternalAsset>;
33
+ cacheToMemory: IHttpMemoryCache<ExternalAsset>;
34
+ Request: IRequest<RequestModule>;
35
+ Document: InstallData<IDocument<IFileManager, ExternalAsset>, DocumentConstructor<IFileManager, ExternalAsset>>[];
36
+ Task: InstallData<ITask, TaskConstructor>[];
37
+ Image: Map<ImageMimeMap> | null;
38
+ Cloud: ICloud | null;
39
+ Watch: WatchInstance<ExternalAsset> | null;
40
+ Compress: ICompress<CompressModule> | null;
41
+ readonly documentAssets: ExternalAsset[];
42
+ readonly taskAssets: (ExternalAsset & Required<TaskAction>)[];
43
+ readonly dataSourceItems: DataSource[];
44
+ readonly files: Set<string>;
45
+ readonly filesQueued: Set<string>;
46
+ readonly filesToRemove: Set<string>;
47
+ readonly filesToCompare: Map<ExternalAsset, string[]>;
48
+ readonly contentToAppend: Map<string, string[]>;
49
+ readonly contentToReplace: Map<string, string[]>;
50
+ readonly processing: IFileThread[];
51
+ readonly fetchedAssets: ExternalAsset[];
52
+ readonly copiedAssets: ExternalAsset[];
53
+ readonly emptyDir: Set<string>;
54
+ install(name: "document", handler: string, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
55
+ install(name: "document", target: DocumentConstructor, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
56
+ install(name: "task", handler: string, module?: TaskModule, ...args: unknown[]): ITask | undefined;
57
+ install(name: "task", target: TaskConstructor, module?: TaskModule, ...args: unknown[]): ITask | undefined;
58
+ install(name: "cloud", handler: string, module?: CloudModule, ...args: unknown[]): ICloud | undefined;
59
+ install(name: "cloud", module?: CloudModule, ...args: unknown[]): ICloud | undefined;
60
+ install(name: "image", handler: string, module?: ImageModule, ...args: unknown[]): IImage | undefined;
61
+ install(name: "image", target: ImageConstructor, module?: ImageModule, ...args: unknown[]): IImage | undefined;
62
+ install(name: "image", targets: Map<string, ImageConstructor>, module?: ImageModule): void;
63
+ install(name: "watch", module: WatchModule): WatchInstance<ExternalAsset> | undefined;
64
+ install(name: "watch", interval?: number | string, port?: number | string, securePort?: number | string, extensions?: unknown[]): WatchInstance<ExternalAsset> | undefined;
65
+ install(name: "compress", module?: CompressModule): ICompress<CompressModule> | undefined;
66
+ install(name: string, ...args: unknown[]): IModule | undefined;
67
+ using(...items: ExternalAsset[] | [boolean, ...ExternalAsset[]]): this;
68
+ contains(item: ExternalAsset, condition?: (target: ExternalAsset) => boolean): boolean;
69
+ removeCwd(value: unknown): string;
70
+ findAsset(value: string | URL, instance?: IModule | FindAssetOptions<ExternalAsset>): ExternalAsset | undefined;
71
+ removeAsset(file: ExternalAsset): boolean;
72
+ replace(file: ExternalAsset, replaceWith: string, mimeType: Undef<string>): boolean;
73
+ replace(file: ExternalAsset, replaceWith: string, options?: ReplaceOptions): boolean;
74
+ rename(file: ExternalAsset, value: string): boolean;
75
+ performAsyncTask(): void;
76
+ removeAsyncTask(): void;
77
+ completeAsyncTask(err?: unknown, uri?: string, parent?: ExternalAsset, type?: number): void;
78
+ performFinalize(override?: boolean): void;
79
+ hasDocument(instance: IModule, document: string | string[] | undefined): boolean;
80
+ getDocumentAssets(instance: IModule, condition?: (target: ExternalAsset) => boolean): ExternalAsset[];
81
+ getDataSourceItems(instance: IModule, condition?: (target: DataSource) => boolean): DataSource[];
82
+ setLocalUri(file: ExternalAsset, replace?: boolean): FileOutput;
83
+ getLocalUri(data: FileData<ExternalAsset>): string;
84
+ getMimeType(data: FileData<ExternalAsset>): string;
85
+ openThread(instance: IModule, data: IFileThread, timeout?: number): boolean;
86
+ closeThread(instance: IModule | null, data: IFileThread, callback?: (...args: unknown[]) => void): boolean;
87
+ addProcessTimeout(instance: IModule, file: ExternalAsset, timeout: number): void;
88
+ removeProcessTimeout(instance: IModule, file: ExternalAsset): void;
89
+ getProcessTimeout(handler: InstallData): number;
90
+ clearProcessTimeout(): void;
91
+ scheduleTask(url: string | URL, data: unknown, priority: number): Promise<unknown>;
92
+ scheduleTask(url: string | URL, data: unknown, thenCallback?: (...args: unknown[]) => unknown, catchCallback?: (...args: unknown[]) => unknown, priority?: number): Promise<unknown>;
93
+ setTaskLimit(value: number): void;
94
+ addDownload(value: number | Buffer | string, encoding: BufferEncoding): number;
95
+ addDownload(value: number | Buffer | string, type?: number | BufferEncoding, encoding?: BufferEncoding): number;
96
+ getDownload(type?: number): [number, number];
97
+ transformAsset(data: IFileThread, parent?: ExternalAsset, override?: boolean): Promise<boolean>;
98
+ addCopy(data: FileCommand<ExternalAsset>, saveAs?: string, replace?: boolean): string | undefined;
99
+ findMime(file: ExternalAsset, rename?: boolean): Promise<string>;
100
+ getUTF8String(file: ExternalAsset, uri?: string): string;
101
+ getBuffer(file: ExternalAsset, minStreamSize?: number): Promise<Buffer | null> | Buffer | null;
102
+ getCacheDir(url: string | URL, createDir?: boolean): string;
103
+ setAssetContent(file: ExternalAsset, content: string, options?: AssetContentOptions): string;
104
+ getAssetContent(file: ExternalAsset, content?: string): string | undefined;
105
+ writeBuffer(file: ExternalAsset, options?: WriteFileOptions): Buffer | null;
106
+ writeImage(document: string | string[], output: OutputFinalize<ExternalAsset>): boolean;
107
+ compressFile(file: ExternalAsset, overwrite?: boolean): Promise<unknown>;
108
+ fetchObject(uri: string | URL, format: BufferFormat): Promise<object | null>;
109
+ fetchObject(uri: string | URL, options?: OpenOptions): Promise<object | null>;
110
+ fetchBuffer(uri: string | URL, options?: OpenOptions): Promise<Buffer | string | null>;
111
+ fetchFiles(uri: string | URL, pathname: string): Promise<string[]>;
112
+ fetchFiles(uri: string | URL, options?: Aria2Options): Promise<string[]>;
113
+ updateProgress(name: "request", id: number | string, receivedBytes: number, totalBytes: number, dataTime?: HighResolutionTime): void;
114
+ start(emptyDir?: boolean): Promise<FinalizeResult>;
115
+ processAssets(emptyDir?: boolean, using?: ExternalAsset[]): void;
116
+ deleteFile(src: string, promises: boolean): Promise<void>;
117
+ deleteFile(src: string, options: DeleteFileOptions & DeleteFileAddendum, promises: boolean): Promise<void>;
118
+ deleteFile(src: string, callback?: NoParamCallback): unknown;
119
+ deleteFile(src: string, options: DeleteFileOptions & DeleteFileAddendum, callback?: NoParamCallback): unknown;
120
+ restart(recursive?: boolean | "abort", emptyDir?: boolean): void;
121
+ restart(recursive?: boolean | "abort", exclusions?: string[], emptyDir?: boolean): void;
122
+ finalizeCompress(assets: ExternalAsset[]): Promise<unknown>;
123
+ finalizeDocument(): Promise<unknown>;
124
+ finalizeTask(assets: (ExternalAsset & Required<TaskAction>)[]): Promise<unknown>;
125
+ finalizeCloud(): Promise<unknown>;
126
+ finalizeCleanup(): Promise<unknown>;
127
+ finalize(): Promise<void>;
128
+ close(): void;
129
+ reset(): boolean;
130
+ get baseDirectory(): string;
131
+ get config(): RequestData;
132
+ get assets(): ExternalAsset[];
133
+ get incremental(): IncrementalMatch;
134
+ set restarting(value);
135
+ get restarting(): boolean;
136
+ get delayed(): number;
137
+ set cleared(value);
138
+ get cleared(): boolean;
139
+ set finalizeState(value);
140
+ get finalizeState(): number;
141
+
142
+ /* Set */
143
+ add(value: string, parent?: ExternalAsset, type?: number): this;
144
+ delete(value: string, emptyDir?: boolean): boolean;
145
+ has(value: unknown): value is string;
146
+
147
+ /* EventEmitter */
148
+ on(event: "end", listener: PostFinalizeCallback): this;
149
+ on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
150
+ on(event: "error", listener: (err: Error) => void): this;
151
+ on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
152
+ on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
153
+ on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
154
+ on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
155
+ on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
156
+ on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
157
+ on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
158
+ once(event: "end", listener: PostFinalizeCallback): this;
159
+ once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
160
+ once(event: "error", listener: (err: Error) => void): this;
161
+ once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
162
+ once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
163
+ once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
164
+ once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
165
+ once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
166
+ once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
167
+ once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
168
+ emit(event: "end", result: FinalizeResult): boolean;
169
+ emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
170
+ emit(event: "error", err: Error): boolean;
171
+ emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
172
+ emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
173
+ emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
174
+ emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
175
+ emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
176
+ emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
177
+ emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
178
+ }
179
+
180
+ interface FileManagerConstructor extends HostConstructor {
181
+ purgeMemory(percent?: number, limit?: number | boolean, parent?: number | boolean): Promise<number>;
182
+ loadSettings(settings: Settings, password?: string): boolean;
183
+ loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
184
+ sanitizeAssets(assets: ExternalAsset[], exclusions?: string[]): ExternalAsset[];
185
+ writeChecksum(root: string, options: ChecksumOptions): Promise<string[]>;
186
+ writeChecksum(root: string, to?: string, options?: ChecksumOptions): Promise<string[] | null>;
187
+ verifyChecksum(root: string, options: ChecksumOptions): Promise<[string[], string[], number] | null>;
188
+ verifyChecksum(root: string, from?: string, options?: ChecksumOptions): Promise<[string[], string[], number] | null>;
189
+ createFileThread(host: IFileManager, file: ExternalAsset): IFileThread;
190
+ setTimeout(options: Record<string, number | string>): void;
191
+ defineHttpCache(options: HttpMemorySettings, disk?: boolean): void;
192
+ defineHttpConnect(options: HttpConnectSettings): void;
193
+ readonly prototype: IFileManager;
194
+ new(baseDirectory: string, config: RequestData, postFinalize?: PostFinalizeCallback): IFileManager;
195
+ new(baseDirectory: string, config: RequestData, permission?: IPermission | null, postFinalize?: PostFinalizeCallback): IFileManager;
196
+ }
197
+ ```
198
+
199
+ ## Settings
200
+
201
+ ```typescript
202
+ interface ProcessModule {
203
+ thread?: {
204
+ sub_limit?: number;
205
+ };
206
+ }
207
+
208
+ interface RequestModule {
209
+ timeout?: number | string;
210
+ disk?: {
211
+ enabled?: boolean;
212
+ expires?: number | string;
213
+ limit?: number | string;
214
+ include?: string[];
215
+ exclude?: string[];
216
+ };
217
+ buffer?: {
218
+ enabled?: boolean;
219
+ expires?: number | string;
220
+ limit?: number | string;
221
+ include?: string[];
222
+ exclude?: string[];
223
+ limit_all?: number | string;
224
+ purge_amount?: number | string;
225
+ to_disk?: number | string | [number | string, (number | string)?];
226
+ };
227
+ connect?: {
228
+ timeout?: number | string;
229
+ retry_wait?: number | string;
230
+ retry_after?: number | string;
231
+ retry_limit?: number;
232
+ redirect_limit?: number;
233
+ };
234
+ }
235
+
236
+ interface ErrorModule {
237
+ recursion_limit?: number;
238
+ }
239
+
240
+ interface LoggerModule {
241
+ session_id?: boolean | number;
242
+ }
243
+ ```
244
+
245
+ ### Example usage
246
+
247
+ ```javascript
248
+ const FileManager = require("@e-mc/file-manager");
249
+
250
+ FileManager.loadSettings({ // Global
251
+ process: {
252
+ thread: { sub_limit: 16 }
253
+ },
254
+ request: {
255
+ timeout: "15s",
256
+ disk: {
257
+ enabled: true,
258
+ limit: "1gb", // Content-Length
259
+ expires: "1d",
260
+ exclude: ["https://github.com", "zip"]
261
+ },
262
+ buffer: {
263
+ enabled: true,
264
+ limit: "64mb",
265
+ limit_all: "512mb",
266
+ expires: "1h",
267
+ purge_amount: 0.25 // When limit_all exceeded
268
+ }
269
+ },
270
+ permission: {
271
+ disk_read: ["**/*"],
272
+ disk_write: ["/tmp/**"]
273
+ }
274
+ });
275
+
276
+ const assets = [
277
+ { pathname: "output", filename: "image1.png", uri: "http://hostname/path/document1.png" },
278
+ { pathname: "output", filename: "image2.png", uri: "http://hostname/path/document2.png" }
279
+ ];
280
+
281
+ const instance = new FileManager("/path/workspace", { assets, incremental: "etag" }, { disk_write: ["/path/workspace/output/**"] });
282
+ await instance.start();
283
+ ```
284
+
285
+ NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-mc/core) and [Module](https://www.npmjs.com/package/@e-mc/module). Their ``loadSettings`` will be called as well which uses a combined [Settings](https://e-mc.readthedocs.io/en/latest/references.html#references-e-mc-types-lib-node) object.
286
+
287
+ ## References
288
+
289
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/squared.d.ts
290
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/asset.d.ts
291
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/core.d.ts
292
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/filemanager.d.ts
293
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/logger.d.ts
294
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/module.d.ts
295
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/node.d.ts
296
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/request.d.ts
297
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/settings.d.ts
298
+
299
+ * https://www.npmjs.com/package/@types/node
300
+
301
+ ## LICENSE
302
+
303
303
  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 '@e-mc/types/lib';
2
+ import type { ExternalAsset } from '@e-mc/types/lib/asset';
3
+
4
+ declare const FileManager: FileManagerConstructor<ExternalAsset>;
5
+
6
6
  export = FileManager;
package/index.js CHANGED
@@ -171,7 +171,7 @@ function checkHash(localUri, output, options, data) {
171
171
  value = options;
172
172
  }
173
173
  if ((0, types_1.isString)(value)) {
174
- algorithm || (algorithm = "sha256");
174
+ algorithm ||= "sha256";
175
175
  if (!data) {
176
176
  try {
177
177
  data = fs.readFileSync(localUri);
@@ -583,7 +583,7 @@ class FileThread extends core_1.AbortComponent {
583
583
  }
584
584
  getObject(data) {
585
585
  const result = { ...data, file: this.file };
586
- result.mimeType || (result.mimeType = this.mimeType);
586
+ result.mimeType ||= this.mimeType;
587
587
  return result;
588
588
  }
589
589
  get host() {
@@ -734,10 +734,10 @@ class FileManager extends core_1.Host {
734
734
  to = undefined;
735
735
  }
736
736
  else {
737
- options || (options = {});
737
+ options ||= {};
738
738
  }
739
739
  const { algorithm, digest, sortBy = 0, recursive = false, ignore = [], include, exclude, verbose = false, joinRoot } = options;
740
- to || (to = checksumFile(algorithm));
740
+ to ||= checksumFile(algorithm);
741
741
  let result = [];
742
742
  try {
743
743
  const filename = path.basename(to);
@@ -782,12 +782,12 @@ class FileManager extends core_1.Host {
782
782
  from = undefined;
783
783
  }
784
784
  else {
785
- options || (options = {});
785
+ options ||= {};
786
786
  }
787
787
  const { digest, sortBy = 0, recursive = false, ignore = [], include, exclude, verbose = true, joinRoot } = options;
788
788
  const parent = recursive === 1 && typeof verbose !== 'number';
789
789
  let algorithm = options.algorithm;
790
- from || (from = checksumFile(algorithm));
790
+ from ||= checksumFile(algorithm);
791
791
  if (!algorithm) {
792
792
  switch (algorithm = path.extname(from).substring(1).toLowerCase()) {
793
793
  case 'md5':
@@ -1032,9 +1032,9 @@ class FileManager extends core_1.Host {
1032
1032
  item.encoding = encoding.endsWith('be') ? undefined : (0, types_1.getEncoding)(encoding);
1033
1033
  }
1034
1034
  if ((0, types_1.usingFlag)(item.flags)) {
1035
- (targeted || (targeted = [])).push(item);
1035
+ (targeted ||= []).push(item);
1036
1036
  }
1037
- item.id || (item.id = ++ASSET_ID);
1037
+ item.id ||= ++ASSET_ID;
1038
1038
  }
1039
1039
  this._assets = assets.slice(0);
1040
1040
  this[kIncremental] = incremental === "staging" ? "staging" : "none";
@@ -1448,7 +1448,7 @@ class FileManager extends core_1.Host {
1448
1448
  }
1449
1449
  }
1450
1450
  if (isFunction(target) && target.prototype instanceof image_1) {
1451
- return createInstance(this.Image ?? (this.Image = new Map()), 'handler', target, ...args);
1451
+ return createInstance(this.Image ??= new Map(), 'handler', target, ...args);
1452
1452
  }
1453
1453
  }
1454
1454
  break;
@@ -1804,7 +1804,7 @@ class FileManager extends core_1.Host {
1804
1804
  return data.file.localUri || '';
1805
1805
  }
1806
1806
  getMimeType(data) {
1807
- return data.mimeType || (data.mimeType = data.file.mimeType || core_1.Host.lookupMime(path.basename(this.getLocalUri(data))));
1807
+ return data.mimeType ||= data.file.mimeType || core_1.Host.lookupMime(path.basename(this.getLocalUri(data)));
1808
1808
  }
1809
1809
  getDocumentAssets(instance, condition) {
1810
1810
  return this.documentAssets.filter(item => this.hasDocument(instance, item.document) && (!condition || condition(item)));
@@ -1820,7 +1820,7 @@ class FileManager extends core_1.Host {
1820
1820
  sourceUTF8 = file.buffer.toString(file.encoding);
1821
1821
  file.buffer = null;
1822
1822
  }
1823
- else if (uri || (uri = file.localUri)) {
1823
+ else if (uri ||= file.localUri) {
1824
1824
  try {
1825
1825
  sourceUTF8 = fs.readFileSync(uri, file.encoding);
1826
1826
  }
@@ -1912,7 +1912,7 @@ class FileManager extends core_1.Host {
1912
1912
  return content;
1913
1913
  }
1914
1914
  let replacing, newline;
1915
- const getSeparator = (value) => newline || (newline = (0, util_2.getNewline)(value));
1915
+ const getSeparator = (value) => newline ||= (0, util_2.getNewline)(value);
1916
1916
  if (content && (replacing = this.contentToReplace.get(localUri)) && replacing.length) {
1917
1917
  for (let i = 0, value, match; i < replacing.length; ++i) {
1918
1918
  if ((0, types_1.isString)(value = appending[i])) {
@@ -1940,7 +1940,7 @@ class FileManager extends core_1.Host {
1940
1940
  return (content || '') + appending.reduce((a, b) => b ? a + getSeparator(b) + b : a, '');
1941
1941
  }
1942
1942
  writeBuffer(file, options) {
1943
- const buffer = file.sourceUTF8 ? Buffer.from(file.sourceUTF8, file.encoding || (file.encoding = 'utf-8')) : file.buffer;
1943
+ const buffer = file.sourceUTF8 ? Buffer.from(file.sourceUTF8, file.encoding ||= 'utf-8') : file.buffer;
1944
1944
  const localUri = file.localUri;
1945
1945
  if (buffer && localUri) {
1946
1946
  try {
@@ -1954,7 +1954,7 @@ class FileManager extends core_1.Host {
1954
1954
  return null;
1955
1955
  }
1956
1956
  writeImage(document, output) {
1957
- output.baseDirectory || (output.baseDirectory = this.baseDirectory);
1957
+ output.baseDirectory ||= this.baseDirectory;
1958
1958
  for (const { instance } of this.Document) {
1959
1959
  if (instance.writeImage && this.hasDocument(instance, document) && instance.writeImage(output)) {
1960
1960
  return true;
@@ -1970,7 +1970,7 @@ class FileManager extends core_1.Host {
1970
1970
  const document = data.file.document;
1971
1971
  const ext = path.extname(localUri).substring(1);
1972
1972
  let output;
1973
- saveAs || (saveAs = ext);
1973
+ saveAs ||= ext;
1974
1974
  if (document) {
1975
1975
  for (const { instance } of this.Document) {
1976
1976
  if (instance.addCopy && this.hasDocument(instance, document) && (output = instance.addCopy(data, saveAs, replace))) {
@@ -2003,7 +2003,7 @@ class FileManager extends core_1.Host {
2003
2003
  }
2004
2004
  } while (this.filesQueued.has(output) && ++i);
2005
2005
  }
2006
- this.filesQueued.add(output || (output = localUri));
2006
+ this.filesQueued.add(output ||= localUri);
2007
2007
  return output;
2008
2008
  }
2009
2009
  async findMime(file, rename) {
@@ -2056,7 +2056,7 @@ class FileManager extends core_1.Host {
2056
2056
  let output;
2057
2057
  switch (format) {
2058
2058
  case 'br':
2059
- options.mimeType || (options.mimeType = file.mimeType);
2059
+ options.mimeType ||= file.mimeType;
2060
2060
  case 'gz':
2061
2061
  output = localUri + '.' + format;
2062
2062
  break;
@@ -2243,7 +2243,7 @@ class FileManager extends core_1.Host {
2243
2243
  }
2244
2244
  addProcessTimeout(instance, file, timeout) {
2245
2245
  if (timeout > 0) {
2246
- const processModule = file.processModule || (file.processModule = {});
2246
+ const processModule = file.processModule ||= {};
2247
2247
  const current = processModule[instance.moduleName];
2248
2248
  if (current) {
2249
2249
  current.timeout += timeout;
@@ -2308,7 +2308,7 @@ class FileManager extends core_1.Host {
2308
2308
  if (typeof options === 'string') {
2309
2309
  options = { format: options };
2310
2310
  }
2311
- options.format || (options.format = 'json');
2311
+ options.format ||= 'json';
2312
2312
  return this.Request.get(uri, options).then(data => typeof data === 'object' ? data : null);
2313
2313
  }
2314
2314
  async fetchBuffer(uri, options) {
@@ -2333,7 +2333,7 @@ class FileManager extends core_1.Host {
2333
2333
  if (typeof options === 'string') {
2334
2334
  options = { pathname: options };
2335
2335
  }
2336
- options.pathname || (options.pathname = this.baseDirectory);
2336
+ options.pathname ||= this.baseDirectory;
2337
2337
  return this.Request.aria2c(uri, options);
2338
2338
  }
2339
2339
  async start(emptyDir) {
@@ -2381,7 +2381,7 @@ class FileManager extends core_1.Host {
2381
2381
  resetAssets.call(this);
2382
2382
  break;
2383
2383
  }
2384
- return this._pendingResult || (this._pendingResult = new Promise((resolve, reject) => {
2384
+ return this._pendingResult ||= new Promise((resolve, reject) => {
2385
2385
  this.on('end', listener(resolve));
2386
2386
  try {
2387
2387
  this.processAssets(emptyDir);
@@ -2390,7 +2390,7 @@ class FileManager extends core_1.Host {
2390
2390
  this.done = true;
2391
2391
  reject(err);
2392
2392
  }
2393
- }));
2393
+ });
2394
2394
  }
2395
2395
  processAssets(emptyDir, targeted) {
2396
2396
  if (this.aborted) {
@@ -2549,19 +2549,18 @@ class FileManager extends core_1.Host {
2549
2549
  }
2550
2550
  };
2551
2551
  const checkQueue = (file, localUri, pathname, content) => {
2552
- var _o;
2553
2552
  if (!createFolder(file, pathname)) {
2554
2553
  return true;
2555
2554
  }
2556
2555
  const { bundleId, bundleIndex = -1 } = file;
2557
2556
  if (!(0, types_1.isEmpty)(bundleId) && bundleIndex >= 0) {
2558
- const items = appending[localUri] || (appending[localUri] = []);
2559
- bundling[_o = file.uri] || (bundling[_o] = []);
2557
+ const items = appending[localUri] ||= [];
2558
+ bundling[file.uri] ||= [];
2560
2559
  if (bundleIndex > 0) {
2561
2560
  items[bundleIndex - 1] = file;
2562
2561
  let url, parent;
2563
2562
  if (file.fetchType === 1 && (cacheToDisk.has(url = file.url) || cacheToMemory.has(url)) && (parent = assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId))) {
2564
- (parent.bundleQueue || (parent.bundleQueue = [])).push(new Promise(resolve => {
2563
+ (parent.bundleQueue ||= []).push(new Promise(resolve => {
2565
2564
  this.Request.open(url, { method: 'HEAD', httpVersion: 1 })
2566
2565
  .on('response', res => {
2567
2566
  if (res.statusCode < 300) {
@@ -2651,7 +2650,7 @@ class FileManager extends core_1.Host {
2651
2650
  else {
2652
2651
  const tasks = [];
2653
2652
  for (const queue of items) {
2654
- const encoding = queue.encoding || (queue.encoding = 'utf-8');
2653
+ const encoding = queue.encoding ||= 'utf-8';
2655
2654
  const { uri, fetchType: type } = queue;
2656
2655
  let tempFile;
2657
2656
  if (checkEtag && queue.trailingContent) {
@@ -3100,7 +3099,7 @@ class FileManager extends core_1.Host {
3100
3099
  const content = item.content;
3101
3100
  item.sourceUTF8 = content;
3102
3101
  this.performAsyncTask();
3103
- fs.writeFile(localUri, content, item.encoding || (item.encoding = 'utf-8'), err => fileReceived(item, localUri, err));
3102
+ fs.writeFile(localUri, content, item.encoding ||= 'utf-8', err => fileReceived(item, localUri, err));
3104
3103
  }
3105
3104
  continue;
3106
3105
  }
@@ -3396,7 +3395,7 @@ class FileManager extends core_1.Host {
3396
3395
  errorRequest(item, localUri, (0, types_1.errorValue)("No files were successfully downloaded", uri));
3397
3396
  }
3398
3397
  else if (bundleMain) {
3399
- const encoding = item.encoding || (item.encoding = 'utf-8');
3398
+ const encoding = item.encoding ||= 'utf-8';
3400
3399
  fs.writeFile(localUri, bundleTorrent.call(this, result, item.mimeType, encoding), encoding, err => {
3401
3400
  if (!err) {
3402
3401
  fetchedAssets.push(item);
@@ -3573,7 +3572,7 @@ class FileManager extends core_1.Host {
3573
3572
  if (pid > 0) {
3574
3573
  const found = scheduler.status.find(item => item.id === pid);
3575
3574
  if (found) {
3576
- found.endTime || (found.endTime = Date.now());
3575
+ found.endTime ||= Date.now();
3577
3576
  }
3578
3577
  }
3579
3578
  --scheduler.count;
@@ -3781,7 +3780,7 @@ class FileManager extends core_1.Host {
3781
3780
  for (const item of this.assets) {
3782
3781
  if (item.sourceUTF8 && !ignoreAsset(item)) {
3783
3782
  try {
3784
- fs.writeFileSync(item.localUri, item.sourceUTF8, item.encoding || (item.encoding = 'utf-8'));
3783
+ fs.writeFileSync(item.localUri, item.sourceUTF8, item.encoding ||= 'utf-8');
3785
3784
  }
3786
3785
  catch (err) {
3787
3786
  this.writeFail(["Unable to write file", path.basename(item.localUri)], err, { type: 32, startTime });
package/package.json CHANGED
@@ -1,35 +1,35 @@
1
- {
2
- "name": "@e-mc/file-manager",
3
- "version": "0.9.9",
4
- "description": "FileManager constructor for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/file-manager"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/cloud": "0.9.9",
24
- "@e-mc/compress": "0.9.9",
25
- "@e-mc/core": "0.9.9",
26
- "@e-mc/document": "0.9.9",
27
- "@e-mc/image": "0.9.9",
28
- "@e-mc/request": "0.9.9",
29
- "@e-mc/task": "0.9.9",
30
- "@e-mc/types": "0.9.9",
31
- "@e-mc/watch": "0.9.9",
32
- "chalk": "4.1.2",
33
- "picomatch": "^4.0.2"
34
- }
35
- }
1
+ {
2
+ "name": "@e-mc/file-manager",
3
+ "version": "0.9.11",
4
+ "description": "FileManager constructor for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/file-manager"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "BSD 3-Clause",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/cloud": "0.9.11",
24
+ "@e-mc/compress": "0.9.11",
25
+ "@e-mc/core": "0.9.11",
26
+ "@e-mc/document": "0.9.11",
27
+ "@e-mc/image": "0.9.11",
28
+ "@e-mc/request": "0.9.11",
29
+ "@e-mc/task": "0.9.11",
30
+ "@e-mc/types": "0.9.11",
31
+ "@e-mc/watch": "0.9.11",
32
+ "chalk": "4.1.2",
33
+ "picomatch": "^4.0.2"
34
+ }
35
+ }