@ac-kit/cmd-exiftool 0.0.0-stage → 0.1.0

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 (60) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +28 -0
  3. package/README.md +176 -2
  4. package/dist/_argfile.d.ts +41 -0
  5. package/dist/_argfile.d.ts.map +1 -0
  6. package/dist/_argfile.js +99 -0
  7. package/dist/_argfile.js.map +1 -0
  8. package/dist/_inspect-file.d.ts +32 -0
  9. package/dist/_inspect-file.d.ts.map +1 -0
  10. package/dist/_inspect-file.js +103 -0
  11. package/dist/_inspect-file.js.map +1 -0
  12. package/dist/_parse-json-output.d.ts +31 -0
  13. package/dist/_parse-json-output.d.ts.map +1 -0
  14. package/dist/_parse-json-output.js +132 -0
  15. package/dist/_parse-json-output.js.map +1 -0
  16. package/dist/_print-read-arguments.d.ts +42 -0
  17. package/dist/_print-read-arguments.d.ts.map +1 -0
  18. package/dist/_print-read-arguments.js +152 -0
  19. package/dist/_print-read-arguments.js.map +1 -0
  20. package/dist/_process-handle.d.ts +7 -0
  21. package/dist/_process-handle.d.ts.map +1 -0
  22. package/dist/_process-handle.js +2 -0
  23. package/dist/_process-handle.js.map +1 -0
  24. package/dist/_response-reader.d.ts +54 -0
  25. package/dist/_response-reader.d.ts.map +1 -0
  26. package/dist/_response-reader.js +129 -0
  27. package/dist/_response-reader.js.map +1 -0
  28. package/dist/_worker.d.ts +104 -0
  29. package/dist/_worker.d.ts.map +1 -0
  30. package/dist/_worker.js +327 -0
  31. package/dist/_worker.js.map +1 -0
  32. package/dist/date-time.d.ts +28 -0
  33. package/dist/date-time.d.ts.map +1 -0
  34. package/dist/date-time.js +74 -0
  35. package/dist/date-time.js.map +1 -0
  36. package/dist/errors.d.ts +125 -0
  37. package/dist/errors.d.ts.map +1 -0
  38. package/dist/errors.js +151 -0
  39. package/dist/errors.js.map +1 -0
  40. package/dist/exiftool-pool.d.ts +203 -0
  41. package/dist/exiftool-pool.d.ts.map +1 -0
  42. package/dist/exiftool-pool.js +455 -0
  43. package/dist/exiftool-pool.js.map +1 -0
  44. package/dist/index.d.ts +7 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +7 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/metadata.d.ts +46 -0
  49. package/dist/metadata.d.ts.map +1 -0
  50. package/dist/metadata.js +8 -0
  51. package/dist/metadata.js.map +1 -0
  52. package/dist/read-options.d.ts +86 -0
  53. package/dist/read-options.d.ts.map +1 -0
  54. package/dist/read-options.js +2 -0
  55. package/dist/read-options.js.map +1 -0
  56. package/dist/version.d.ts +39 -0
  57. package/dist/version.d.ts.map +1 -0
  58. package/dist/version.js +53 -0
  59. package/dist/version.js.map +1 -0
  60. package/package.json +61 -3
@@ -0,0 +1,125 @@
1
+ import type { ProcessExit } from "@ac-kit/node";
2
+ import type { ExiftoolVersion } from "./version.js";
3
+ /** Why {@link ExiftoolArgumentError} refused a request. */
4
+ export type ExiftoolArgumentReason =
5
+ /**
6
+ * A tag selector, group family or `-api` name outside what this package
7
+ * accepts.
8
+ */
9
+ "invalid-name"
10
+ /** A value that cannot be passed: empty path, NUL, lone surrogate. */
11
+ | "invalid-value"
12
+ /** Text exiftool's argument file cannot carry exactly (see the README). */
13
+ | "unrepresentable";
14
+ /**
15
+ * A request refused before anything is sent to exiftool.
16
+ *
17
+ * `field` names the setting at fault, such as `path`, `tags[2]` or
18
+ * `api[0].name`.
19
+ */
20
+ export declare class ExiftoolArgumentError extends TypeError {
21
+ readonly reason: ExiftoolArgumentReason;
22
+ readonly field: string;
23
+ constructor(reason: ExiftoolArgumentReason, field: string, message: string, options?: ErrorOptions);
24
+ }
25
+ /**
26
+ * Exiftool ran the command but produced no entry for the file, or more than
27
+ * one: a missing file, a path it could not read.
28
+ */
29
+ export declare class ExiftoolCommandError extends Error {
30
+ readonly status: number;
31
+ readonly stderr: string;
32
+ /**
33
+ * @param status Exiftool's exit status for the command (0, 1 or 2).
34
+ * @param stderr What exiftool printed to stderr for the command, capped at
35
+ * the pool's `maxStderrBytes`.
36
+ */
37
+ constructor(status: number, stderr: string, message?: string, options?: ErrorOptions);
38
+ }
39
+ /**
40
+ * The exiftool process failed: it exited during the request, its pipes broke,
41
+ * or it could not be started for a reason other than a spawn error. The
42
+ * underlying error, when there is one, is the `cause`.
43
+ */
44
+ export declare class ExiftoolProcessError extends Error {
45
+ readonly exit: ProcessExit | null;
46
+ readonly stderr: string;
47
+ /**
48
+ * @param exit How the process ended, `null` when it had not exited yet.
49
+ * @param stderr What the process printed to stderr for the request.
50
+ */
51
+ constructor(exit: ProcessExit | null, stderr: string, message?: string, options?: ErrorOptions);
52
+ }
53
+ /**
54
+ * Exiftool's output was not what the protocol promises: not UTF-8, not the
55
+ * expected JSON shape, or an end marker for another request. The process that
56
+ * produced it is killed.
57
+ */
58
+ export declare class ExiftoolOutputError extends SyntaxError {
59
+ constructor(message: string, options?: ErrorOptions);
60
+ }
61
+ /** Which bound {@link ExiftoolLimitError} reports. */
62
+ export type ExiftoolLimitKind =
63
+ /** Stdout of one request over the pool's `maxResponseBytes`. */
64
+ "response-bytes"
65
+ /** JSON arrays and objects nested deeper than `EXIFTOOL_MAX_JSON_DEPTH`. */
66
+ | "nesting-depth";
67
+ /** A response exceeded a bound. The response was discarded and the process kept. */
68
+ export declare class ExiftoolLimitError extends RangeError {
69
+ readonly kind: ExiftoolLimitKind;
70
+ readonly limit: number;
71
+ readonly received: number;
72
+ /**
73
+ * @param kind Which bound.
74
+ * @param limit The bound in force (bytes, or nesting levels).
75
+ * @param received What the response had (bytes, or the first level past the
76
+ * bound).
77
+ */
78
+ constructor(kind: ExiftoolLimitKind, limit: number, received: number, options?: ErrorOptions);
79
+ }
80
+ /** Why {@link ExiftoolFileError} refused a file. */
81
+ export type ExiftoolFileErrorReason =
82
+ /** Nothing at that path (or a path component is not a directory). */
83
+ "not-found"
84
+ /** The file exists but could not be opened (permissions and the like). */
85
+ | "not-readable"
86
+ /** A directory, FIFO, device or socket rather than a regular file. */
87
+ | "not-a-file";
88
+ /**
89
+ * The file could not be checked before reading, so it was not read: the pool
90
+ * only hands exiftool regular files it has inspected. The system error, when
91
+ * there is one, is the `cause`.
92
+ */
93
+ export declare class ExiftoolFileError extends Error {
94
+ readonly reason: ExiftoolFileErrorReason;
95
+ readonly path: string;
96
+ /**
97
+ * @param reason Why.
98
+ * @param path The path as the caller gave it.
99
+ */
100
+ constructor(reason: ExiftoolFileErrorReason, path: string, options?: ErrorOptions);
101
+ }
102
+ /**
103
+ * The file is an encrypted PDF. exiftool decrypts such a file with the empty
104
+ * password before reading it, and this package never decrypts anything, so the
105
+ * request is refused before exiftool sees the file.
106
+ */
107
+ export declare class ExiftoolEncryptedDocumentError extends Error {
108
+ readonly path: string;
109
+ /** @param path The path as the caller gave it. */
110
+ constructor(path: string, options?: ErrorOptions);
111
+ }
112
+ /**
113
+ * The exiftool program is older than `EXIFTOOL_MINIMUM_VERSION`, or than
114
+ * `EXIFTOOL_TEXT_SCALARS_VERSION` for a read with `scalars: "text"`.
115
+ */
116
+ export declare class ExiftoolVersionError extends Error {
117
+ readonly version: ExiftoolVersion;
118
+ readonly minimum: ExiftoolVersion;
119
+ constructor(version: ExiftoolVersion, minimum: ExiftoolVersion, options?: ErrorOptions);
120
+ }
121
+ /** The pool was closed before the request could run. */
122
+ export declare class ExiftoolPoolClosedError extends Error {
123
+ constructor(message?: string, options?: ErrorOptions);
124
+ }
125
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,2DAA2D;AAC3D,MAAM,MAAM,sBAAsB;AACjC;;;GAGG;AACD,cAAc;AAChB,sEAAsE;GACpE,e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T1B;;;;;OAKG;IACH,YACU,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EACzB,OAAO,CAAC,EAAE,YAAY,EAUtB;CACD;AAED,oDAAoD;AACpD,MAAM,MAAM,uBAAuB;AAClC,qEAAqE;AACnE,WAAW;AACb,0EAA0E;GACxE,cAAc;AAChB,sEAAsE;GACpE,YAAY,CAAC;AAEhB;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAM1C,QAAQ,CAAC,MAAM,EAAE,uBAAuB;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM;IANtB;;;OAGG;IACH,YACU,MAAM,EAAE,uBAAuB,EAC/B,IAAI,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,YAAY,EAKtB;CACD;AAED;;;;GAIG;AACH,qBAAa,8BAA+B,SAAQ,KAAK;IAGvD,QAAQ,CAAC,IAAI,EAAE,MAAM;IAFtB,kDAAkD;IAClD,YACU,IAAI,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,YAAY,EAQtB;CACD;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAE7C,QAAQ,CAAC,OAAO,EAAE,eAAe;IACjC,QAAQ,CAAC,OAAO,EAAE,eAAe;IAFlC,YACU,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,eAAe,EACjC,OAAO,CAAC,EAAE,YAAY,EAQtB;CACD;AAED,wDAAwD;AACxD,qBAAa,uBAAwB,SAAQ,KAAK;IACjD,YAAY,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAInD;CACD"}
package/dist/errors.js ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * A request refused before anything is sent to exiftool.
3
+ *
4
+ * `field` names the setting at fault, such as `path`, `tags[2]` or
5
+ * `api[0].name`.
6
+ */
7
+ export class ExiftoolArgumentError extends TypeError {
8
+ reason;
9
+ field;
10
+ constructor(reason, field, message, options) {
11
+ super(`${field}: ${message}`, options);
12
+ this.reason = reason;
13
+ this.field = field;
14
+ this.name = "ExiftoolArgumentError";
15
+ }
16
+ }
17
+ /**
18
+ * Exiftool ran the command but produced no entry for the file, or more than
19
+ * one: a missing file, a path it could not read.
20
+ */
21
+ export class ExiftoolCommandError extends Error {
22
+ status;
23
+ stderr;
24
+ /**
25
+ * @param status Exiftool's exit status for the command (0, 1 or 2).
26
+ * @param stderr What exiftool printed to stderr for the command, capped at
27
+ * the pool's `maxStderrBytes`.
28
+ */
29
+ constructor(status, stderr, message, options) {
30
+ super(message ??
31
+ `exiftool failed with status ${status}${stderr.trim() === "" ? "" : `: ${stderr.trim()}`}`, options);
32
+ this.status = status;
33
+ this.stderr = stderr;
34
+ this.name = "ExiftoolCommandError";
35
+ }
36
+ }
37
+ /**
38
+ * The exiftool process failed: it exited during the request, its pipes broke,
39
+ * or it could not be started for a reason other than a spawn error. The
40
+ * underlying error, when there is one, is the `cause`.
41
+ */
42
+ export class ExiftoolProcessError extends Error {
43
+ exit;
44
+ stderr;
45
+ /**
46
+ * @param exit How the process ended, `null` when it had not exited yet.
47
+ * @param stderr What the process printed to stderr for the request.
48
+ */
49
+ constructor(exit, stderr, message, options) {
50
+ super(message ?? describeExit_(exit), options);
51
+ this.exit = exit;
52
+ this.stderr = stderr;
53
+ this.name = "ExiftoolProcessError";
54
+ }
55
+ }
56
+ /**
57
+ * Exiftool's output was not what the protocol promises: not UTF-8, not the
58
+ * expected JSON shape, or an end marker for another request. The process that
59
+ * produced it is killed.
60
+ */
61
+ export class ExiftoolOutputError extends SyntaxError {
62
+ constructor(message, options) {
63
+ super(message, options);
64
+ this.name = "ExiftoolOutputError";
65
+ }
66
+ }
67
+ /** A response exceeded a bound. The response was discarded and the process kept. */
68
+ export class ExiftoolLimitError extends RangeError {
69
+ kind;
70
+ limit;
71
+ received;
72
+ /**
73
+ * @param kind Which bound.
74
+ * @param limit The bound in force (bytes, or nesting levels).
75
+ * @param received What the response had (bytes, or the first level past the
76
+ * bound).
77
+ */
78
+ constructor(kind, limit, received, options) {
79
+ super(kind === "response-bytes"
80
+ ? `exiftool response of ${received} bytes exceeds the limit of ${limit} bytes`
81
+ : `exiftool response nests JSON deeper than ${limit} levels`, options);
82
+ this.kind = kind;
83
+ this.limit = limit;
84
+ this.received = received;
85
+ this.name = "ExiftoolLimitError";
86
+ }
87
+ }
88
+ /**
89
+ * The file could not be checked before reading, so it was not read: the pool
90
+ * only hands exiftool regular files it has inspected. The system error, when
91
+ * there is one, is the `cause`.
92
+ */
93
+ export class ExiftoolFileError extends Error {
94
+ reason;
95
+ path;
96
+ /**
97
+ * @param reason Why.
98
+ * @param path The path as the caller gave it.
99
+ */
100
+ constructor(reason, path, options) {
101
+ super(`${path}: ${reason.replaceAll("-", " ")}`, options);
102
+ this.reason = reason;
103
+ this.path = path;
104
+ this.name = "ExiftoolFileError";
105
+ }
106
+ }
107
+ /**
108
+ * The file is an encrypted PDF. exiftool decrypts such a file with the empty
109
+ * password before reading it, and this package never decrypts anything, so the
110
+ * request is refused before exiftool sees the file.
111
+ */
112
+ export class ExiftoolEncryptedDocumentError extends Error {
113
+ path;
114
+ /** @param path The path as the caller gave it. */
115
+ constructor(path, options) {
116
+ super(`${path}: encrypted PDF refused (exiftool would decrypt it)`, options);
117
+ this.path = path;
118
+ this.name = "ExiftoolEncryptedDocumentError";
119
+ }
120
+ }
121
+ /**
122
+ * The exiftool program is older than `EXIFTOOL_MINIMUM_VERSION`, or than
123
+ * `EXIFTOOL_TEXT_SCALARS_VERSION` for a read with `scalars: "text"`.
124
+ */
125
+ export class ExiftoolVersionError extends Error {
126
+ version;
127
+ minimum;
128
+ constructor(version, minimum, options) {
129
+ super(`exiftool ${version.text} is older than the supported minimum ${minimum.text}`, options);
130
+ this.version = version;
131
+ this.minimum = minimum;
132
+ this.name = "ExiftoolVersionError";
133
+ }
134
+ }
135
+ /** The pool was closed before the request could run. */
136
+ export class ExiftoolPoolClosedError extends Error {
137
+ constructor(message, options) {
138
+ super(message ?? "The exiftool pool is closed", options);
139
+ this.name = "ExiftoolPoolClosedError";
140
+ }
141
+ }
142
+ function describeExit_(exit) {
143
+ if (exit === null) {
144
+ return "The exiftool process failed";
145
+ }
146
+ if (exit.signal !== null) {
147
+ return `The exiftool process was killed by ${exit.signal}`;
148
+ }
149
+ return `The exiftool process exited with code ${exit.code}`;
150
+ }
151
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAEzC,MAAM;IACN,KAAK;IAFf,YACU,MAA8B,EAC9B,KAAa,EACtB,OAAe,EACf,OAAsB;QAEtB,KAAK,CAAC,GAAG,KAAK,KAAK,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;sBAL9B,MAAM;qBACN,KAAK;QAMd,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACrC,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAOpC,MAAM;IACN,MAAM;IAPhB;;;;OAIG;IACH,YACU,MAAc,EACd,MAAc,EACvB,OAAgB,EAChB,OAAsB;QAEtB,KAAK,CACJ,OAAO;YACN,+BAA+B,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,EAC3F,OAAO,CACP,CAAC;sBATO,MAAM;sBACN,MAAM;QAUf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACpC,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAMpC,IAAI;IACJ,MAAM;IANhB;;;OAGG;IACH,YACU,IAAwB,EACxB,MAAc,EACvB,OAAgB,EAChB,OAAsB;QAEtB,KAAK,CAAC,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GAAG,IAAI,qDAAqD,EAC5D,OAAO,CACP,CAAC;oBANO,IAAI;QAQb,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC9C,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAEpC,OAAO;IACP,OAAO;IAFjB,YACU,OAAwB,EACxB,OAAwB,EACjC,OAAsB;QAEtB,KAAK,CACJ,YAAY,OAAO,CAAC,IAAI,wCAAwC,OAAO,CAAC,IAAI,EAAE,EAC9E,OAAO,CACP,CAAC;uBAPO,OAAO;uBACP,OAAO;QAQhB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACpC,CAAC;CACD;AAED,wDAAwD;AACxD,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACjD,YAAY,OAAgB,EAAE,OAAsB;QACnD,KAAK,CAAC,OAAO,IAAI,6BAA6B,EAAE,OAAO,CAAC,CAAC;QAEzD,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;AAED,SAAS,aAAa,CAAC,IAAwB;IAC9C,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,6BAA6B,CAAC;IACtC,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO,sCAAsC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5D,CAAC;IACD,OAAO,yCAAyC,IAAI,CAAC,IAAI,EAAE,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,203 @@
1
+ import type { ExiftoolMetadata } from "./metadata.js";
2
+ import type { ExiftoolReadOptions } from "./read-options.js";
3
+ import { type ExiftoolVersion } from "./version.js";
4
+ /** How an {@link ExiftoolPool} starts and bounds its processes. */
5
+ export type ExiftoolPoolOptions = {
6
+ /** The program. Default `"exiftool"`, found through `PATH`. */
7
+ readonly command?: string | null;
8
+ /**
9
+ * Arguments before exiftool's own, such as
10
+ * `["/opt/Image-ExifTool-12.40/exiftool"]` with `command: "perl"`.
11
+ */
12
+ readonly commandArgs?: readonly string[] | null;
13
+ /**
14
+ * A trusted exiftool configuration file (`-config <file>`, user-defined
15
+ * tags). A configuration file is Perl code exiftool runs, so none is loaded
16
+ * by default: the pool passes `-config ""`, which also stops exiftool from
17
+ * loading `.ExifTool_config` from `$EXIFTOOL_HOME`, `$HOME` or its own
18
+ * directory.
19
+ */
20
+ readonly configFile?: string | null;
21
+ /** Working directory of every process; relative paths resolve against it. */
22
+ readonly cwd?: string | null;
23
+ /** Environment of every process. Default: this process's. */
24
+ readonly env?: NodeJS.ProcessEnv | null;
25
+ /** Processes running at once; an integer ≥ 1. Default 1. */
26
+ readonly maxProcesses?: number | null;
27
+ /**
28
+ * Commands a process runs before it is closed and replaced, bounding what a
29
+ * long-lived Perl process accumulates. An integer ≥ 1 or `Infinity`. Default 1000.
30
+ */
31
+ readonly maxRequestsPerProcess?: number | null;
32
+ /**
33
+ * Time a request may run once it has a process (queue time excluded),
34
+ * starting one included. Milliseconds ≥ 0; `Infinity` disables it. Default 60 000.
35
+ */
36
+ readonly requestTimeoutMs?: number | null;
37
+ /**
38
+ * Stdout bytes kept per request; a larger response rejects with
39
+ * {@link ExiftoolLimitError}. Default 16 MiB.
40
+ */
41
+ readonly maxResponseBytes?: number | null;
42
+ /** Stderr bytes kept per request; the rest is dropped. Default 64 KiB. */
43
+ readonly maxStderrBytes?: number | null;
44
+ /**
45
+ * Time a closing process gets to exit after `-stay_open False` (and after
46
+ * SIGTERM) before it is killed; an integer from 0 to 2 147 483 647 (what a
47
+ * single timer can wait). Default 5000.
48
+ */
49
+ readonly shutdownGraceMs?: number | null;
50
+ /**
51
+ * Time an idle process is kept before it is closed. An idle process keeps
52
+ * Node's event loop alive, so this bounds how long a program that never calls
53
+ * `close()` waits before it can exit. Default 2000; `Infinity` keeps
54
+ * processes until `close()`.
55
+ */
56
+ readonly idleTimeoutMs?: number | null;
57
+ };
58
+ /**
59
+ * A pool of `exiftool -stay_open True -@ -` processes, reading metadata as
60
+ * typed JSON without paying Perl's start-up for every file.
61
+ *
62
+ * - Nothing is spawned until the first request. A process answers `-ver` first
63
+ * and is refused below `EXIFTOOL_MINIMUM_VERSION`. No exiftool configuration
64
+ * file is loaded unless `configFile` names one.
65
+ * - Each process runs one command at a time; requests go to an idle process, then
66
+ * to a new one while fewer than `maxProcesses` are alive (starting, busy,
67
+ * idle or still exiting), otherwise into one FIFO queue. Memory: O(queued
68
+ * requests) plus at most `maxResponseBytes` and `maxStderrBytes` per running
69
+ * request.
70
+ * - A request's file is resolved and inspected once the request holds a process,
71
+ * so at most `maxProcesses` files are open for inspection, and inspection
72
+ * counts toward `requestTimeoutMs`, stops on cancellation and is awaited by
73
+ * `close()`.
74
+ * - A response is checked before its process takes the next request; a process
75
+ * that answered garbage is killed, never reused.
76
+ * - A process that exits during a request rejects that request with
77
+ * `ExiftoolProcessError`, without retry (the file may be what kills it);
78
+ * queued requests are unaffected and a fresh process starts for the next. A
79
+ * spawn failure rejects only the request that triggered it.
80
+ * - A process is replaced after `maxRequestsPerProcess` commands, and closed
81
+ * after `idleTimeoutMs` without work.
82
+ * - Exiftool never exits on end of input, so the pool kills its processes
83
+ * (SIGKILL) if Node exits without `close()`, through one shared
84
+ * `process.on("exit")` listener present only while a process lives; a process
85
+ * is registered the moment it is spawned. A parent killed outright (SIGKILL,
86
+ * or a signal Node does not handle) still leaves them running: call `close()`
87
+ * on shutdown, for instance from `@ac-kit/app-system`'s
88
+ * `watchShutdownSignals`.
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * await using pool = new ExiftoolPool({ maxProcesses: 2 });
93
+ * const { tags } = await pool.readMetadata("photo.jpg", {
94
+ * tags: ["EXIF:DateTimeOriginal", "Orientation"],
95
+ * });
96
+ * ```;
97
+ */
98
+ export declare class ExiftoolPool implements AsyncDisposable {
99
+ private readonly config;
100
+ private readonly maxProcesses;
101
+ private readonly maxRequestsPerProcess;
102
+ private readonly requestTimeoutMs;
103
+ private readonly idleTimeoutMs;
104
+ private readonly queue;
105
+ /** Started and in service, busy or idle. */
106
+ private readonly workers;
107
+ private readonly idle;
108
+ private readonly idleTimers;
109
+ /** Every started process that has not exited yet, retiring ones included. */
110
+ private readonly alive;
111
+ /** Requests holding or acquiring a process. */
112
+ private readonly active;
113
+ private starting;
114
+ private closing;
115
+ private readonly drained;
116
+ /**
117
+ * @param options See {@link ExiftoolPoolOptions}.
118
+ * @throws {RangeError} For a count that is not a positive integer (or
119
+ * `Infinity` where allowed), or a duration outside its range.
120
+ */
121
+ constructor(options?: ExiftoolPoolOptions);
122
+ /** Whether {@link close} has been called. */
123
+ get closed(): boolean;
124
+ /**
125
+ * Reads one file's metadata.
126
+ *
127
+ * @param path A local file; relative paths resolve against the pool's `cwd`.
128
+ * Remote files must be copied locally first.
129
+ * @param options What to read; see {@link ExiftoolReadOptions}.
130
+ * @returns The entry exiftool produced for `path`, with `sourceFile` set to
131
+ * `path` as given.
132
+ * @throws {ExiftoolArgumentError} An invalid selector, group family or `-api`
133
+ * name; an empty path, a directory, NUL, a lone surrogate, a path the
134
+ * argument file cannot carry, or (on Windows) a path with `*` or `?`.
135
+ * @throws {ExiftoolEncryptedDocumentError} The file is an encrypted PDF,
136
+ * which exiftool would decrypt.
137
+ * @throws {ExiftoolCommandError} Exiftool produced no entry, or more than one
138
+ * (a missing or unreadable file). Carries `status` and `stderr`.
139
+ * @throws {ExiftoolLimitError} Stdout over `maxResponseBytes`, or JSON nested
140
+ * deeper than `EXIFTOOL_MAX_JSON_DEPTH`. The process is kept.
141
+ * @throws {ExiftoolOutputError} Stdout was not the expected JSON, its
142
+ * `SourceFile` was not the file asked for, or an end marker carried the
143
+ * wrong id. The process is killed.
144
+ * @throws {ExiftoolProcessError} The process exited during the request.
145
+ * @throws {ExiftoolVersionError} A new process is older than the minimum, or
146
+ * older than `EXIFTOOL_TEXT_SCALARS_VERSION` with `scalars: "text"`.
147
+ * @throws {ExiftoolPoolClosedError} The pool was closed before the request
148
+ * ran.
149
+ * @throws `signal.reason` on abort, or a `DOMException` named
150
+ * `"TimeoutError"` after `requestTimeoutMs`. A queued request is removed; a
151
+ * running one has its process terminated in the background and replaced on
152
+ * demand.
153
+ * @throws What spawning throws, such as an `ENOENT` error when the program is
154
+ * not installed.
155
+ */
156
+ readMetadata(path: string, options: ExiftoolReadOptions & {
157
+ readonly scalars: "text";
158
+ }): Promise<ExiftoolMetadata<string>>;
159
+ readMetadata(path: string, options?: ExiftoolReadOptions): Promise<ExiftoolMetadata>;
160
+ /**
161
+ * The version of the program, starting a process if none is running.
162
+ *
163
+ * @param signal Aborts the wait (and a process being started for it).
164
+ * @throws As {@link readMetadata} does for spawning and closing.
165
+ */
166
+ getVersion(signal?: AbortSignal | null): Promise<ExiftoolVersion>;
167
+ /**
168
+ * Closes the pool. Idempotent.
169
+ *
170
+ * - Queued requests reject with {@link ExiftoolPoolClosedError}.
171
+ * - Running requests, and requests waiting for a new process, finish unless
172
+ * `signal` aborts, which rejects them with its reason and terminates their
173
+ * processes.
174
+ * - Each process is sent `-stay_open False` and given `shutdownGraceMs` to
175
+ * exit, then terminated.
176
+ *
177
+ * @returns Resolves once every process has exited; never rejects.
178
+ */
179
+ close(signal?: AbortSignal | null): Promise<void>;
180
+ [Symbol.asyncDispose](): Promise<void>;
181
+ private submit;
182
+ private dispatch;
183
+ private armTimeout;
184
+ private startFor;
185
+ private assign;
186
+ /** Interprets a response, then hands the process back or retires it. */
187
+ private finish;
188
+ private release;
189
+ /**
190
+ * Takes a process out of service, gracefully or by terminating it. It still
191
+ * counts against `maxProcesses` until it has exited.
192
+ */
193
+ private retire;
194
+ private onWorkerExited;
195
+ private cancelRequest;
196
+ /** Rejects a request that has not settled yet. */
197
+ private settle;
198
+ /** Resolves a request that has not settled yet. */
199
+ private fulfil;
200
+ private markSettled;
201
+ private checkDrained;
202
+ }
203
+ //# sourceMappingURL=exiftool-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exiftool-pool.d.ts","sourceRoot":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