@spinajs/fs 2.0.480 → 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.
Files changed (211) hide show
  1. package/lib/cjs/cli/cat.d.ts +11 -0
  2. package/lib/cjs/cli/cat.d.ts.map +1 -0
  3. package/lib/cjs/cli/cat.js +40 -0
  4. package/lib/cjs/cli/cat.js.map +1 -0
  5. package/lib/cjs/cli/cp.d.ts +11 -0
  6. package/lib/cjs/cli/cp.d.ts.map +1 -0
  7. package/lib/cjs/cli/cp.js +41 -0
  8. package/lib/cjs/cli/cp.js.map +1 -0
  9. package/lib/cjs/cli/download.d.ts +7 -0
  10. package/lib/cjs/cli/download.d.ts.map +1 -0
  11. package/lib/cjs/cli/download.js +39 -0
  12. package/lib/cjs/cli/download.js.map +1 -0
  13. package/lib/cjs/cli/exists.d.ts +7 -0
  14. package/lib/cjs/cli/exists.d.ts.map +1 -0
  15. package/lib/cjs/cli/exists.js +39 -0
  16. package/lib/cjs/cli/exists.js.map +1 -0
  17. package/lib/cjs/cli/fs.d.ts +11 -0
  18. package/lib/cjs/cli/fs.d.ts.map +1 -1
  19. package/lib/cjs/cli/fs.js +47 -21
  20. package/lib/cjs/cli/fs.js.map +1 -1
  21. package/lib/cjs/cli/hash.d.ts +11 -0
  22. package/lib/cjs/cli/hash.d.ts.map +1 -0
  23. package/lib/cjs/cli/hash.js +40 -0
  24. package/lib/cjs/cli/hash.js.map +1 -0
  25. package/lib/cjs/cli/info.d.ts +7 -0
  26. package/lib/cjs/cli/info.d.ts.map +1 -0
  27. package/lib/cjs/cli/info.js +45 -0
  28. package/lib/cjs/cli/info.js.map +1 -0
  29. package/lib/cjs/cli/ls.d.ts +7 -0
  30. package/lib/cjs/cli/ls.d.ts.map +1 -0
  31. package/lib/cjs/cli/ls.js +40 -0
  32. package/lib/cjs/cli/ls.js.map +1 -0
  33. package/lib/cjs/cli/mkdir.d.ts +7 -0
  34. package/lib/cjs/cli/mkdir.d.ts.map +1 -0
  35. package/lib/cjs/cli/mkdir.js +39 -0
  36. package/lib/cjs/cli/mkdir.js.map +1 -0
  37. package/lib/cjs/cli/mv.d.ts +11 -0
  38. package/lib/cjs/cli/mv.d.ts.map +1 -0
  39. package/lib/cjs/cli/mv.js +41 -0
  40. package/lib/cjs/cli/mv.js.map +1 -0
  41. package/lib/cjs/cli/rm.d.ts +1 -6
  42. package/lib/cjs/cli/rm.d.ts.map +1 -1
  43. package/lib/cjs/cli/rm.js +14 -4
  44. package/lib/cjs/cli/rm.js.map +1 -1
  45. package/lib/cjs/cli/stat.d.ts +1 -5
  46. package/lib/cjs/cli/stat.d.ts.map +1 -1
  47. package/lib/cjs/cli/stat.js +20 -3
  48. package/lib/cjs/cli/stat.js.map +1 -1
  49. package/lib/cjs/cli/unzip.d.ts +11 -0
  50. package/lib/cjs/cli/unzip.d.ts.map +1 -0
  51. package/lib/cjs/cli/unzip.js +47 -0
  52. package/lib/cjs/cli/unzip.js.map +1 -0
  53. package/lib/cjs/cli/upload.d.ts +7 -0
  54. package/lib/cjs/cli/upload.d.ts.map +1 -0
  55. package/lib/cjs/cli/upload.js +40 -0
  56. package/lib/cjs/cli/upload.js.map +1 -0
  57. package/lib/cjs/cli/write.d.ts +13 -0
  58. package/lib/cjs/cli/write.d.ts.map +1 -0
  59. package/lib/cjs/cli/write.js +54 -0
  60. package/lib/cjs/cli/write.js.map +1 -0
  61. package/lib/cjs/cli/zip.d.ts +12 -0
  62. package/lib/cjs/cli/zip.d.ts.map +1 -0
  63. package/lib/cjs/cli/zip.js +51 -0
  64. package/lib/cjs/cli/zip.js.map +1 -0
  65. package/lib/cjs/config/fs.d.ts +9 -0
  66. package/lib/cjs/config/fs.d.ts.map +1 -0
  67. package/lib/cjs/config/fs.js +22 -0
  68. package/lib/cjs/config/fs.js.map +1 -0
  69. package/lib/cjs/file-hasher.d.ts +85 -5
  70. package/lib/cjs/file-hasher.d.ts.map +1 -1
  71. package/lib/cjs/file-hasher.js +106 -14
  72. package/lib/cjs/file-hasher.js.map +1 -1
  73. package/lib/cjs/file-info.d.ts +94 -5
  74. package/lib/cjs/file-info.d.ts.map +1 -1
  75. package/lib/cjs/file-info.js +267 -73
  76. package/lib/cjs/file-info.js.map +1 -1
  77. package/lib/cjs/fp.d.ts +80 -2
  78. package/lib/cjs/fp.d.ts.map +1 -1
  79. package/lib/cjs/fp.js +149 -3
  80. package/lib/cjs/fp.js.map +1 -1
  81. package/lib/cjs/index.d.ts +2 -1
  82. package/lib/cjs/index.d.ts.map +1 -1
  83. package/lib/cjs/index.js +7 -2
  84. package/lib/cjs/index.js.map +1 -1
  85. package/lib/cjs/interfaces.d.ts +89 -12
  86. package/lib/cjs/interfaces.d.ts.map +1 -1
  87. package/lib/cjs/interfaces.js +13 -13
  88. package/lib/cjs/interfaces.js.map +1 -1
  89. package/lib/cjs/local-provider.d.ts +51 -6
  90. package/lib/cjs/local-provider.d.ts.map +1 -1
  91. package/lib/cjs/local-provider.js +254 -76
  92. package/lib/cjs/local-provider.js.map +1 -1
  93. package/lib/cjs/temp-cleanup-strategy.d.ts +70 -0
  94. package/lib/cjs/temp-cleanup-strategy.d.ts.map +1 -0
  95. package/lib/cjs/temp-cleanup-strategy.js +157 -0
  96. package/lib/cjs/temp-cleanup-strategy.js.map +1 -0
  97. package/lib/cjs/temp-provider.d.ts +59 -0
  98. package/lib/cjs/temp-provider.d.ts.map +1 -0
  99. package/lib/cjs/temp-provider.js +150 -0
  100. package/lib/cjs/temp-provider.js.map +1 -0
  101. package/lib/mjs/cli/cat.d.ts +11 -0
  102. package/lib/mjs/cli/cat.d.ts.map +1 -0
  103. package/lib/mjs/cli/cat.js +37 -0
  104. package/lib/mjs/cli/cat.js.map +1 -0
  105. package/lib/mjs/cli/cp.d.ts +11 -0
  106. package/lib/mjs/cli/cp.d.ts.map +1 -0
  107. package/lib/mjs/cli/cp.js +38 -0
  108. package/lib/mjs/cli/cp.js.map +1 -0
  109. package/lib/mjs/cli/download.d.ts +7 -0
  110. package/lib/mjs/cli/download.d.ts.map +1 -0
  111. package/lib/mjs/cli/download.js +36 -0
  112. package/lib/mjs/cli/download.js.map +1 -0
  113. package/lib/mjs/cli/exists.d.ts +7 -0
  114. package/lib/mjs/cli/exists.d.ts.map +1 -0
  115. package/lib/mjs/cli/exists.js +36 -0
  116. package/lib/mjs/cli/exists.js.map +1 -0
  117. package/lib/mjs/cli/fs.d.ts +11 -1
  118. package/lib/mjs/cli/fs.d.ts.map +1 -1
  119. package/lib/mjs/cli/fs.js +43 -22
  120. package/lib/mjs/cli/fs.js.map +1 -1
  121. package/lib/mjs/cli/hash.d.ts +11 -0
  122. package/lib/mjs/cli/hash.d.ts.map +1 -0
  123. package/lib/mjs/cli/hash.js +37 -0
  124. package/lib/mjs/cli/hash.js.map +1 -0
  125. package/lib/mjs/cli/info.d.ts +7 -0
  126. package/lib/mjs/cli/info.d.ts.map +1 -0
  127. package/lib/mjs/cli/info.js +42 -0
  128. package/lib/mjs/cli/info.js.map +1 -0
  129. package/lib/mjs/cli/ls.d.ts +7 -0
  130. package/lib/mjs/cli/ls.d.ts.map +1 -0
  131. package/lib/mjs/cli/ls.js +37 -0
  132. package/lib/mjs/cli/ls.js.map +1 -0
  133. package/lib/mjs/cli/mkdir.d.ts +7 -0
  134. package/lib/mjs/cli/mkdir.d.ts.map +1 -0
  135. package/lib/mjs/cli/mkdir.js +36 -0
  136. package/lib/mjs/cli/mkdir.js.map +1 -0
  137. package/lib/mjs/cli/mv.d.ts +11 -0
  138. package/lib/mjs/cli/mv.d.ts.map +1 -0
  139. package/lib/mjs/cli/mv.js +38 -0
  140. package/lib/mjs/cli/mv.js.map +1 -0
  141. package/lib/mjs/cli/rm.d.ts +1 -6
  142. package/lib/mjs/cli/rm.d.ts.map +1 -1
  143. package/lib/mjs/cli/rm.js +15 -5
  144. package/lib/mjs/cli/rm.js.map +1 -1
  145. package/lib/mjs/cli/stat.d.ts +1 -5
  146. package/lib/mjs/cli/stat.d.ts.map +1 -1
  147. package/lib/mjs/cli/stat.js +21 -4
  148. package/lib/mjs/cli/stat.js.map +1 -1
  149. package/lib/mjs/cli/unzip.d.ts +11 -0
  150. package/lib/mjs/cli/unzip.d.ts.map +1 -0
  151. package/lib/mjs/cli/unzip.js +44 -0
  152. package/lib/mjs/cli/unzip.js.map +1 -0
  153. package/lib/mjs/cli/upload.d.ts +7 -0
  154. package/lib/mjs/cli/upload.d.ts.map +1 -0
  155. package/lib/mjs/cli/upload.js +37 -0
  156. package/lib/mjs/cli/upload.js.map +1 -0
  157. package/lib/mjs/cli/write.d.ts +13 -0
  158. package/lib/mjs/cli/write.d.ts.map +1 -0
  159. package/lib/mjs/cli/write.js +51 -0
  160. package/lib/mjs/cli/write.js.map +1 -0
  161. package/lib/mjs/cli/zip.d.ts +12 -0
  162. package/lib/mjs/cli/zip.d.ts.map +1 -0
  163. package/lib/mjs/cli/zip.js +48 -0
  164. package/lib/mjs/cli/zip.js.map +1 -0
  165. package/lib/mjs/config/fs.d.ts +9 -0
  166. package/lib/mjs/config/fs.d.ts.map +1 -0
  167. package/lib/mjs/config/fs.js +20 -0
  168. package/lib/mjs/config/fs.js.map +1 -0
  169. package/lib/mjs/file-hasher.d.ts +85 -5
  170. package/lib/mjs/file-hasher.d.ts.map +1 -1
  171. package/lib/mjs/file-hasher.js +106 -14
  172. package/lib/mjs/file-hasher.js.map +1 -1
  173. package/lib/mjs/file-info.d.ts +94 -5
  174. package/lib/mjs/file-info.d.ts.map +1 -1
  175. package/lib/mjs/file-info.js +233 -73
  176. package/lib/mjs/file-info.js.map +1 -1
  177. package/lib/mjs/fp.d.ts +80 -2
  178. package/lib/mjs/fp.d.ts.map +1 -1
  179. package/lib/mjs/fp.js +135 -4
  180. package/lib/mjs/fp.js.map +1 -1
  181. package/lib/mjs/index.d.ts +2 -1
  182. package/lib/mjs/index.d.ts.map +1 -1
  183. package/lib/mjs/index.js +8 -3
  184. package/lib/mjs/index.js.map +1 -1
  185. package/lib/mjs/interfaces.d.ts +89 -12
  186. package/lib/mjs/interfaces.d.ts.map +1 -1
  187. package/lib/mjs/interfaces.js +13 -13
  188. package/lib/mjs/interfaces.js.map +1 -1
  189. package/lib/mjs/local-provider.d.ts +51 -6
  190. package/lib/mjs/local-provider.d.ts.map +1 -1
  191. package/lib/mjs/local-provider.js +257 -79
  192. package/lib/mjs/local-provider.js.map +1 -1
  193. package/lib/mjs/temp-cleanup-strategy.d.ts +70 -0
  194. package/lib/mjs/temp-cleanup-strategy.d.ts.map +1 -0
  195. package/lib/mjs/temp-cleanup-strategy.js +153 -0
  196. package/lib/mjs/temp-cleanup-strategy.js.map +1 -0
  197. package/lib/mjs/temp-provider.d.ts +59 -0
  198. package/lib/mjs/temp-provider.d.ts.map +1 -0
  199. package/lib/mjs/temp-provider.js +147 -0
  200. package/lib/mjs/temp-provider.js.map +1 -0
  201. package/lib/tsconfig.cjs.tsbuildinfo +1 -1
  202. package/lib/tsconfig.mjs.tsbuildinfo +1 -1
  203. package/package.json +11 -6
  204. package/lib/cjs/local-temp-provider.d.ts +0 -18
  205. package/lib/cjs/local-temp-provider.d.ts.map +0 -1
  206. package/lib/cjs/local-temp-provider.js +0 -63
  207. package/lib/cjs/local-temp-provider.js.map +0 -1
  208. package/lib/mjs/local-temp-provider.d.ts +0 -18
  209. package/lib/mjs/local-temp-provider.d.ts.map +0 -1
  210. package/lib/mjs/local-temp-provider.js +0 -60
  211. package/lib/mjs/local-temp-provider.js.map +0 -1
@@ -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]?.alghoritm ?? 'sha256';
26
- return this.Alghoritm === requestedAlgo;
52
+ const requestedAlgo = creationOptions?.[0] ?? this.ConfiguredAlgorithm;
53
+ return this.Algorithm === requestedAlgo;
27
54
  }
28
- constructor(Alghoritm, HashOptions) {
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.Alghoritm = Alghoritm;
64
+ this.Algorithm = Algorithm;
31
65
  this.HashOptions = HashOptions;
32
- this.Alghoritm = this.Alghoritm || 'sha256';
66
+ this.Algorithm = this.Algorithm || this.ConfiguredAlgorithm;
33
67
  }
34
- async hash(pathToFile) {
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
- if (!this.Alghoritm) {
39
- throw new exceptions_1.IOFail(`Hashing algorithm is not specified for file hasher. Please provide algorithm as constructor parameter or set default algorithm in configuration`);
40
- }
41
- const algo = crypto_1.default.createHash(this.Alghoritm, this.HashOptions);
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
- node_fs_1.default.createReadStream(pathToFile)
44
- .on('data', (data) => algo.update(data))
45
- .on('end', () => resolve(algo.digest('hex')))
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,oDAA4B;AAC5B,sDAAyB;AACzB,oDA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C,KAAK;QACrF,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACnC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,UAAU,CAAC,MAA6B,EAAE,WAAiC,KAAK;QAC3F,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,mBAAM,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC,CAAC;IACrG,CAAC;CACF,CAAA;AA9HY,8CAAiB;AASlB;IADT,IAAA,sBAAM,EAAC,4BAA4B,EAAE,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;;8DACnC;4BAT5B,iBAAiB;IAF7B,IAAA,eAAU,EAAC,0BAAU,CAAC;IACtB,IAAA,qBAAgB,GAAE;;GACN,iBAAiB,CA8H7B"}
@@ -1,11 +1,100 @@
1
- import { Log } from '@spinajs/log';
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
- protected spawnExifProcess(file: string): Promise<string>;
7
- protected getMetadata(file: string): Promise<{
8
- [key: string]: string | number;
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":"AAGA,OAAO,EAAE,GAAG,EAAU,MAAM,cAAc,CAAC;AAG3C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA4C7D,qBACa,eAAgB,SAAQ,eAAe;IAElD,SAAS,CAAC,GAAG,EAAG,GAAG,CAAC;IAEP,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;cAsB5C,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAa/C,WAAW,CAAC,IAAI,EAAE,MAAM;;;CAsCzC"}
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,O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