@spinajs/fs 2.0.481 → 2.0.482
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/lib/cjs/cli/cat.d.ts +11 -0
- package/lib/cjs/cli/cat.d.ts.map +1 -0
- package/lib/cjs/cli/cat.js +40 -0
- package/lib/cjs/cli/cat.js.map +1 -0
- package/lib/cjs/cli/cp.d.ts +11 -0
- package/lib/cjs/cli/cp.d.ts.map +1 -0
- package/lib/cjs/cli/cp.js +41 -0
- package/lib/cjs/cli/cp.js.map +1 -0
- package/lib/cjs/cli/download.d.ts +7 -0
- package/lib/cjs/cli/download.d.ts.map +1 -0
- package/lib/cjs/cli/download.js +39 -0
- package/lib/cjs/cli/download.js.map +1 -0
- package/lib/cjs/cli/exists.d.ts +7 -0
- package/lib/cjs/cli/exists.d.ts.map +1 -0
- package/lib/cjs/cli/exists.js +39 -0
- package/lib/cjs/cli/exists.js.map +1 -0
- package/lib/cjs/cli/fs.d.ts +11 -0
- package/lib/cjs/cli/fs.d.ts.map +1 -1
- package/lib/cjs/cli/fs.js +47 -21
- package/lib/cjs/cli/fs.js.map +1 -1
- package/lib/cjs/cli/hash.d.ts +11 -0
- package/lib/cjs/cli/hash.d.ts.map +1 -0
- package/lib/cjs/cli/hash.js +40 -0
- package/lib/cjs/cli/hash.js.map +1 -0
- package/lib/cjs/cli/info.d.ts +7 -0
- package/lib/cjs/cli/info.d.ts.map +1 -0
- package/lib/cjs/cli/info.js +45 -0
- package/lib/cjs/cli/info.js.map +1 -0
- package/lib/cjs/cli/ls.d.ts +7 -0
- package/lib/cjs/cli/ls.d.ts.map +1 -0
- package/lib/cjs/cli/ls.js +40 -0
- package/lib/cjs/cli/ls.js.map +1 -0
- package/lib/cjs/cli/mkdir.d.ts +7 -0
- package/lib/cjs/cli/mkdir.d.ts.map +1 -0
- package/lib/cjs/cli/mkdir.js +39 -0
- package/lib/cjs/cli/mkdir.js.map +1 -0
- package/lib/cjs/cli/mv.d.ts +11 -0
- package/lib/cjs/cli/mv.d.ts.map +1 -0
- package/lib/cjs/cli/mv.js +41 -0
- package/lib/cjs/cli/mv.js.map +1 -0
- package/lib/cjs/cli/rm.d.ts +1 -6
- package/lib/cjs/cli/rm.d.ts.map +1 -1
- package/lib/cjs/cli/rm.js +14 -4
- package/lib/cjs/cli/rm.js.map +1 -1
- package/lib/cjs/cli/stat.d.ts +1 -5
- package/lib/cjs/cli/stat.d.ts.map +1 -1
- package/lib/cjs/cli/stat.js +20 -3
- package/lib/cjs/cli/stat.js.map +1 -1
- package/lib/cjs/cli/unzip.d.ts +11 -0
- package/lib/cjs/cli/unzip.d.ts.map +1 -0
- package/lib/cjs/cli/unzip.js +47 -0
- package/lib/cjs/cli/unzip.js.map +1 -0
- package/lib/cjs/cli/upload.d.ts +7 -0
- package/lib/cjs/cli/upload.d.ts.map +1 -0
- package/lib/cjs/cli/upload.js +40 -0
- package/lib/cjs/cli/upload.js.map +1 -0
- package/lib/cjs/cli/write.d.ts +13 -0
- package/lib/cjs/cli/write.d.ts.map +1 -0
- package/lib/cjs/cli/write.js +54 -0
- package/lib/cjs/cli/write.js.map +1 -0
- package/lib/cjs/cli/zip.d.ts +12 -0
- package/lib/cjs/cli/zip.d.ts.map +1 -0
- package/lib/cjs/cli/zip.js +51 -0
- package/lib/cjs/cli/zip.js.map +1 -0
- package/lib/cjs/config/fs.d.ts +9 -0
- package/lib/cjs/config/fs.d.ts.map +1 -0
- package/lib/cjs/config/fs.js +22 -0
- package/lib/cjs/config/fs.js.map +1 -0
- package/lib/cjs/file-hasher.d.ts +85 -5
- package/lib/cjs/file-hasher.d.ts.map +1 -1
- package/lib/cjs/file-hasher.js +106 -14
- package/lib/cjs/file-hasher.js.map +1 -1
- package/lib/cjs/file-info.d.ts +94 -5
- package/lib/cjs/file-info.d.ts.map +1 -1
- package/lib/cjs/file-info.js +267 -73
- package/lib/cjs/file-info.js.map +1 -1
- package/lib/cjs/fp.d.ts +80 -2
- package/lib/cjs/fp.d.ts.map +1 -1
- package/lib/cjs/fp.js +149 -3
- package/lib/cjs/fp.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +7 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +89 -12
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +13 -13
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/local-provider.d.ts +51 -6
- package/lib/cjs/local-provider.d.ts.map +1 -1
- package/lib/cjs/local-provider.js +254 -76
- package/lib/cjs/local-provider.js.map +1 -1
- package/lib/cjs/temp-cleanup-strategy.d.ts +70 -0
- package/lib/cjs/temp-cleanup-strategy.d.ts.map +1 -0
- package/lib/cjs/temp-cleanup-strategy.js +157 -0
- package/lib/cjs/temp-cleanup-strategy.js.map +1 -0
- package/lib/cjs/temp-provider.d.ts +59 -0
- package/lib/cjs/temp-provider.d.ts.map +1 -0
- package/lib/cjs/temp-provider.js +150 -0
- package/lib/cjs/temp-provider.js.map +1 -0
- package/lib/mjs/cli/cat.d.ts +11 -0
- package/lib/mjs/cli/cat.d.ts.map +1 -0
- package/lib/mjs/cli/cat.js +37 -0
- package/lib/mjs/cli/cat.js.map +1 -0
- package/lib/mjs/cli/cp.d.ts +11 -0
- package/lib/mjs/cli/cp.d.ts.map +1 -0
- package/lib/mjs/cli/cp.js +38 -0
- package/lib/mjs/cli/cp.js.map +1 -0
- package/lib/mjs/cli/download.d.ts +7 -0
- package/lib/mjs/cli/download.d.ts.map +1 -0
- package/lib/mjs/cli/download.js +36 -0
- package/lib/mjs/cli/download.js.map +1 -0
- package/lib/mjs/cli/exists.d.ts +7 -0
- package/lib/mjs/cli/exists.d.ts.map +1 -0
- package/lib/mjs/cli/exists.js +36 -0
- package/lib/mjs/cli/exists.js.map +1 -0
- package/lib/mjs/cli/fs.d.ts +11 -1
- package/lib/mjs/cli/fs.d.ts.map +1 -1
- package/lib/mjs/cli/fs.js +43 -22
- package/lib/mjs/cli/fs.js.map +1 -1
- package/lib/mjs/cli/hash.d.ts +11 -0
- package/lib/mjs/cli/hash.d.ts.map +1 -0
- package/lib/mjs/cli/hash.js +37 -0
- package/lib/mjs/cli/hash.js.map +1 -0
- package/lib/mjs/cli/info.d.ts +7 -0
- package/lib/mjs/cli/info.d.ts.map +1 -0
- package/lib/mjs/cli/info.js +42 -0
- package/lib/mjs/cli/info.js.map +1 -0
- package/lib/mjs/cli/ls.d.ts +7 -0
- package/lib/mjs/cli/ls.d.ts.map +1 -0
- package/lib/mjs/cli/ls.js +37 -0
- package/lib/mjs/cli/ls.js.map +1 -0
- package/lib/mjs/cli/mkdir.d.ts +7 -0
- package/lib/mjs/cli/mkdir.d.ts.map +1 -0
- package/lib/mjs/cli/mkdir.js +36 -0
- package/lib/mjs/cli/mkdir.js.map +1 -0
- package/lib/mjs/cli/mv.d.ts +11 -0
- package/lib/mjs/cli/mv.d.ts.map +1 -0
- package/lib/mjs/cli/mv.js +38 -0
- package/lib/mjs/cli/mv.js.map +1 -0
- package/lib/mjs/cli/rm.d.ts +1 -6
- package/lib/mjs/cli/rm.d.ts.map +1 -1
- package/lib/mjs/cli/rm.js +15 -5
- package/lib/mjs/cli/rm.js.map +1 -1
- package/lib/mjs/cli/stat.d.ts +1 -5
- package/lib/mjs/cli/stat.d.ts.map +1 -1
- package/lib/mjs/cli/stat.js +21 -4
- package/lib/mjs/cli/stat.js.map +1 -1
- package/lib/mjs/cli/unzip.d.ts +11 -0
- package/lib/mjs/cli/unzip.d.ts.map +1 -0
- package/lib/mjs/cli/unzip.js +44 -0
- package/lib/mjs/cli/unzip.js.map +1 -0
- package/lib/mjs/cli/upload.d.ts +7 -0
- package/lib/mjs/cli/upload.d.ts.map +1 -0
- package/lib/mjs/cli/upload.js +37 -0
- package/lib/mjs/cli/upload.js.map +1 -0
- package/lib/mjs/cli/write.d.ts +13 -0
- package/lib/mjs/cli/write.d.ts.map +1 -0
- package/lib/mjs/cli/write.js +51 -0
- package/lib/mjs/cli/write.js.map +1 -0
- package/lib/mjs/cli/zip.d.ts +12 -0
- package/lib/mjs/cli/zip.d.ts.map +1 -0
- package/lib/mjs/cli/zip.js +48 -0
- package/lib/mjs/cli/zip.js.map +1 -0
- package/lib/mjs/config/fs.d.ts +9 -0
- package/lib/mjs/config/fs.d.ts.map +1 -0
- package/lib/mjs/config/fs.js +20 -0
- package/lib/mjs/config/fs.js.map +1 -0
- package/lib/mjs/file-hasher.d.ts +85 -5
- package/lib/mjs/file-hasher.d.ts.map +1 -1
- package/lib/mjs/file-hasher.js +106 -14
- package/lib/mjs/file-hasher.js.map +1 -1
- package/lib/mjs/file-info.d.ts +94 -5
- package/lib/mjs/file-info.d.ts.map +1 -1
- package/lib/mjs/file-info.js +233 -73
- package/lib/mjs/file-info.js.map +1 -1
- package/lib/mjs/fp.d.ts +80 -2
- package/lib/mjs/fp.d.ts.map +1 -1
- package/lib/mjs/fp.js +135 -4
- package/lib/mjs/fp.js.map +1 -1
- package/lib/mjs/index.d.ts +2 -1
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +8 -3
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +89 -12
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +13 -13
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/local-provider.d.ts +51 -6
- package/lib/mjs/local-provider.d.ts.map +1 -1
- package/lib/mjs/local-provider.js +257 -79
- package/lib/mjs/local-provider.js.map +1 -1
- package/lib/mjs/temp-cleanup-strategy.d.ts +70 -0
- package/lib/mjs/temp-cleanup-strategy.d.ts.map +1 -0
- package/lib/mjs/temp-cleanup-strategy.js +153 -0
- package/lib/mjs/temp-cleanup-strategy.js.map +1 -0
- package/lib/mjs/temp-provider.d.ts +59 -0
- package/lib/mjs/temp-provider.d.ts.map +1 -0
- package/lib/mjs/temp-provider.js +147 -0
- package/lib/mjs/temp-provider.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +11 -6
- package/lib/cjs/local-temp-provider.d.ts +0 -18
- package/lib/cjs/local-temp-provider.d.ts.map +0 -1
- package/lib/cjs/local-temp-provider.js +0 -63
- package/lib/cjs/local-temp-provider.js.map +0 -1
- package/lib/mjs/local-temp-provider.d.ts +0 -18
- package/lib/mjs/local-temp-provider.d.ts.map +0 -1
- package/lib/mjs/local-temp-provider.js +0 -60
- package/lib/mjs/local-temp-provider.js.map +0 -1
package/lib/mjs/file-info.d.ts
CHANGED
|
@@ -1,11 +1,100 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
+
import { Log } from '@spinajs/log-common';
|
|
2
3
|
import { FileInfoService, IFileInfo } from './interfaces.js';
|
|
4
|
+
import { DateTime } from 'luxon';
|
|
5
|
+
/**
|
|
6
|
+
* A single extracted metadata value.
|
|
7
|
+
*/
|
|
8
|
+
type ExifValue = string | number | DateTime;
|
|
9
|
+
/**
|
|
10
|
+
* Resolves the path to the exiftool binary.
|
|
11
|
+
*
|
|
12
|
+
* Prefers the vendored binary shipped with the `exiftool-vendored` platform
|
|
13
|
+
* packages ( no system installation required ), and falls back to `exiftool`
|
|
14
|
+
* available on PATH.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveExifToolPath(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Default {@link FileInfoService} implementation backed by the `exiftool`
|
|
19
|
+
* command line tool.
|
|
20
|
+
*
|
|
21
|
+
* The binary is auto-resolved ( vendored, then PATH ) unless overridden with
|
|
22
|
+
* the `fs.fileInfo.exifToolPath` configuration key. The invocation is bounded
|
|
23
|
+
* by the `fs.fileInfo.timeout` configuration ( default {@link DEFAULT_TIMEOUT} ).
|
|
24
|
+
*/
|
|
3
25
|
export declare class DefaultFileInfo extends FileInfoService {
|
|
4
26
|
protected Log: Log;
|
|
27
|
+
/**
|
|
28
|
+
* Optional exiftool binary path override from configuration. When unset, the
|
|
29
|
+
* binary is auto-resolved via {@link resolveExifToolPath}.
|
|
30
|
+
*/
|
|
31
|
+
protected ConfiguredPath?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Timeout ( ms ) for the exiftool process, from configuration.
|
|
34
|
+
*/
|
|
35
|
+
protected Timeout: number;
|
|
36
|
+
/**
|
|
37
|
+
* exiftool arguments controlling extraction breadth, from configuration
|
|
38
|
+
* ( default {@link DEFAULT_ARGS} ). The file spec ( path or `-` ) is appended
|
|
39
|
+
* automatically. NOTE: some flags ( eg. `-G` ) change the output tag names.
|
|
40
|
+
*/
|
|
41
|
+
protected ExifArgs: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Auto-resolved exiftool binary path, cached after first use.
|
|
44
|
+
*/
|
|
45
|
+
protected ExifToolPath: string;
|
|
46
|
+
/**
|
|
47
|
+
* Extracts file information from a file on disk.
|
|
48
|
+
*
|
|
49
|
+
* @param pathToFile absolute path to the file
|
|
50
|
+
* @throws {IOFail} when the file does not exist or exiftool fails
|
|
51
|
+
*/
|
|
5
52
|
getInfo(pathToFile: string): Promise<IFileInfo>;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Extracts file information from a readable stream by piping its content to
|
|
55
|
+
* exiftool via stdin ( `exiftool -n -` ).
|
|
56
|
+
*
|
|
57
|
+
* @param stream readable stream with the file content
|
|
58
|
+
* @throws {IOFail} when exiftool fails or the stream errors
|
|
59
|
+
*/
|
|
60
|
+
getInfoFromStream(stream: NodeJS.ReadableStream): Promise<IFileInfo>;
|
|
61
|
+
/**
|
|
62
|
+
* Resolves the exiftool binary path, preferring the configured override.
|
|
63
|
+
*/
|
|
64
|
+
protected binaryPath(): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Spawns the exiftool process. Extracted so it can be overridden ( eg. in tests ).
|
|
67
|
+
*/
|
|
68
|
+
protected spawnExif(binary: string, args: string[]): ChildProcessWithoutNullStreams;
|
|
69
|
+
/**
|
|
70
|
+
* Runs exiftool against a file spec ( a path, or `-` for stdin ) and returns
|
|
71
|
+
* its stdout.
|
|
72
|
+
*
|
|
73
|
+
* Success/failure is determined by the process exit code ( not by the mere
|
|
74
|
+
* presence of stderr, which exiftool uses for non-fatal warnings ). The call
|
|
75
|
+
* is bounded by {@link Timeout} and any failure is surfaced as {@link IOFail}.
|
|
76
|
+
*
|
|
77
|
+
* @param fileArg file path or `-` to read from stdin
|
|
78
|
+
* @param input optional readable stream piped to the process stdin
|
|
79
|
+
*/
|
|
80
|
+
protected runExifTool(fileArg: string, input?: NodeJS.ReadableStream): Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Parses raw exiftool text output into a `{ normalisedTag: value }` map with
|
|
83
|
+
* EVERY emitted tag ( nothing is filtered ).
|
|
84
|
+
*
|
|
85
|
+
* Each line is split on the FIRST `': '` only, so values that themselves
|
|
86
|
+
* contain `': '` are preserved. Values are coerced by {@link coerceValue}
|
|
87
|
+
* ( numbers and date-shaped strings ).
|
|
88
|
+
*/
|
|
89
|
+
protected parseMetadata(raw: string): Record<string, ExifValue>;
|
|
90
|
+
/**
|
|
91
|
+
* Projects a parsed metadata map onto {@link IFileInfo}.
|
|
92
|
+
*
|
|
93
|
+
* Every extracted tag is promoted: known tags via their {@link TAG_ALIASES}
|
|
94
|
+
* friendly field name, all others under their PascalCased tag name. The full
|
|
95
|
+
* unmodified map is always available under `Raw`.
|
|
96
|
+
*/
|
|
97
|
+
protected toFileInfo(metadata: Record<string, ExifValue>): IFileInfo;
|
|
10
98
|
}
|
|
99
|
+
export {};
|
|
11
100
|
//# sourceMappingURL=file-info.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-info.d.ts","sourceRoot":"","sources":["../../src/file-info.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file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8C5F;;;;;;;OAOG;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAqB/D;;;;;;OAMG;IACH,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS;CAarE"}
|
package/lib/mjs/file-info.js
CHANGED
|
@@ -7,114 +7,274 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
/// <reference path="./typings/exiftool.d.ts" />
|
|
11
|
+
import { spawn } from 'node:child_process';
|
|
11
12
|
import { Injectable } from '@spinajs/di';
|
|
12
|
-
import {
|
|
13
|
+
import { Config } from '@spinajs/configuration';
|
|
14
|
+
import { Log, Logger } from '@spinajs/log-common';
|
|
13
15
|
import { IOFail } from '@spinajs/exceptions';
|
|
14
16
|
import { existsSync } from 'fs';
|
|
15
17
|
import { FileInfoService } from './interfaces.js';
|
|
16
|
-
import { DateTime } from
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
import { DateTime } from 'luxon';
|
|
19
|
+
/**
|
|
20
|
+
* Default process timeout ( ms ) for the exiftool invocation.
|
|
21
|
+
*/
|
|
22
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
23
|
+
/**
|
|
24
|
+
* Default exiftool arguments. `-n` disables print-conversion ( numeric values ).
|
|
25
|
+
* Extend via the `fs.fileInfo.args` configuration ( eg. add `-a`, `-G`, `-ee`,
|
|
26
|
+
* `-All` ) to widen what is extracted.
|
|
27
|
+
*/
|
|
28
|
+
const DEFAULT_ARGS = ['-n'];
|
|
29
|
+
/**
|
|
30
|
+
* Friendly aliases: normalised exiftool tag -> {@link IFileInfo} field name.
|
|
31
|
+
*
|
|
32
|
+
* This is NOT an allow-list - every tag emitted by exiftool is extracted and
|
|
33
|
+
* promoted ( see {@link DefaultFileInfo.toFileInfo} ). Aliases only give the
|
|
34
|
+
* most common tags stable, typed names and keep existing consumers working.
|
|
35
|
+
* Several source tags may collapse onto one field ( eg. duration / playDuration ).
|
|
36
|
+
*/
|
|
37
|
+
const TAG_ALIASES = {
|
|
20
38
|
imageWidth: 'Width',
|
|
39
|
+
imageHeight: 'Height',
|
|
21
40
|
duration: 'Duration',
|
|
22
41
|
playDuration: 'Duration',
|
|
23
42
|
frameCount: 'FrameCount',
|
|
24
43
|
frameRate: 'FrameRate',
|
|
25
44
|
videoFrameRate: 'FrameRate',
|
|
45
|
+
audioChannels: 'AudioChannels',
|
|
26
46
|
maxBitrate: 'Bitrate',
|
|
27
47
|
maxDataRate: 'Bitrate',
|
|
28
48
|
avgBitrate: 'Bitrate',
|
|
29
49
|
compressorID: 'Codec',
|
|
30
|
-
fileSize:
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
fileSize: 'FileSize',
|
|
51
|
+
mimeType: 'MimeType',
|
|
52
|
+
mimeEncoding: 'Encoding',
|
|
53
|
+
wordCount: 'WordCount',
|
|
54
|
+
lineCount: 'LineCount',
|
|
55
|
+
fileAccessDateTime: 'AccessDate',
|
|
56
|
+
fileCreationDateTime: 'CreationDate',
|
|
57
|
+
fileModificationDateTime: 'ModificationDate',
|
|
38
58
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Matches the leading part of an exiftool date value, eg. `2024:01:15 10:30:45`.
|
|
61
|
+
*/
|
|
62
|
+
const EXIFTOOL_DATE = /^\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}/;
|
|
63
|
+
/**
|
|
64
|
+
* Date formats exiftool may emit ( with/without sub-seconds and timezone ).
|
|
65
|
+
*/
|
|
66
|
+
const EXIFTOOL_DATE_FORMATS = [
|
|
67
|
+
'yyyy:MM:dd HH:mm:ssZZ',
|
|
68
|
+
'yyyy:MM:dd HH:mm:ss.SSSZZ',
|
|
69
|
+
'yyyy:MM:dd HH:mm:ss.SSS',
|
|
70
|
+
'yyyy:MM:dd HH:mm:ss',
|
|
71
|
+
];
|
|
72
|
+
/**
|
|
73
|
+
* Normalises a raw exiftool tag name ( eg. "Image Width", "File
|
|
74
|
+
* Modification Date/Time" ) into a stable camelCase key ( "imageWidth",
|
|
75
|
+
* "fileModificationDateTime" ) by splitting on any non-alphanumeric run.
|
|
76
|
+
*/
|
|
77
|
+
function normalizeTag(rawTag) {
|
|
78
|
+
return rawTag
|
|
79
|
+
.split(/[^a-zA-Z0-9]+/)
|
|
80
|
+
.filter((token) => token.length > 0)
|
|
81
|
+
.map((token, index) => (index === 0 ? token.toLowerCase() : token[0].toUpperCase() + token.slice(1)))
|
|
82
|
+
.join('');
|
|
51
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Coerces a raw exiftool string value into a typed value: date-shaped strings
|
|
86
|
+
* become {@link DateTime} ( detected by value shape, not by a hardcoded field
|
|
87
|
+
* list ), purely numeric strings become numbers, everything else stays a string.
|
|
88
|
+
*/
|
|
89
|
+
function coerceValue(value) {
|
|
90
|
+
if (EXIFTOOL_DATE.test(value)) {
|
|
91
|
+
for (const format of EXIFTOOL_DATE_FORMATS) {
|
|
92
|
+
const parsed = DateTime.fromFormat(value, format);
|
|
93
|
+
if (parsed.isValid) {
|
|
94
|
+
return parsed;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (value !== '' && +value === +value) {
|
|
99
|
+
return parseFloat(value);
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Resolves the path to the exiftool binary.
|
|
105
|
+
*
|
|
106
|
+
* Prefers the vendored binary shipped with the `exiftool-vendored` platform
|
|
107
|
+
* packages ( no system installation required ), and falls back to `exiftool`
|
|
108
|
+
* available on PATH.
|
|
109
|
+
*/
|
|
110
|
+
export async function resolveExifToolPath() {
|
|
111
|
+
try {
|
|
112
|
+
const mod = process.platform === 'win32' ? await import('exiftool-vendored.exe') : await import('exiftool-vendored.pl');
|
|
113
|
+
const binaryPath = (mod.default ?? mod);
|
|
114
|
+
if (typeof binaryPath === 'string' && existsSync(binaryPath)) {
|
|
115
|
+
return binaryPath;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
/* vendored package not installed for this platform - fall back to PATH */
|
|
120
|
+
}
|
|
121
|
+
return 'exiftool';
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Default {@link FileInfoService} implementation backed by the `exiftool`
|
|
125
|
+
* command line tool.
|
|
126
|
+
*
|
|
127
|
+
* The binary is auto-resolved ( vendored, then PATH ) unless overridden with
|
|
128
|
+
* the `fs.fileInfo.exifToolPath` configuration key. The invocation is bounded
|
|
129
|
+
* by the `fs.fileInfo.timeout` configuration ( default {@link DEFAULT_TIMEOUT} ).
|
|
130
|
+
*/
|
|
52
131
|
let DefaultFileInfo = class DefaultFileInfo extends FileInfoService {
|
|
132
|
+
/**
|
|
133
|
+
* Extracts file information from a file on disk.
|
|
134
|
+
*
|
|
135
|
+
* @param pathToFile absolute path to the file
|
|
136
|
+
* @throws {IOFail} when the file does not exist or exiftool fails
|
|
137
|
+
*/
|
|
53
138
|
async getInfo(pathToFile) {
|
|
54
139
|
if (!existsSync(pathToFile)) {
|
|
55
140
|
throw new IOFail(`Path ${pathToFile} not exists`);
|
|
56
141
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
142
|
+
const raw = await this.runExifTool(pathToFile);
|
|
143
|
+
return this.toFileInfo(this.parseMetadata(raw));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Extracts file information from a readable stream by piping its content to
|
|
147
|
+
* exiftool via stdin ( `exiftool -n -` ).
|
|
148
|
+
*
|
|
149
|
+
* @param stream readable stream with the file content
|
|
150
|
+
* @throws {IOFail} when exiftool fails or the stream errors
|
|
151
|
+
*/
|
|
152
|
+
async getInfoFromStream(stream) {
|
|
153
|
+
const raw = await this.runExifTool('-', stream);
|
|
154
|
+
return this.toFileInfo(this.parseMetadata(raw));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Resolves the exiftool binary path, preferring the configured override.
|
|
158
|
+
*/
|
|
159
|
+
async binaryPath() {
|
|
160
|
+
if (this.ConfiguredPath) {
|
|
161
|
+
return this.ConfiguredPath;
|
|
70
162
|
}
|
|
71
|
-
|
|
163
|
+
if (!this.ExifToolPath) {
|
|
164
|
+
this.ExifToolPath = await resolveExifToolPath();
|
|
165
|
+
this.Log.trace(`Using exiftool binary: ${this.ExifToolPath}`);
|
|
166
|
+
}
|
|
167
|
+
return this.ExifToolPath;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Spawns the exiftool process. Extracted so it can be overridden ( eg. in tests ).
|
|
171
|
+
*/
|
|
172
|
+
spawnExif(binary, args) {
|
|
173
|
+
return spawn(binary, args);
|
|
72
174
|
}
|
|
73
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Runs exiftool against a file spec ( a path, or `-` for stdin ) and returns
|
|
177
|
+
* its stdout.
|
|
178
|
+
*
|
|
179
|
+
* Success/failure is determined by the process exit code ( not by the mere
|
|
180
|
+
* presence of stderr, which exiftool uses for non-fatal warnings ). The call
|
|
181
|
+
* is bounded by {@link Timeout} and any failure is surfaced as {@link IOFail}.
|
|
182
|
+
*
|
|
183
|
+
* @param fileArg file path or `-` to read from stdin
|
|
184
|
+
* @param input optional readable stream piped to the process stdin
|
|
185
|
+
*/
|
|
186
|
+
async runExifTool(fileArg, input) {
|
|
187
|
+
const binary = await this.binaryPath();
|
|
188
|
+
const child = this.spawnExif(binary, [...this.ExifArgs, fileArg]);
|
|
74
189
|
return new Promise((resolve, reject) => {
|
|
75
|
-
|
|
76
|
-
let
|
|
77
|
-
let
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
190
|
+
let stdout = '';
|
|
191
|
+
let stderr = '';
|
|
192
|
+
let settled = false;
|
|
193
|
+
const finish = (fn) => {
|
|
194
|
+
if (settled) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
settled = true;
|
|
198
|
+
clearTimeout(timer);
|
|
199
|
+
fn();
|
|
200
|
+
};
|
|
201
|
+
const timer = setTimeout(() => {
|
|
202
|
+
child.kill('SIGKILL');
|
|
203
|
+
finish(() => reject(new IOFail(`exiftool timed out after ${this.Timeout}ms`)));
|
|
204
|
+
}, this.Timeout);
|
|
205
|
+
child.on('error', (err) => finish(() => reject(new IOFail(`Cannot run exiftool ( ${binary} )`, err))));
|
|
206
|
+
child.on('close', (code) => finish(() => code === 0
|
|
207
|
+
? resolve(stdout)
|
|
208
|
+
: reject(new IOFail(`exiftool exited with code ${code}${stderr ? `: ${stderr.trim()}` : ''}`))));
|
|
209
|
+
child.stdout.on('data', (data) => (stdout += data.toString('utf-8')));
|
|
210
|
+
child.stderr.on('data', (data) => (stderr += data.toString('utf-8')));
|
|
211
|
+
if (input) {
|
|
212
|
+
input.on('error', (err) => finish(() => {
|
|
213
|
+
child.kill('SIGKILL');
|
|
214
|
+
reject(new IOFail('Error reading input stream for exiftool', err));
|
|
215
|
+
}));
|
|
216
|
+
input.pipe(child.stdin);
|
|
217
|
+
}
|
|
82
218
|
});
|
|
83
219
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
220
|
+
/**
|
|
221
|
+
* Parses raw exiftool text output into a `{ normalisedTag: value }` map with
|
|
222
|
+
* EVERY emitted tag ( nothing is filtered ).
|
|
223
|
+
*
|
|
224
|
+
* Each line is split on the FIRST `': '` only, so values that themselves
|
|
225
|
+
* contain `': '` are preserved. Values are coerced by {@link coerceValue}
|
|
226
|
+
* ( numbers and date-shaped strings ).
|
|
227
|
+
*/
|
|
228
|
+
parseMetadata(raw) {
|
|
89
229
|
const metaData = {};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
//Turn the plain text data key into a camel case key.
|
|
95
|
-
var key = pieces[0].trim().split(' ').map(function (tokenInKey, tokenNumber) {
|
|
96
|
-
if (tokenNumber === 0)
|
|
97
|
-
return tokenInKey.toLowerCase();
|
|
98
|
-
else
|
|
99
|
-
return tokenInKey[0].toUpperCase() + tokenInKey.slice(1);
|
|
100
|
-
}).join('');
|
|
101
|
-
//Trim the value associated with the key to make it nice.
|
|
102
|
-
var value = pieces[1].trim();
|
|
103
|
-
if (+value === +value) {
|
|
104
|
-
metaData[key] = parseFloat(value);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
metaData[key] = value;
|
|
108
|
-
}
|
|
230
|
+
for (const line of raw.split('\n')) {
|
|
231
|
+
const sep = line.indexOf(': ');
|
|
232
|
+
if (sep === -1) {
|
|
233
|
+
continue;
|
|
109
234
|
}
|
|
110
|
-
|
|
235
|
+
const rawKey = line.slice(0, sep).trim();
|
|
236
|
+
const value = line.slice(sep + 2).trim();
|
|
237
|
+
if (!rawKey) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
metaData[normalizeTag(rawKey)] = coerceValue(value);
|
|
241
|
+
}
|
|
111
242
|
return metaData;
|
|
112
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Projects a parsed metadata map onto {@link IFileInfo}.
|
|
246
|
+
*
|
|
247
|
+
* Every extracted tag is promoted: known tags via their {@link TAG_ALIASES}
|
|
248
|
+
* friendly field name, all others under their PascalCased tag name. The full
|
|
249
|
+
* unmodified map is always available under `Raw`.
|
|
250
|
+
*/
|
|
251
|
+
toFileInfo(metadata) {
|
|
252
|
+
const fInfo = { FileSize: 0 };
|
|
253
|
+
for (const tag in metadata) {
|
|
254
|
+
const field = TAG_ALIASES[tag] ?? tag[0].toUpperCase() + tag.slice(1);
|
|
255
|
+
fInfo[field] = metadata[tag];
|
|
256
|
+
}
|
|
257
|
+
// set Raw last so a stray `Raw` tag can never clobber the full map
|
|
258
|
+
fInfo.Raw = metadata;
|
|
259
|
+
return fInfo;
|
|
260
|
+
}
|
|
113
261
|
};
|
|
114
262
|
__decorate([
|
|
115
263
|
Logger('fs'),
|
|
116
264
|
__metadata("design:type", Log)
|
|
117
265
|
], DefaultFileInfo.prototype, "Log", void 0);
|
|
266
|
+
__decorate([
|
|
267
|
+
Config('fs.fileInfo.exifToolPath'),
|
|
268
|
+
__metadata("design:type", String)
|
|
269
|
+
], DefaultFileInfo.prototype, "ConfiguredPath", void 0);
|
|
270
|
+
__decorate([
|
|
271
|
+
Config('fs.fileInfo.timeout', { defaultValue: DEFAULT_TIMEOUT }),
|
|
272
|
+
__metadata("design:type", Number)
|
|
273
|
+
], DefaultFileInfo.prototype, "Timeout", void 0);
|
|
274
|
+
__decorate([
|
|
275
|
+
Config('fs.fileInfo.args', { defaultValue: DEFAULT_ARGS }),
|
|
276
|
+
__metadata("design:type", Array)
|
|
277
|
+
], DefaultFileInfo.prototype, "ExifArgs", void 0);
|
|
118
278
|
DefaultFileInfo = __decorate([
|
|
119
279
|
Injectable(FileInfoService)
|
|
120
280
|
], DefaultFileInfo);
|
package/lib/mjs/file-info.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-info.js","sourceRoot":"","sources":["../../src/file-info.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"file-info.js","source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AAqB,EAAE,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC;;gDACtC;AAQjB;IADT,MAAM,CAAC,kBAAkB,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;;iDAC7B;AAvBnB,eAAe;IAD3B,UAAU,CAAC,eAAe,CAAC;GACf,eAAe,CA0L3B"}
|
package/lib/mjs/fp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fs, IFileInfo } from './interfaces.js';
|
|
1
|
+
import { fs, IFileInfo, IStat } from './interfaces.js';
|
|
2
2
|
import { Abortable } from 'events';
|
|
3
3
|
/**
|
|
4
4
|
* Gets filesystem by its name
|
|
@@ -31,7 +31,85 @@ export declare function _fileInfo(path: string): Promise<IFileInfo>;
|
|
|
31
31
|
* @returns
|
|
32
32
|
*/
|
|
33
33
|
export declare function _file_hash(path: string): Promise<string>;
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Checks if a path exists.
|
|
36
|
+
*
|
|
37
|
+
* Without a filesystem, checks an absolute local path directly. With a filesystem
|
|
38
|
+
* ( name or instance ), delegates to that provider ( path relative to its base ).
|
|
39
|
+
*
|
|
40
|
+
* @param path path to check
|
|
41
|
+
* @param fileSystem optional provider name / instance
|
|
42
|
+
*/
|
|
43
|
+
export declare function _exists(path: string, fileSystem?: string | fs): () => Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Reads whole file content through a filesystem provider.
|
|
46
|
+
*
|
|
47
|
+
* @param path path relative to provider base
|
|
48
|
+
* @param encoding optional encoding ( raw Buffer when omitted )
|
|
49
|
+
* @param fileSystem provider name / instance, or default provider
|
|
50
|
+
*/
|
|
51
|
+
export declare function _read(path: string, encoding?: BufferEncoding, fileSystem?: string | fs): Promise<string | Buffer>;
|
|
52
|
+
/**
|
|
53
|
+
* Writes data to a file through a filesystem provider.
|
|
54
|
+
*/
|
|
55
|
+
export declare function _write(path: string, data: string | Uint8Array, encoding?: BufferEncoding, fileSystem?: string | fs): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Appends data to a file through a filesystem provider.
|
|
58
|
+
*/
|
|
59
|
+
export declare function _append(path: string, data: string | Uint8Array, encoding?: BufferEncoding, fileSystem?: string | fs): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Copies a file / dir, optionally into another filesystem.
|
|
62
|
+
*
|
|
63
|
+
* @param src source path ( relative to srcFs )
|
|
64
|
+
* @param dst destination path
|
|
65
|
+
* @param srcFs source provider name / instance ( default provider when omitted )
|
|
66
|
+
* @param dstFs optional destination provider - copy within srcFs when omitted
|
|
67
|
+
*/
|
|
68
|
+
export declare function _copy(src: string, dst: string, srcFs?: string | fs, dstFs?: string | fs): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Moves a file / dir, optionally into another filesystem.
|
|
71
|
+
*/
|
|
72
|
+
export declare function _move(src: string, dst: string, srcFs?: string | fs, dstFs?: string | fs): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Renames a file within a single filesystem.
|
|
75
|
+
*/
|
|
76
|
+
export declare function _rename(oldPath: string, newPath: string, fileSystem?: string | fs): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Removes a file or a directory ( recursively ).
|
|
79
|
+
*/
|
|
80
|
+
export declare function _rm(path: string, fileSystem?: string | fs): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a directory ( recursively ).
|
|
83
|
+
*/
|
|
84
|
+
export declare function _mkdir(path: string, fileSystem?: string | fs): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Lists directory content.
|
|
87
|
+
*/
|
|
88
|
+
export declare function _list(path: string, fileSystem?: string | fs): Promise<string[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Returns file / dir statistics.
|
|
91
|
+
*/
|
|
92
|
+
export declare function _stat(path: string, fileSystem?: string | fs): Promise<IStat>;
|
|
93
|
+
/**
|
|
94
|
+
* Checks if a path is an existing directory.
|
|
95
|
+
*/
|
|
96
|
+
export declare function _dir_exists(path: string, fileSystem?: string | fs): Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Checks if a path is a directory.
|
|
99
|
+
*/
|
|
100
|
+
export declare function _is_dir(path: string, fileSystem?: string | fs): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* Downloads a file to local storage and returns the local path.
|
|
103
|
+
*/
|
|
104
|
+
export declare function _download(path: string, fileSystem?: string | fs): Promise<string>;
|
|
105
|
+
/**
|
|
106
|
+
* Uploads a local file into a filesystem provider.
|
|
107
|
+
*/
|
|
108
|
+
export declare function _upload(srcPath: string, dstPath?: string, fileSystem?: string | fs): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Hashes a file through a filesystem provider.
|
|
111
|
+
*/
|
|
112
|
+
export declare function _hash(path: string, algo?: string, fileSystem?: string | fs): Promise<string>;
|
|
35
113
|
export declare function _is_of_type(path: string, extension: string): () => Promise<void>;
|
|
36
114
|
export declare function _is_of_mimetype(path: string, mimetype: string): () => Promise<void>;
|
|
37
115
|
export declare function _read_file(path: string, options?: ({
|
package/lib/mjs/fp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp.d.ts","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fp.d.ts","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGpF,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AA2BnC;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS,CAUjE;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,EAAE,oB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