@spinajs/fs 2.0.481 → 2.0.484
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 +12 -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/cjs/file-hasher.js
CHANGED
|
@@ -14,40 +14,132 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.DefaultFileHasher = void 0;
|
|
16
16
|
const di_1 = require("@spinajs/di");
|
|
17
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
17
18
|
const crypto_1 = __importDefault(require("crypto"));
|
|
18
19
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
19
20
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
20
21
|
const interfaces_js_1 = require("./interfaces.js");
|
|
22
|
+
/**
|
|
23
|
+
* Hard fallback algorithm used when nothing is provided and no config default is set.
|
|
24
|
+
*/
|
|
25
|
+
const DEFAULT_ALGORITHM = 'sha256';
|
|
26
|
+
/**
|
|
27
|
+
* Default {@link FileHasher} implementation backed by node's `crypto` module.
|
|
28
|
+
*
|
|
29
|
+
* The algorithm is fixed per instance and provided as the first constructor
|
|
30
|
+
* argument ( eg. `DI.resolve(FileHasher, ['md5'])` ). When no algorithm is
|
|
31
|
+
* given it falls back to the value configured under `fs.hasher.defaultAlgorithm`,
|
|
32
|
+
* and finally to {@link DEFAULT_ALGORITHM} ( sha256 ).
|
|
33
|
+
*
|
|
34
|
+
* Instances are cached per algorithm via {@link PerInstanceCheck} /
|
|
35
|
+
* {@link __checkInstance__}, so resolving the same algorithm twice reuses the
|
|
36
|
+
* same hasher while different algorithms get distinct instances.
|
|
37
|
+
*/
|
|
21
38
|
let DefaultFileHasher = class DefaultFileHasher extends interfaces_js_1.FileHasher {
|
|
39
|
+
/**
|
|
40
|
+
* Per-instance cache predicate used by {@link PerInstanceCheck}.
|
|
41
|
+
*
|
|
42
|
+
* Returns `true` when this instance was created for the algorithm requested in
|
|
43
|
+
* `creationOptions`. The requested algorithm is resolved exactly like the
|
|
44
|
+
* constructor does ( explicit arg, else the configured default ), so cached
|
|
45
|
+
* instances match reliably.
|
|
46
|
+
*
|
|
47
|
+
* @param creationOptions constructor arguments the container is resolving with
|
|
48
|
+
*/
|
|
22
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
50
|
__checkInstance__(creationOptions) {
|
|
24
51
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
25
|
-
const requestedAlgo = creationOptions?.[0]
|
|
26
|
-
return this.
|
|
52
|
+
const requestedAlgo = creationOptions?.[0] ?? this.ConfiguredAlgorithm;
|
|
53
|
+
return this.Algorithm === requestedAlgo;
|
|
27
54
|
}
|
|
28
|
-
|
|
55
|
+
/**
|
|
56
|
+
* @param Algorithm hash algorithm to use ( eg. `sha256`, `md5` ). When omitted,
|
|
57
|
+
* the configured default ( `fs.hasher.defaultAlgorithm` ) or
|
|
58
|
+
* sha256 is used.
|
|
59
|
+
* @param HashOptions optional node `crypto` hash options ( eg. `outputLength`
|
|
60
|
+
* for XOF algorithms such as shake256 )
|
|
61
|
+
*/
|
|
62
|
+
constructor(Algorithm, HashOptions) {
|
|
29
63
|
super();
|
|
30
|
-
this.
|
|
64
|
+
this.Algorithm = Algorithm;
|
|
31
65
|
this.HashOptions = HashOptions;
|
|
32
|
-
this.
|
|
66
|
+
this.Algorithm = this.Algorithm || this.ConfiguredAlgorithm;
|
|
33
67
|
}
|
|
34
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Creates a `crypto.Hash` for the configured algorithm.
|
|
70
|
+
*
|
|
71
|
+
* The algorithm is validated against the platform's supported hashes first so
|
|
72
|
+
* an unsupported/typo'd algorithm produces a clear {@link IOFail} instead of a
|
|
73
|
+
* cryptic native crypto error.
|
|
74
|
+
*
|
|
75
|
+
* @throws {IOFail} when the configured algorithm is not supported
|
|
76
|
+
*/
|
|
77
|
+
createHasher() {
|
|
78
|
+
const algo = this.Algorithm;
|
|
79
|
+
if (!crypto_1.default.getHashes().includes(algo)) {
|
|
80
|
+
throw new exceptions_1.IOFail(`Unsupported hash algorithm '${algo}'. Use one of: ${crypto_1.default.getHashes().join(', ')}`);
|
|
81
|
+
}
|
|
82
|
+
return crypto_1.default.createHash(algo, this.HashOptions);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Hashes the content of a file by streaming it through the hash.
|
|
86
|
+
*
|
|
87
|
+
* @param pathToFile absolute path to the file to hash
|
|
88
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
89
|
+
* @returns the digest string in the requested encoding
|
|
90
|
+
* @throws {IOFail} when the file does not exist, the algorithm is unsupported,
|
|
91
|
+
* or the file cannot be read
|
|
92
|
+
*/
|
|
93
|
+
async hash(pathToFile, encoding = 'hex') {
|
|
35
94
|
if (!node_fs_1.default.existsSync(pathToFile)) {
|
|
36
95
|
throw new exceptions_1.IOFail(`File ${pathToFile} not exists`);
|
|
37
96
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
97
|
+
return this.digestStream(node_fs_1.default.createReadStream(pathToFile), encoding, (err) => new exceptions_1.IOFail(`Cannot read file ${pathToFile} for hashing`, err));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Consumes a readable stream through a fresh hasher and resolves with the
|
|
101
|
+
* digest. Stream errors are wrapped by `wrapError` so file and raw-stream
|
|
102
|
+
* callers surface their own context.
|
|
103
|
+
*/
|
|
104
|
+
digestStream(stream, encoding, wrapError) {
|
|
105
|
+
const hasher = this.createHasher();
|
|
42
106
|
return new Promise((resolve, reject) => {
|
|
43
|
-
|
|
44
|
-
.on('data', (data) =>
|
|
45
|
-
.on('end', () => resolve(
|
|
46
|
-
.on('error', (err) => reject(err));
|
|
107
|
+
stream
|
|
108
|
+
.on('data', (data) => hasher.update(data))
|
|
109
|
+
.on('end', () => resolve(hasher.digest(encoding)))
|
|
110
|
+
.on('error', (err) => reject(wrapError(err)));
|
|
47
111
|
});
|
|
48
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Hashes raw in-memory data.
|
|
115
|
+
*
|
|
116
|
+
* @param data string or binary data to hash
|
|
117
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
118
|
+
* @returns the digest string in the requested encoding
|
|
119
|
+
* @throws {IOFail} when the configured algorithm is unsupported
|
|
120
|
+
*/
|
|
121
|
+
async hashData(data, encoding = 'hex') {
|
|
122
|
+
const hasher = this.createHasher();
|
|
123
|
+
hasher.update(data);
|
|
124
|
+
return hasher.digest(encoding);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Hashes the content of a readable stream by consuming it to the end.
|
|
128
|
+
*
|
|
129
|
+
* @param stream readable stream to consume
|
|
130
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
131
|
+
* @returns the digest string in the requested encoding
|
|
132
|
+
* @throws {IOFail} when the configured algorithm is unsupported or the stream errors
|
|
133
|
+
*/
|
|
134
|
+
async hashStream(stream, encoding = 'hex') {
|
|
135
|
+
return this.digestStream(stream, encoding, (err) => new exceptions_1.IOFail(`Error while hashing stream`, err));
|
|
136
|
+
}
|
|
49
137
|
};
|
|
50
138
|
exports.DefaultFileHasher = DefaultFileHasher;
|
|
139
|
+
__decorate([
|
|
140
|
+
(0, configuration_1.Config)('fs.hasher.defaultAlgorithm', { defaultValue: DEFAULT_ALGORITHM }),
|
|
141
|
+
__metadata("design:type", String)
|
|
142
|
+
], DefaultFileHasher.prototype, "ConfiguredAlgorithm", void 0);
|
|
51
143
|
exports.DefaultFileHasher = DefaultFileHasher = __decorate([
|
|
52
144
|
(0, di_1.Injectable)(interfaces_js_1.FileHasher),
|
|
53
145
|
(0, di_1.PerInstanceCheck)(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-hasher.js","sourceRoot":"","sources":["../../src/file-hasher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oCAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"file-hasher.js","sourceRoot":"","sources":["../../src/file-hasher.ts"],"names":[],"mappings":"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"}
|
package/lib/cjs/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-info.d.ts","sourceRoot":"","sources":["../../src/file-info.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AAI3E,OAAO,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAcjC;;GAEG;AACH,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAmF5C;;;;;;GAMG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAa3D;AAED;;;;;;;GAOG;AACH,qBACa,eAAgB,SAAQ,eAAe;IAElD,SAAS,CAAC,GAAG,EAAG,GAAG,CAAC;IAEpB;;;OAGG;IAEH,SAAS,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAElC;;OAEG;IAEH,SAAS,CAAC,OAAO,EAAG,MAAM,CAAC;IAE3B;;;;OAIG;IAEH,SAAS,CAAC,QAAQ,EAAG,MAAM,EAAE,CAAC;IAE9B;;OAEG;IACH,SAAS,CAAC,YAAY,EAAG,MAAM,CAAC;IAEhC;;;;;OAKG;IACU,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAS5D;;;;;;OAMG;IACU,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC;IAKjF;;OAEG;cACa,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAa7C;;OAEG;IACH,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,8BAA8B;IAInF;;;;;;;;;;OAUG;cACa,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IA8C5F;;;;;;;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"}
|