@ac-kit/cmd-exiftool 0.0.0-stage → 0.1.1
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/CHANGELOG.md +42 -0
- package/LICENSE +28 -0
- package/README.md +176 -2
- package/dist/_argfile.d.ts +41 -0
- package/dist/_argfile.d.ts.map +1 -0
- package/dist/_argfile.js +99 -0
- package/dist/_argfile.js.map +1 -0
- package/dist/_inspect-file.d.ts +32 -0
- package/dist/_inspect-file.d.ts.map +1 -0
- package/dist/_inspect-file.js +103 -0
- package/dist/_inspect-file.js.map +1 -0
- package/dist/_parse-json-output.d.ts +31 -0
- package/dist/_parse-json-output.d.ts.map +1 -0
- package/dist/_parse-json-output.js +132 -0
- package/dist/_parse-json-output.js.map +1 -0
- package/dist/_print-read-arguments.d.ts +42 -0
- package/dist/_print-read-arguments.d.ts.map +1 -0
- package/dist/_print-read-arguments.js +152 -0
- package/dist/_print-read-arguments.js.map +1 -0
- package/dist/_process-handle.d.ts +7 -0
- package/dist/_process-handle.d.ts.map +1 -0
- package/dist/_process-handle.js +2 -0
- package/dist/_process-handle.js.map +1 -0
- package/dist/_response-reader.d.ts +54 -0
- package/dist/_response-reader.d.ts.map +1 -0
- package/dist/_response-reader.js +129 -0
- package/dist/_response-reader.js.map +1 -0
- package/dist/_worker.d.ts +104 -0
- package/dist/_worker.d.ts.map +1 -0
- package/dist/_worker.js +327 -0
- package/dist/_worker.js.map +1 -0
- package/dist/date-time.d.ts +28 -0
- package/dist/date-time.d.ts.map +1 -0
- package/dist/date-time.js +74 -0
- package/dist/date-time.js.map +1 -0
- package/dist/errors.d.ts +125 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +151 -0
- package/dist/errors.js.map +1 -0
- package/dist/exiftool-pool.d.ts +203 -0
- package/dist/exiftool-pool.d.ts.map +1 -0
- package/dist/exiftool-pool.js +455 -0
- package/dist/exiftool-pool.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata.d.ts +46 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +8 -0
- package/dist/metadata.js.map +1 -0
- package/dist/read-options.d.ts +86 -0
- package/dist/read-options.d.ts.map +1 -0
- package/dist/read-options.js +2 -0
- package/dist/read-options.js.map +1 -0
- package/dist/version.d.ts +39 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +53 -0
- package/dist/version.js.map +1 -0
- package/package.json +61 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @ac-kit/cmd-exiftool
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [065cf8d]
|
|
8
|
+
- Updated dependencies [065cf8d]
|
|
9
|
+
- Updated dependencies [065cf8d]
|
|
10
|
+
- Updated dependencies [065cf8d]
|
|
11
|
+
- Updated dependencies [065cf8d]
|
|
12
|
+
- Updated dependencies [065cf8d]
|
|
13
|
+
- @ac-kit/core@0.11.0
|
|
14
|
+
- @ac-kit/node@0.10.0
|
|
15
|
+
- @ac-kit/data@0.3.3
|
|
16
|
+
|
|
17
|
+
## 0.1.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- 5152230: New package: typed exiftool reads through a pool of `-stay_open` processes. `ExiftoolPool.readMetadata(path, options)` returns `ExiftoolMetadata` (tags keyed as exiftool prints them, `-G1` and machine values `-n` by default, `scalars: "json"` or exact `"text"`), with FIFO queueing over `maxProcesses`, `AbortSignal` and `requestTimeoutMs` cancellation (a running request's process is terminated and replaced), crash isolation, recycling after `maxRequestsPerProcess`, idle closing after `idleTimeoutMs`, and `close()`/`await using`. Processes still alive when Node exits are killed, including one spawned in the same tick; starting and exiting processes count against `maxProcesses`, and a response is checked before its process serves another request. No exiftool configuration file is loaded unless `configFile` names one (`-config ""`). Each file is resolved with `realpath`, inspected inside the request (bounded by `maxProcesses`, timed, cancellable, awaited by `close()`), and exiftool is given that resolved path; a file that is missing, unreadable or not a regular file is refused with `ExiftoolFileError`, and an encrypted PDF, which exiftool would decrypt with the empty password, with `ExiftoolEncryptedDocumentError`. Tag selectors are always sent as `-All:<selector>` and relative paths as `./<path>` so none can become an option (`-` or U+2212); on Windows, paths with `*` or `?` are refused; the returned `SourceFile` must match; arguments are encoded per exiftool's argument-file rules (unrepresentable text is refused), `-api` names are allow-listed (`Password`, `Filter`, `FilterW` refused), and exiftool older than `EXIFTOOL_MINIMUM_VERSION` (12.40) is refused. JSON nested deeper than `EXIFTOOL_MAX_JSON_DEPTH` rejects with `ExiftoolLimitError` (kind `"nesting-depth"`). Also `parseExiftoolDateTime` (to `Temporal`), `parseExiftoolVersion`, and the `Exiftool*Error` classes. Reads only; local files only.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [2a0fe74]
|
|
26
|
+
- Updated dependencies [5152230]
|
|
27
|
+
- Updated dependencies [2a0fe74]
|
|
28
|
+
- Updated dependencies [5152230]
|
|
29
|
+
- Updated dependencies [5152230]
|
|
30
|
+
- Updated dependencies [2a0fe74]
|
|
31
|
+
- Updated dependencies [2a0fe74]
|
|
32
|
+
- Updated dependencies [5152230]
|
|
33
|
+
- Updated dependencies [5152230]
|
|
34
|
+
- Updated dependencies [5152230]
|
|
35
|
+
- Updated dependencies [5152230]
|
|
36
|
+
- Updated dependencies [5152230]
|
|
37
|
+
- Updated dependencies [5152230]
|
|
38
|
+
- Updated dependencies [5152230]
|
|
39
|
+
- Updated dependencies [5152230]
|
|
40
|
+
- @ac-kit/core@0.10.0
|
|
41
|
+
- @ac-kit/node@0.9.0
|
|
42
|
+
- @ac-kit/data@0.3.2
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Anthony Champagne and contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,177 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ac-kit/cmd-exiftool
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reads file metadata through [ExifTool](https://exiftool.org/) — the Perl
|
|
4
|
+
program that knows thousands of tags across JPEG, HEIC, RAW, PDF, video and
|
|
5
|
+
audio formats — as typed JSON, without paying Perl's start-up for every file.
|
|
6
|
+
|
|
7
|
+
`ExiftoolPool` keeps a few `exiftool -stay_open True -@ -` processes running,
|
|
8
|
+
sends each read as one command, matches the answer to the request, and
|
|
9
|
+
cancels, times out, restarts and recycles processes for you. Every argument is
|
|
10
|
+
encoded so a file name or tag selector can never become an exiftool option.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { ExiftoolPool, parseExiftoolDateTime } from "@ac-kit/cmd-exiftool";
|
|
14
|
+
|
|
15
|
+
await using pool = new ExiftoolPool({ maxProcesses: 2 });
|
|
16
|
+
|
|
17
|
+
const photo = await pool.readMetadata("holiday/IMG_0042.jpg", {
|
|
18
|
+
tags: ["EXIF:DateTimeOriginal", "Orientation", "GPS*"],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
photo.tags["IFD0:Orientation"]; // 6 — machine values by default (-n)
|
|
22
|
+
const taken = parseExiftoolDateTime(String(photo.tags["ExifIFD:DateTimeOriginal"]));
|
|
23
|
+
if (taken?.kind === "date-time") {
|
|
24
|
+
console.log(taken.value.toString(), taken.instant?.toString());
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Requires the `exiftool` program, 12.40 or newer, on `PATH` (or `command` and
|
|
29
|
+
`commandArgs` pointing at it); it is not bundled. Node only. `parseExiftoolDateTime`
|
|
30
|
+
needs the `Temporal` global: Node 26 has it, older runtimes load a polyfill
|
|
31
|
+
such as `temporal-polyfill`.
|
|
32
|
+
|
|
33
|
+
See the
|
|
34
|
+
[generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/cmd-exiftool/)
|
|
35
|
+
for the full reference.
|
|
36
|
+
|
|
37
|
+
## Reading
|
|
38
|
+
|
|
39
|
+
`readMetadata(path, options)` returns one `ExiftoolMetadata`:
|
|
40
|
+
|
|
41
|
+
- `sourceFile` — `path` exactly as you passed it.
|
|
42
|
+
- `tags` — every tag keyed as exiftool prints it. The default `groups: [1]`
|
|
43
|
+
gives `IFD0:Make`, `ExifIFD:DateTimeOriginal`, `XMP-dc:Title`; `groups: []`
|
|
44
|
+
gives bare names.
|
|
45
|
+
- `error` and `warning` — exiftool's own `Error` and `Warning` tags, such as
|
|
46
|
+
`"Unknown file type"`.
|
|
47
|
+
- `stderr` — what exiftool printed for this request.
|
|
48
|
+
|
|
49
|
+
Values are machine values (`-n`) unless `printConversion: true`. Scalars are
|
|
50
|
+
typed as exiftool typed them in its JSON (`scalars: "json"`, so `"1.50"` reads
|
|
51
|
+
as `1.5`), or kept as the exact text with `scalars: "text"`, which returns
|
|
52
|
+
`ExiftoolMetadata<string>` and needs exiftool 13.00 or newer (older ones
|
|
53
|
+
reject it with `ExiftoolVersionError`).
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { ExiftoolPool } from "@ac-kit/cmd-exiftool";
|
|
57
|
+
|
|
58
|
+
const pool = new ExiftoolPool();
|
|
59
|
+
const exact = await pool.readMetadata("scan.pdf", { scalars: "text", groups: [0, 1] });
|
|
60
|
+
await pool.close();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`tags`, `excludeTags`, `struct`, `extractEmbedded`, `unknown`, `fast` and an
|
|
64
|
+
allow-list of `-api` options are available; see `ExiftoolReadOptions`.
|
|
65
|
+
|
|
66
|
+
A missing, unreadable or non-regular file (directory, FIFO) rejects with
|
|
67
|
+
`ExiftoolFileError` before exiftool sees it; a file exiftool cannot read
|
|
68
|
+
anyway rejects with `ExiftoolCommandError` (with exiftool's `status` and
|
|
69
|
+
`stderr`); a response over `maxResponseBytes` or nested deeper than
|
|
70
|
+
`EXIFTOOL_MAX_JSON_DEPTH` with `ExiftoolLimitError`, a process that died with
|
|
71
|
+
`ExiftoolProcessError`, an encrypted PDF with `ExiftoolEncryptedDocumentError`. An exiftool that is not
|
|
72
|
+
installed rejects with Node's `ENOENT` error.
|
|
73
|
+
|
|
74
|
+
## Pool behaviour
|
|
75
|
+
|
|
76
|
+
- Nothing starts until the first request. A process answers `-ver` first and
|
|
77
|
+
is refused (`ExiftoolVersionError`) below `EXIFTOOL_MINIMUM_VERSION`.
|
|
78
|
+
- Each process runs one command at a time. Requests go to an idle process,
|
|
79
|
+
then to a new one while fewer than `maxProcesses` are alive (starting and
|
|
80
|
+
exiting ones count), otherwise wait in one FIFO queue.
|
|
81
|
+
- A response is checked before its process takes the next request; a
|
|
82
|
+
process that printed garbage is killed, never reused.
|
|
83
|
+
- `signal` or `requestTimeoutMs` removes a queued request, or terminates the
|
|
84
|
+
process running it; a new one starts when needed.
|
|
85
|
+
- A process that crashes rejects only the request it was running. A process
|
|
86
|
+
is replaced after `maxRequestsPerProcess` commands, and closed after
|
|
87
|
+
`idleTimeoutMs` (default 2 s) without work.
|
|
88
|
+
- Defaults: `maxProcesses` 1, `maxRequestsPerProcess` 1000,
|
|
89
|
+
`requestTimeoutMs` 60 s, `maxResponseBytes` 16 MiB. A request after
|
|
90
|
+
`close()` rejects with `ExiftoolPoolClosedError`; output that breaks the
|
|
91
|
+
protocol (not UTF-8, unexpected JSON shape) rejects with `ExiftoolOutputError`.
|
|
92
|
+
|
|
93
|
+
**Close the pool on shutdown** (`await pool.close()`, `await using`, or from
|
|
94
|
+
`@ac-kit/app-system`'s `watchShutdownSignals`). exiftool never exits when its
|
|
95
|
+
input ends — it keeps polling it — so a process left behind would run
|
|
96
|
+
forever. The pool limits the damage: an idle process keeps Node alive at most
|
|
97
|
+
`idleTimeoutMs`, and if Node exits without `close()` (end of the event loop,
|
|
98
|
+
`process.exit()`, an uncaught exception) the pool kills its processes from one
|
|
99
|
+
shared `process.on("exit")` listener; a process is registered the moment it
|
|
100
|
+
is spawned, so even a `process.exit()` in the same tick kills it. A parent
|
|
101
|
+
killed by `SIGKILL`, or by a signal Node does not handle, still leaves them
|
|
102
|
+
running.
|
|
103
|
+
|
|
104
|
+
## Security
|
|
105
|
+
|
|
106
|
+
The pool is meant for hostile files, such as uploads and downloads.
|
|
107
|
+
|
|
108
|
+
- **Local regular files only, checked and read as one.** exiftool never
|
|
109
|
+
fetches anything: copy remote files to a private temporary file first.
|
|
110
|
+
Each path is resolved the way the kernel does (`realpath`, so
|
|
111
|
+
`link/../x` follows the link), inspected, and exiftool is given that
|
|
112
|
+
resolved absolute path; its `SourceFile` must match it. Anything that
|
|
113
|
+
cannot be resolved, opened or identified as a regular file is refused with
|
|
114
|
+
`ExiftoolFileError` (fail closed). The file must not change between the
|
|
115
|
+
check and exiftool's read, which a private copy guarantees.
|
|
116
|
+
- **Inspection is part of the request.** It starts once the request holds a
|
|
117
|
+
process, so at most `maxProcesses` files are open for it; it counts toward
|
|
118
|
+
`requestTimeoutMs`, stops on cancellation, and `close()` waits for it.
|
|
119
|
+
- **No decryption.** exiftool opens an encrypted PDF with the empty password
|
|
120
|
+
on its own, and no option turns that off. Every PDF (`%PDF-` in the first
|
|
121
|
+
KiB, where exiftool looks) is therefore scanned for the `/Encrypt` trailer
|
|
122
|
+
key, which exiftool matches literally, and refused with
|
|
123
|
+
`ExiftoolEncryptedDocumentError`. The scan reads the whole PDF (linear
|
|
124
|
+
time, one 64 KiB buffer); a `/Encrypt` inside a stream refuses a file that
|
|
125
|
+
is not encrypted, erring on the safe side. `-password` and `-api Password`
|
|
126
|
+
are not offered.
|
|
127
|
+
- **No configuration file.** An exiftool configuration file is Perl code.
|
|
128
|
+
The pool passes `-config ""`, so `.ExifTool_config` in `$HOME`,
|
|
129
|
+
`$EXIFTOOL_HOME` or exiftool's directory is never loaded; `configFile`
|
|
130
|
+
names a trusted one explicitly.
|
|
131
|
+
- **No option injection.** Every tag selector is sent as `-All:<selector>`
|
|
132
|
+
(`All` matches any group), so `delete_original`, `w`, `textout`, `tagout`,
|
|
133
|
+
`o`, `tagsfromfile`, `p`, `r`, `if` or `execute5` stay tag names. Selectors
|
|
134
|
+
must match `(<group>:)*<name>[#]`, where `<name>` may hold `*` and `?`
|
|
135
|
+
wildcards; `=`, `<`, spaces and leading dashes are
|
|
136
|
+
refused. A relative path is always sent as `./<path>`, so a leading `-`
|
|
137
|
+
or U+2212 MINUS SIGN (also an option prefix to exiftool) stays a file
|
|
138
|
+
name. On Windows, where exiftool expands `*` and `?` in file names, such
|
|
139
|
+
paths are refused, as are drive-relative paths (`C:name`). exiftool's
|
|
140
|
+
`SourceFile` must name the file asked for, or the response is refused.
|
|
141
|
+
- **Exact arguments.** Arguments travel through exiftool's argument file:
|
|
142
|
+
plain lines when exiftool takes them verbatim, `#[CSTR]` C-escaped lines
|
|
143
|
+
otherwise (line breaks, leading spaces, a leading `#`). exiftool adds a
|
|
144
|
+
backslash before every `$` and `@` of a `#[CSTR]` line, so text needing both
|
|
145
|
+
is refused (`ExiftoolArgumentError`, reason `"unrepresentable"`); so are NUL
|
|
146
|
+
and lone surrogates. File names are sent with `-charset filename=utf8`.
|
|
147
|
+
- **`-api` allow-list.** Only options that change what a read reports are
|
|
148
|
+
accepted. `Password` is refused, and so are `Filter` and `FilterW` (Perl
|
|
149
|
+
expressions), output options and options that outlive a request.
|
|
150
|
+
- **Forged end markers.** Each command ends with a stderr echo carrying a
|
|
151
|
+
random per-process nonce, so a crafted file name in an error message cannot
|
|
152
|
+
end a response early. `-json` escapes line breaks, so no value can forge the
|
|
153
|
+
stdout `{ready}` marker. Responses are framed on raw bytes with no
|
|
154
|
+
line-length limit, and JSON nesting is checked before parsing.
|
|
155
|
+
- **Version floor.** 12.38 fixed CVE-2022-23935 (command execution through a
|
|
156
|
+
crafted file name); the pool refuses anything older than 12.40.
|
|
157
|
+
- **Read-only.** No write command exists.
|
|
158
|
+
|
|
159
|
+
## Design notes
|
|
160
|
+
|
|
161
|
+
[exiftool-vendored](https://github.com/photostructure/exiftool-vendored.js)
|
|
162
|
+
(MIT) is the established Node wrapper, and it is good. This package exists
|
|
163
|
+
because the trade-offs differ:
|
|
164
|
+
|
|
165
|
+
- It bundles an exiftool copy and a large typed tag catalogue; here the
|
|
166
|
+
program is the system's (or one you point at), and tags stay a record keyed
|
|
167
|
+
as exiftool prints them, which follows exiftool's own documentation and
|
|
168
|
+
every version.
|
|
169
|
+
- The security model here is explicit and tested against the real program:
|
|
170
|
+
every argument is checked against ports of exiftool's own argument-file
|
|
171
|
+
filter, selectors are group-prefixed, `-api` names are allow-listed, and
|
|
172
|
+
only reads exist.
|
|
173
|
+
- It converts dates into its own classes; here `Temporal` values come from
|
|
174
|
+
`parseExiftoolDateTime`, on request.
|
|
175
|
+
- It builds on the `batch-cluster` process-pool library; here the pool is a
|
|
176
|
+
few hundred lines over `@ac-kit/node`'s `startProcess`, with cancellation
|
|
177
|
+
through `AbortSignal` and the lifecycle rules above.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port of the plain branch of exiftool's `FilterArgfileLine` (13.50): what
|
|
3
|
+
* exiftool makes of a line that does not start with `#`.
|
|
4
|
+
*
|
|
5
|
+
* @param line One line, without its terminator.
|
|
6
|
+
* @returns The argument exiftool receives, or `null` when it drops the line.
|
|
7
|
+
*/
|
|
8
|
+
export declare function filterPlainArgfileLine(line: string): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Port of the `#[CSTR]` branch of exiftool's `FilterArgfileLine` (13.50).
|
|
11
|
+
*
|
|
12
|
+
* Unescaped `"`, `$` and `@` gain a backslash before the C escapes are decoded,
|
|
13
|
+
* so a `$` or `@` always reaches exiftool with a backslash in front.
|
|
14
|
+
*
|
|
15
|
+
* @param content The line after the `#[CSTR]` marker.
|
|
16
|
+
* @returns The argument exiftool receives.
|
|
17
|
+
*/
|
|
18
|
+
export declare function filterCstrArgfileLine(content: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Encodes one argument as a line of an exiftool `-@` argument file, so that
|
|
21
|
+
* exiftool receives exactly `argument`.
|
|
22
|
+
*
|
|
23
|
+
* A plain line when exiftool would take it verbatim, otherwise a `#[CSTR]` line
|
|
24
|
+
* with C escapes. O(length).
|
|
25
|
+
*
|
|
26
|
+
* @param argument The argument.
|
|
27
|
+
* @param field Names the setting in an error.
|
|
28
|
+
* @returns The line, without its terminator.
|
|
29
|
+
* @throws {ExiftoolArgumentError} `"invalid-value"` for NUL or a lone
|
|
30
|
+
* surrogate; `"unrepresentable"` when neither form carries the text exactly
|
|
31
|
+
* (a `$` or `@` in an argument that needs the CSTR form).
|
|
32
|
+
*/
|
|
33
|
+
export declare function encodeArgfileLine(argument: string, field: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Encodes already-encoded argument lines as one write.
|
|
36
|
+
*
|
|
37
|
+
* @param lines Lines from {@link encodeArgfileLine} or known-safe constants.
|
|
38
|
+
* @returns The UTF-8 bytes, each line terminated by LF.
|
|
39
|
+
*/
|
|
40
|
+
export declare function encodeArgfileCommand(lines: readonly string[]): Uint8Array<ArrayBuffer>;
|
|
41
|
+
//# sourceMappingURL=_argfile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_argfile.d.ts","sourceRoot":"","sources":["../src/_argfile.ts"],"names":[],"mappings":"AA8BA;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAa7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAqCzE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,SAAS,MAAM,EAAE,GACtB,UAAU,CAAC,WAAW,CAAC,CAEzB"}
|
package/dist/_argfile.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ExiftoolArgumentError } from "./errors.js";
|
|
2
|
+
// Perl's `\s` on exiftool's byte strings: ASCII whitespace only (VT since 5.18).
|
|
3
|
+
const LEADING_WHITESPACE_ = /^[\t\n\v\f\r ]+/;
|
|
4
|
+
const TRAILING_NEWLINES_ = /[\r\n]+$/;
|
|
5
|
+
const TAG_ASSIGNMENT_ = /^(-[-_0-9A-Z:]+#?)[\t\n\v\f\r ]*([-+<]?=) ?/i;
|
|
6
|
+
const CSTR_MARKER_ = "#[CSTR]";
|
|
7
|
+
const CSTR_PROTECT_ = /\\(.)|(["$@]|\\$)/gs;
|
|
8
|
+
const CSTR_UNESCAPE_ = /\\(.)/gs;
|
|
9
|
+
const CSTR_ESCAPES_ = new Map([
|
|
10
|
+
["a", "\u0007"],
|
|
11
|
+
["b", "\b"],
|
|
12
|
+
["f", "\f"],
|
|
13
|
+
["n", "\n"],
|
|
14
|
+
["r", "\r"],
|
|
15
|
+
["t", "\t"],
|
|
16
|
+
['"', '"'],
|
|
17
|
+
["\\", "\\"],
|
|
18
|
+
]);
|
|
19
|
+
const CSTR_ENCODE_ = /[\\\n\r\t"]/g;
|
|
20
|
+
const CSTR_ENCODINGS_ = new Map([
|
|
21
|
+
["\\", "\\\\"],
|
|
22
|
+
["\n", "\\n"],
|
|
23
|
+
["\r", "\\r"],
|
|
24
|
+
["\t", "\\t"],
|
|
25
|
+
['"', '\\"'],
|
|
26
|
+
]);
|
|
27
|
+
const ENCODER_ = new TextEncoder();
|
|
28
|
+
/**
|
|
29
|
+
* Port of the plain branch of exiftool's `FilterArgfileLine` (13.50): what
|
|
30
|
+
* exiftool makes of a line that does not start with `#`.
|
|
31
|
+
*
|
|
32
|
+
* @param line One line, without its terminator.
|
|
33
|
+
* @returns The argument exiftool receives, or `null` when it drops the line.
|
|
34
|
+
*/
|
|
35
|
+
export function filterPlainArgfileLine(line) {
|
|
36
|
+
const argument = line
|
|
37
|
+
.replace(LEADING_WHITESPACE_, "")
|
|
38
|
+
.replace(TRAILING_NEWLINES_, "")
|
|
39
|
+
.replace(TAG_ASSIGNMENT_, "$1$2");
|
|
40
|
+
return argument === "" ? null : argument;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Port of the `#[CSTR]` branch of exiftool's `FilterArgfileLine` (13.50).
|
|
44
|
+
*
|
|
45
|
+
* Unescaped `"`, `$` and `@` gain a backslash before the C escapes are decoded,
|
|
46
|
+
* so a `$` or `@` always reaches exiftool with a backslash in front.
|
|
47
|
+
*
|
|
48
|
+
* @param content The line after the `#[CSTR]` marker.
|
|
49
|
+
* @returns The argument exiftool receives.
|
|
50
|
+
*/
|
|
51
|
+
export function filterCstrArgfileLine(content) {
|
|
52
|
+
return content
|
|
53
|
+
.replace(TRAILING_NEWLINES_, "")
|
|
54
|
+
.replace(CSTR_PROTECT_, (_match, escaped, special) => `\\${special ?? escaped}`)
|
|
55
|
+
.replace(CSTR_UNESCAPE_, (_match, character) => CSTR_ESCAPES_.get(character) ?? `\\${character}`);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Encodes one argument as a line of an exiftool `-@` argument file, so that
|
|
59
|
+
* exiftool receives exactly `argument`.
|
|
60
|
+
*
|
|
61
|
+
* A plain line when exiftool would take it verbatim, otherwise a `#[CSTR]` line
|
|
62
|
+
* with C escapes. O(length).
|
|
63
|
+
*
|
|
64
|
+
* @param argument The argument.
|
|
65
|
+
* @param field Names the setting in an error.
|
|
66
|
+
* @returns The line, without its terminator.
|
|
67
|
+
* @throws {ExiftoolArgumentError} `"invalid-value"` for NUL or a lone
|
|
68
|
+
* surrogate; `"unrepresentable"` when neither form carries the text exactly
|
|
69
|
+
* (a `$` or `@` in an argument that needs the CSTR form).
|
|
70
|
+
*/
|
|
71
|
+
export function encodeArgfileLine(argument, field) {
|
|
72
|
+
if (argument.includes("\0")) {
|
|
73
|
+
throw new ExiftoolArgumentError("invalid-value", field, "contains a NUL character");
|
|
74
|
+
}
|
|
75
|
+
if (!argument.isWellFormed()) {
|
|
76
|
+
throw new ExiftoolArgumentError("invalid-value", field, "contains a lone surrogate");
|
|
77
|
+
}
|
|
78
|
+
if (!argument.includes("\n") &&
|
|
79
|
+
!argument.includes("\r") &&
|
|
80
|
+
!argument.startsWith("#") &&
|
|
81
|
+
filterPlainArgfileLine(argument) === argument) {
|
|
82
|
+
return argument;
|
|
83
|
+
}
|
|
84
|
+
const encoded = argument.replace(CSTR_ENCODE_, (character) => CSTR_ENCODINGS_.get(character));
|
|
85
|
+
if (filterCstrArgfileLine(encoded) === argument) {
|
|
86
|
+
return CSTR_MARKER_ + encoded;
|
|
87
|
+
}
|
|
88
|
+
throw new ExiftoolArgumentError("unrepresentable", field, "exiftool's argument file cannot carry a '$' or '@' in text that also needs escaping (a line break, leading whitespace, a leading '#', or an empty value)");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Encodes already-encoded argument lines as one write.
|
|
92
|
+
*
|
|
93
|
+
* @param lines Lines from {@link encodeArgfileLine} or known-safe constants.
|
|
94
|
+
* @returns The UTF-8 bytes, each line terminated by LF.
|
|
95
|
+
*/
|
|
96
|
+
export function encodeArgfileCommand(lines) {
|
|
97
|
+
return ENCODER_.encode(`${lines.join("\n")}\n`);
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=_argfile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_argfile.js","sourceRoot":"","sources":["../src/_argfile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,iFAAiF;AACjF,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,kBAAkB,GAAG,UAAU,CAAC;AACtC,MAAM,eAAe,GAAG,8CAA8C,CAAC;AACvE,MAAM,YAAY,GAAG,SAAS,CAAC;AAC/B,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,cAAc,GAAG,S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AAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a file the way the file system does and checks it before exiftool
|
|
3
|
+
* reads it. exiftool is then given the returned path, so what was checked is
|
|
4
|
+
* what is read (short of the file changing in between: callers read files they
|
|
5
|
+
* own).
|
|
6
|
+
*
|
|
7
|
+
* - The path is joined to `cwd` without collapsing `..` lexically and resolved
|
|
8
|
+
* with `realpath`, so `link/../x` names the parent of the link's target, as
|
|
9
|
+
* the kernel sees it.
|
|
10
|
+
* - Fails closed: a file that cannot be resolved, opened or identified as a
|
|
11
|
+
* regular file is refused rather than left to exiftool. It is opened
|
|
12
|
+
* non-blocking, so a FIFO swapped in cannot block.
|
|
13
|
+
* - A PDF (`%PDF-` in its first KiB, which is where exiftool looks) is read to
|
|
14
|
+
* the end looking for the trailer key `/Encrypt`; exiftool matches that key
|
|
15
|
+
* literally, so a byte scan finds every file it would decrypt. A `/Encrypt`
|
|
16
|
+
* elsewhere (inside a stream) refuses a file that is not encrypted, which
|
|
17
|
+
* errs on the safe side.
|
|
18
|
+
*
|
|
19
|
+
* Time O(file size) for a PDF, O(1) otherwise; memory one 64 KiB buffer and one
|
|
20
|
+
* file descriptor, closed before returning.
|
|
21
|
+
*
|
|
22
|
+
* @param path The path as the caller gave it.
|
|
23
|
+
* @param cwd Absolute directory a relative `path` is relative to.
|
|
24
|
+
* @param signal Checked between steps and chunks.
|
|
25
|
+
* @returns The resolved absolute path.
|
|
26
|
+
* @throws {ExiftoolFileError} When the file cannot be inspected or is not a
|
|
27
|
+
* regular file.
|
|
28
|
+
* @throws {ExiftoolEncryptedDocumentError} For an encrypted PDF.
|
|
29
|
+
* @throws `signal.reason` when it aborts.
|
|
30
|
+
*/
|
|
31
|
+
export declare function inspectFile(path: string, cwd: string, signal: AbortSignal | null): Promise<string>;
|
|
32
|
+
//# sourceMappingURL=_inspect-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_inspect-file.d.ts","sourceRoot":"","sources":["../src/_inspect-file.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,WAAW,CAChC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,WAAW,GAAG,IAAI,GACxB,OAAO,CAAC,MAAM,CAAC,CA+DjB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { open, realpath } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute, sep } from "node:path";
|
|
4
|
+
import { indexOfSequence } from "@ac-kit/core";
|
|
5
|
+
import { isNodeErrorWithCode } from "@ac-kit/node";
|
|
6
|
+
import { ExiftoolEncryptedDocumentError, ExiftoolFileError } from "./errors.js";
|
|
7
|
+
const PDF_HEADER_ = new TextEncoder().encode("%PDF-");
|
|
8
|
+
const ENCRYPT_KEY_ = new TextEncoder().encode("/Encrypt");
|
|
9
|
+
/** Exiftool recognises a file type from its first 1024 bytes. */
|
|
10
|
+
const HEADER_BYTES_ = 1024;
|
|
11
|
+
const CHUNK_BYTES_ = 64 * 1024;
|
|
12
|
+
/**
|
|
13
|
+
* Resolves a file the way the file system does and checks it before exiftool
|
|
14
|
+
* reads it. exiftool is then given the returned path, so what was checked is
|
|
15
|
+
* what is read (short of the file changing in between: callers read files they
|
|
16
|
+
* own).
|
|
17
|
+
*
|
|
18
|
+
* - The path is joined to `cwd` without collapsing `..` lexically and resolved
|
|
19
|
+
* with `realpath`, so `link/../x` names the parent of the link's target, as
|
|
20
|
+
* the kernel sees it.
|
|
21
|
+
* - Fails closed: a file that cannot be resolved, opened or identified as a
|
|
22
|
+
* regular file is refused rather than left to exiftool. It is opened
|
|
23
|
+
* non-blocking, so a FIFO swapped in cannot block.
|
|
24
|
+
* - A PDF (`%PDF-` in its first KiB, which is where exiftool looks) is read to
|
|
25
|
+
* the end looking for the trailer key `/Encrypt`; exiftool matches that key
|
|
26
|
+
* literally, so a byte scan finds every file it would decrypt. A `/Encrypt`
|
|
27
|
+
* elsewhere (inside a stream) refuses a file that is not encrypted, which
|
|
28
|
+
* errs on the safe side.
|
|
29
|
+
*
|
|
30
|
+
* Time O(file size) for a PDF, O(1) otherwise; memory one 64 KiB buffer and one
|
|
31
|
+
* file descriptor, closed before returning.
|
|
32
|
+
*
|
|
33
|
+
* @param path The path as the caller gave it.
|
|
34
|
+
* @param cwd Absolute directory a relative `path` is relative to.
|
|
35
|
+
* @param signal Checked between steps and chunks.
|
|
36
|
+
* @returns The resolved absolute path.
|
|
37
|
+
* @throws {ExiftoolFileError} When the file cannot be inspected or is not a
|
|
38
|
+
* regular file.
|
|
39
|
+
* @throws {ExiftoolEncryptedDocumentError} For an encrypted PDF.
|
|
40
|
+
* @throws `signal.reason` when it aborts.
|
|
41
|
+
*/
|
|
42
|
+
export async function inspectFile(path, cwd, signal) {
|
|
43
|
+
const joined = isAbsolute(path)
|
|
44
|
+
? path
|
|
45
|
+
: `${cwd}${cwd.endsWith(sep) ? "" : sep}${path}`;
|
|
46
|
+
let resolved;
|
|
47
|
+
try {
|
|
48
|
+
resolved = await realpath(joined);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw fileError_(error, path);
|
|
52
|
+
}
|
|
53
|
+
signal?.throwIfAborted();
|
|
54
|
+
let file;
|
|
55
|
+
try {
|
|
56
|
+
file = await open(resolved, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw fileError_(error, path);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
if (!(await file.stat()).isFile()) {
|
|
63
|
+
throw new ExiftoolFileError("not-a-file", path);
|
|
64
|
+
}
|
|
65
|
+
const buffer = new Uint8Array(CHUNK_BYTES_);
|
|
66
|
+
const header = await file.read(buffer, 0, HEADER_BYTES_, 0);
|
|
67
|
+
if (indexOfSequence(buffer.subarray(0, header.bytesRead), PDF_HEADER_) === -1) {
|
|
68
|
+
return resolved;
|
|
69
|
+
}
|
|
70
|
+
// Each chunk starts with the last bytes of the previous one, so a key
|
|
71
|
+
// split across two reads is still found.
|
|
72
|
+
const overlap = ENCRYPT_KEY_.length - 1;
|
|
73
|
+
let carried = 0;
|
|
74
|
+
let position = 0;
|
|
75
|
+
for (;;) {
|
|
76
|
+
signal?.throwIfAborted();
|
|
77
|
+
const { bytesRead } = await file.read(buffer, carried, buffer.length - carried, position);
|
|
78
|
+
if (bytesRead === 0) {
|
|
79
|
+
return resolved;
|
|
80
|
+
}
|
|
81
|
+
const filled = carried + bytesRead;
|
|
82
|
+
if (indexOfSequence(buffer.subarray(0, filled), ENCRYPT_KEY_) !== -1) {
|
|
83
|
+
throw new ExiftoolEncryptedDocumentError(path);
|
|
84
|
+
}
|
|
85
|
+
position += bytesRead;
|
|
86
|
+
carried = Math.min(overlap, filled);
|
|
87
|
+
buffer.copyWithin(0, filled - carried, filled);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
await file.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function fileError_(error, path) {
|
|
95
|
+
const reason = isNodeErrorWithCode(error, "ENOENT") ||
|
|
96
|
+
isNodeErrorWithCode(error, "ENOTDIR")
|
|
97
|
+
? "not-found"
|
|
98
|
+
: isNodeErrorWithCode(error, "EISDIR")
|
|
99
|
+
? "not-a-file"
|
|
100
|
+
: "not-readable";
|
|
101
|
+
return new ExiftoolFileError(reason, path, { cause: error });
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=_inspect-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_inspect-file.js","sourceRoot":"","sources":["../src/_inspect-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,O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E,MAAM,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBACtE,MAAM,IAAI,8BAA8B,CAAC,IAAI,CAAC,CAAC;YAChD,CAAC;YACD,QAAQ,IAAI,SAAS,CAAC;YACtB,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACpC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC;QAChD,CAAC;IACF,CAAC;YAAS,CAAC;QACV,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;AACF,CAAC;AAED,SAAS,UAAU,CAAC,KAAc,EAAE,IAAY;IAC/C,MAAM,MAAM,GACX,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC;QACpC,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC;QACpC,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC;YACrC,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,cAAc,CAAC;IACpB,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ExiftoolValue } from "./metadata.js";
|
|
2
|
+
import type { ExiftoolGroupFamily } from "./read-options.js";
|
|
3
|
+
/** One `-json` entry, `SourceFile` checked to be a string. */
|
|
4
|
+
export type JsonEntry = {
|
|
5
|
+
readonly SourceFile: string;
|
|
6
|
+
} & Readonly<Record<string, ExiftoolValue>>;
|
|
7
|
+
/**
|
|
8
|
+
* Parses the stdout of one `-json` command.
|
|
9
|
+
*
|
|
10
|
+
* @param body The bytes before the `{ready}` marker.
|
|
11
|
+
* @param scalars `"text"` turns every number and boolean left by exiftool into
|
|
12
|
+
* its source text.
|
|
13
|
+
* @returns The entries, `[]` for empty output. O(body length).
|
|
14
|
+
* @throws {ExiftoolLimitError} Kind `"nesting-depth"` when arrays and objects
|
|
15
|
+
* nest deeper than {@link EXIFTOOL_MAX_JSON_DEPTH}: `JSON.parse` revives
|
|
16
|
+
* recursively, so the depth is checked first.
|
|
17
|
+
* @throws {ExiftoolOutputError} When the bytes are not UTF-8, not JSON, or not
|
|
18
|
+
* an array of objects with a string `SourceFile`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseJsonOutput(body: Uint8Array, scalars: "json" | "text"): JsonEntry[];
|
|
21
|
+
/**
|
|
22
|
+
* Finds exiftool's own `Error` or `Warning` tag among an entry's keys.
|
|
23
|
+
*
|
|
24
|
+
* The key ends in `:<name>` (or is `<name>` with no groups). When the families
|
|
25
|
+
* include 0, 1 or 2, one of its groups must be `ExifTool`, which is what those
|
|
26
|
+
* families call exiftool's own tags; otherwise the first match is taken.
|
|
27
|
+
*
|
|
28
|
+
* @returns The value as text, or `null`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function findExiftoolMessage(tags: Readonly<Record<string, ExiftoolValue<unknown>>>, name: "Error" | "Warning", groups: readonly ExiftoolGroupFamily[]): string | null;
|
|
31
|
+
//# sourceMappingURL=_parse-json-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_parse-json-output.d.ts","sourceRoot":"","sources":["../src/_parse-json-output.ts"],"names":[],"mappings":"AAUA,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,8DAA8D;AAC9D,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,QAAQ,CACjE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAC7B,CAAC;AA6BF;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,GACtB,SAAS,EAAE,CAqDb;AAuCD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EACtD,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,MAAM,EAAE,SAAS,mBAAmB,EAAE,GACpC,MAAM,GAAG,IAAI,CAef"}
|