exifreader 4.39.1 → 4.40.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.
- package/README.md +324 -166
- package/bin/profile-diff.js +171 -0
- package/bin/profile.js +852 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +53 -10
- package/package.json +7 -7
- package/src/exif-reader.js +36 -142
- package/src/file-loaders.js +308 -0
- package/src/image-header-avif.js +7 -4
- package/src/image-header-gif.js +21 -1
- package/src/image-header-heic.js +7 -4
- package/src/image-header-iso-bmff.js +169 -18
- package/src/image-header-jpeg.js +53 -1
- package/src/image-header-jxl.js +63 -12
- package/src/image-header-png.js +51 -5
- package/src/image-header-webp.js +32 -2
- package/src/image-header.js +32 -12
- package/src/load-auto.js +310 -0
- package/src/loadview-pipeline.js +66 -1
- package/src/xml.js +39 -1
package/exif-reader.d.ts
CHANGED
|
@@ -237,6 +237,37 @@ export interface ExpandedTags {
|
|
|
237
237
|
photoshop?: PhotoshopTags;
|
|
238
238
|
makerNotes?: CanonTags & PentaxTags;
|
|
239
239
|
composite?: CompositeTags;
|
|
240
|
+
metadataRange?: MetadataRange;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export type MetadataBlockType =
|
|
244
|
+
| 'exif'
|
|
245
|
+
| 'iptc'
|
|
246
|
+
| 'xmp'
|
|
247
|
+
| 'icc'
|
|
248
|
+
| 'mpf'
|
|
249
|
+
| 'mpfImage'
|
|
250
|
+
| 'jfif'
|
|
251
|
+
| 'file'
|
|
252
|
+
| 'png'
|
|
253
|
+
| 'riff'
|
|
254
|
+
| 'gif';
|
|
255
|
+
|
|
256
|
+
export interface MetadataBlock {
|
|
257
|
+
type: MetadataBlockType,
|
|
258
|
+
start: number,
|
|
259
|
+
end: number,
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface MetadataRange {
|
|
263
|
+
start: number,
|
|
264
|
+
end: number,
|
|
265
|
+
complete: boolean,
|
|
266
|
+
blocks: MetadataBlock[],
|
|
267
|
+
// Only present when length: 'auto' was used:
|
|
268
|
+
buffer?: ArrayBuffer | SharedArrayBuffer | Buffer,
|
|
269
|
+
fetched?: number,
|
|
270
|
+
requests?: number,
|
|
240
271
|
}
|
|
241
272
|
|
|
242
273
|
interface GpsTags {
|
|
@@ -387,19 +418,31 @@ type CommonOptions = {
|
|
|
387
418
|
decompress?: DecompressOptions,
|
|
388
419
|
};
|
|
389
420
|
|
|
421
|
+
type ExpandedOnly = {expanded: true, includeOffsets?: boolean};
|
|
422
|
+
type FlatOnly = {expanded?: false, includeOffsets?: false};
|
|
423
|
+
|
|
424
|
+
type AutoLengthOptions = {
|
|
425
|
+
length: 'auto',
|
|
426
|
+
expanded: true,
|
|
427
|
+
includeOffsets: true,
|
|
428
|
+
async?: boolean,
|
|
429
|
+
};
|
|
430
|
+
|
|
390
431
|
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer): Tags;
|
|
391
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions &
|
|
392
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions &
|
|
393
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions &
|
|
394
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions &
|
|
432
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & AutoLengthOptions): Promise<ExpandedTags>;
|
|
433
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & ExpandedOnly & {length?: number, async?: false}): ExpandedTags;
|
|
434
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & FlatOnly & {length?: number, async?: false}): Tags;
|
|
435
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & ExpandedOnly & {length?: number, async: true}): Promise<ExpandedTags>;
|
|
436
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & FlatOnly & {length?: number, async: true}): Promise<Tags>;
|
|
395
437
|
export function load(data: string | File): Promise<Tags>;
|
|
396
|
-
export function load(data: string | File, options: CommonOptions &
|
|
397
|
-
export function load(data: string | File, options: CommonOptions &
|
|
438
|
+
export function load(data: string | File, options: CommonOptions & AutoLengthOptions): Promise<ExpandedTags>;
|
|
439
|
+
export function load(data: string | File, options: CommonOptions & ExpandedOnly & {length?: number, async?: boolean }): Promise<ExpandedTags>;
|
|
440
|
+
export function load(data: string | File, options: CommonOptions & FlatOnly & {length?: number, async?: boolean }): Promise<Tags>;
|
|
398
441
|
export function loadView(data: DataView): Tags;
|
|
399
|
-
export function loadView(data: DataView, options: CommonOptions &
|
|
400
|
-
export function loadView(data: DataView, options: CommonOptions &
|
|
401
|
-
export function loadView(data: DataView, options: CommonOptions &
|
|
402
|
-
export function loadView(data: DataView, options: CommonOptions &
|
|
442
|
+
export function loadView(data: DataView, options: CommonOptions & ExpandedOnly & {async?: false}): ExpandedTags;
|
|
443
|
+
export function loadView(data: DataView, options: CommonOptions & FlatOnly & {async?: false}): Tags;
|
|
444
|
+
export function loadView(data: DataView, options: CommonOptions & ExpandedOnly & {async: true}): Promise<ExpandedTags>;
|
|
445
|
+
export function loadView(data: DataView, options: CommonOptions & FlatOnly & {async: true}): Promise<Tags>;
|
|
403
446
|
|
|
404
447
|
export namespace errors {
|
|
405
448
|
export class MetadataMissingError extends Error {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.40.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -28,26 +28,26 @@
|
|
|
28
28
|
"@babel/core": "^7.25.2",
|
|
29
29
|
"@babel/preset-env": "^7.29.5",
|
|
30
30
|
"@babel/register": "^7.29.3",
|
|
31
|
-
"@types/node": "^25.
|
|
31
|
+
"@types/node": "^25.9.1",
|
|
32
32
|
"babel-loader": "^10.0.0",
|
|
33
33
|
"babel-plugin-rewire": "^1.2.0",
|
|
34
34
|
"chai": "^4.3.10",
|
|
35
35
|
"cross-env": "^10.0.0",
|
|
36
|
-
"cypress": "^15.
|
|
36
|
+
"cypress": "^15.15.0",
|
|
37
37
|
"eslint": "^8.52.0",
|
|
38
38
|
"eslint-plugin-cypress": "^3.0.2",
|
|
39
39
|
"husky": "^9.0.11",
|
|
40
40
|
"linkedom": "^0.18.9",
|
|
41
|
-
"mocha": "^11.
|
|
41
|
+
"mocha": "^11.7.6",
|
|
42
42
|
"npm-run-all": "^4.1.5",
|
|
43
43
|
"nyc": "^18.0.0",
|
|
44
44
|
"rimraf": "^5.0.5",
|
|
45
45
|
"string-replace-loader": "^3.1.0",
|
|
46
|
-
"terser-webpack-plugin": "^5.
|
|
46
|
+
"terser-webpack-plugin": "^5.6.0",
|
|
47
47
|
"typescript": "^6.0.3",
|
|
48
|
-
"webpack": "5.
|
|
48
|
+
"webpack": "5.107.1",
|
|
49
49
|
"webpack-cli": "^7.0.0",
|
|
50
|
-
"webpack-dev-server": "^5.
|
|
50
|
+
"webpack-dev-server": "^5.2.4"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "node bin/build.js",
|
package/src/exif-reader.js
CHANGED
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
7
7
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
8
8
|
*/
|
|
9
|
-
/* global Buffer
|
|
9
|
+
/* global Buffer */
|
|
10
10
|
|
|
11
|
-
import {objectAssign,
|
|
11
|
+
import {objectAssign, decompress, COMPRESSION_METHOD_BROTLI} from './utils.js';
|
|
12
|
+
import {isFilePathOrURL, isBrowserFileObject, loadFile, loadFileObject} from './file-loaders.js';
|
|
13
|
+
import {makeLoadAuto, validateAutoOptions} from './load-auto.js';
|
|
12
14
|
import DataViewWrapper from './dataview.js';
|
|
13
15
|
import Constants from './constants.js';
|
|
14
16
|
import {getStringValueFromArray} from './utils.js';
|
|
@@ -46,153 +48,29 @@ export default {
|
|
|
46
48
|
export const errors = exifErrors;
|
|
47
49
|
|
|
48
50
|
export function load(data, options = {}) {
|
|
51
|
+
if (options.length === 'auto') {
|
|
52
|
+
validateAutoOptions(options);
|
|
53
|
+
return makeLoadAuto(loadFromData)(data, options);
|
|
54
|
+
}
|
|
49
55
|
if (isFilePathOrURL(data)) {
|
|
50
|
-
options.async = true;
|
|
51
|
-
|
|
52
56
|
if (typeof Promise === 'undefined') {
|
|
53
57
|
throw new Error('Promise is required when async mode is enabled.');
|
|
54
58
|
}
|
|
59
|
+
const asyncOptions = objectAssign({}, options, {async: true});
|
|
55
60
|
|
|
56
|
-
return loadFile(data,
|
|
61
|
+
return loadFile(data, asyncOptions).then((fileContents) => loadFromData(fileContents, asyncOptions));
|
|
57
62
|
}
|
|
58
63
|
if (isBrowserFileObject(data)) {
|
|
59
|
-
options.async = true;
|
|
60
|
-
|
|
61
64
|
if (typeof Promise === 'undefined') {
|
|
62
65
|
throw new Error('Promise is required when async mode is enabled.');
|
|
63
66
|
}
|
|
67
|
+
const asyncOptions = objectAssign({}, options, {async: true});
|
|
64
68
|
|
|
65
|
-
return loadFileObject(data,
|
|
69
|
+
return loadFileObject(data, asyncOptions).then((fileContents) => loadFromData(fileContents, asyncOptions));
|
|
66
70
|
}
|
|
67
71
|
return loadFromData(data, options);
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
function isFilePathOrURL(data) {
|
|
71
|
-
return typeof data === 'string';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function loadFile(filename, options) {
|
|
75
|
-
if (/^\w+:\/\//.test(filename)) {
|
|
76
|
-
if (typeof fetch !== 'undefined') {
|
|
77
|
-
return fetchRemoteFile(filename, options);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return nodeGetRemoteFile(filename, options);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (isDataUri(filename)) {
|
|
84
|
-
return Promise.resolve(dataUriToBuffer(filename));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return loadLocalFile(filename, options);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function fetchRemoteFile(url, {length} = {}) {
|
|
91
|
-
const options = {method: 'GET'};
|
|
92
|
-
if (Number.isInteger(length) && length >= 0) {
|
|
93
|
-
options.headers = {
|
|
94
|
-
range: `bytes=0-${length - 1}`,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return fetch(url, options).then((response) => response.arrayBuffer());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function nodeGetRemoteFile(url, {length} = {}) {
|
|
101
|
-
return new Promise((resolve, reject) => {
|
|
102
|
-
const options = {};
|
|
103
|
-
if (Number.isInteger(length) && length >= 0) {
|
|
104
|
-
options.headers = {
|
|
105
|
-
range: `bytes=0-${length - 1}`,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const get = requireNodeGet(url);
|
|
110
|
-
get(url, options, (response) => {
|
|
111
|
-
if ((response.statusCode >= 200) && (response.statusCode <= 299)) {
|
|
112
|
-
const data = [];
|
|
113
|
-
response.on('data', (chunk) => data.push(Buffer.from(chunk)));
|
|
114
|
-
response.on('error', (error) => reject(error));
|
|
115
|
-
response.on('end', () => resolve(Buffer.concat(data)));
|
|
116
|
-
} else {
|
|
117
|
-
reject(`Could not fetch file: ${response.statusCode} ${response.statusMessage}`);
|
|
118
|
-
response.resume();
|
|
119
|
-
}
|
|
120
|
-
}).on('error', (error) => reject(error));
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function requireNodeGet(url) {
|
|
125
|
-
if (/^https:\/\//.test(url)) {
|
|
126
|
-
return __non_webpack_require__('https').get;
|
|
127
|
-
}
|
|
128
|
-
return __non_webpack_require__('http').get;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function isDataUri(filename) {
|
|
132
|
-
return /^data:[^;,]*(;base64)?,/.test(filename);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function loadLocalFile(filename, {length} = {}) {
|
|
136
|
-
return new Promise((resolve, reject) => {
|
|
137
|
-
const fs = requireNodeFs();
|
|
138
|
-
fs.open(filename, (error, fd) => {
|
|
139
|
-
if (error) {
|
|
140
|
-
reject(error);
|
|
141
|
-
} else {
|
|
142
|
-
fs.stat(filename, (error, stat) => {
|
|
143
|
-
if (error) {
|
|
144
|
-
reject(error);
|
|
145
|
-
} else {
|
|
146
|
-
const size = Math.min(stat.size, length !== undefined ? length : stat.size);
|
|
147
|
-
const buffer = Buffer.alloc(size);
|
|
148
|
-
const options = {
|
|
149
|
-
buffer,
|
|
150
|
-
length: size
|
|
151
|
-
};
|
|
152
|
-
fs.read(fd, options, (error) => {
|
|
153
|
-
if (error) {
|
|
154
|
-
reject(error);
|
|
155
|
-
} else {
|
|
156
|
-
fs.close(fd, (error) => {
|
|
157
|
-
if (error) {
|
|
158
|
-
console.warn(`Could not close file ${filename}:`, error); // eslint-disable-line no-console
|
|
159
|
-
}
|
|
160
|
-
resolve(buffer);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function requireNodeFs() {
|
|
172
|
-
try {
|
|
173
|
-
return __non_webpack_require__('fs');
|
|
174
|
-
} catch (error) {
|
|
175
|
-
return undefined;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function isBrowserFileObject(data) {
|
|
180
|
-
return (typeof File !== 'undefined') && (data instanceof File);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function loadFileObject(file, {length}) {
|
|
184
|
-
return new Promise((resolve, reject) => {
|
|
185
|
-
const reader = new FileReader();
|
|
186
|
-
reader.onload = (readerEvent) => resolve(readerEvent.target.result);
|
|
187
|
-
reader.onerror = () => reject(reader.error);
|
|
188
|
-
if (Number.isInteger(length) && length >= 0 && file.slice !== undefined) {
|
|
189
|
-
reader.readAsArrayBuffer(file.slice(0, length));
|
|
190
|
-
} else {
|
|
191
|
-
reader.readAsArrayBuffer(file);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
74
|
function loadFromData(data, options) {
|
|
197
75
|
if (isNodeBuffer(data)) {
|
|
198
76
|
// File data read in Node can share the underlying buffer with other
|
|
@@ -225,19 +103,21 @@ export function loadView(
|
|
|
225
103
|
async = false,
|
|
226
104
|
computed = false,
|
|
227
105
|
includeUnknown = false,
|
|
106
|
+
includeOffsets = false,
|
|
228
107
|
domParser = undefined,
|
|
229
108
|
includeTags = undefined,
|
|
230
109
|
excludeTags = undefined,
|
|
231
|
-
decompress: decompressConfig = undefined
|
|
110
|
+
decompress: decompressConfig = undefined
|
|
232
111
|
} = {
|
|
233
112
|
expanded: false,
|
|
234
113
|
async: false,
|
|
235
114
|
computed: false,
|
|
236
115
|
includeUnknown: false,
|
|
116
|
+
includeOffsets: false,
|
|
237
117
|
domParser: undefined,
|
|
238
118
|
includeTags: undefined,
|
|
239
119
|
excludeTags: undefined,
|
|
240
|
-
decompress: undefined
|
|
120
|
+
decompress: undefined
|
|
241
121
|
}
|
|
242
122
|
) {
|
|
243
123
|
const tagFilter = createTagFilter({includeTags, excludeTags});
|
|
@@ -265,8 +145,12 @@ export function loadView(
|
|
|
265
145
|
gifHeaderOffset,
|
|
266
146
|
brobExifChunk,
|
|
267
147
|
brobXmpChunk,
|
|
268
|
-
jxlCodestreamOffset
|
|
269
|
-
|
|
148
|
+
jxlCodestreamOffset,
|
|
149
|
+
metadataBlocks,
|
|
150
|
+
metadataTruncated,
|
|
151
|
+
exifDataView,
|
|
152
|
+
xmpDataView
|
|
153
|
+
} = ImageHeader.parseAppMarkers(dataView, async, expanded && includeOffsets);
|
|
270
154
|
|
|
271
155
|
const fileHasMetaData = hasPotentialMetaData({
|
|
272
156
|
fileType,
|
|
@@ -330,7 +214,7 @@ export function loadView(
|
|
|
330
214
|
&& tagFilter.shouldParseGroup('exif')
|
|
331
215
|
) {
|
|
332
216
|
const {tags: readTags, byteOrder} = Tags.read(
|
|
333
|
-
dataView,
|
|
217
|
+
exifDataView || dataView,
|
|
334
218
|
tiffHeaderOffset,
|
|
335
219
|
includeUnknown,
|
|
336
220
|
computed,
|
|
@@ -458,7 +342,7 @@ export function loadView(
|
|
|
458
342
|
) {
|
|
459
343
|
if (hasCanonData(parsedExifTags)) {
|
|
460
344
|
const readCanonTags = CanonTags.read(
|
|
461
|
-
dataView,
|
|
345
|
+
exifDataView || dataView,
|
|
462
346
|
tiffHeaderOffset,
|
|
463
347
|
parsedExifTags['MakerNote'].__offset,
|
|
464
348
|
byteOrder,
|
|
@@ -476,7 +360,7 @@ export function loadView(
|
|
|
476
360
|
}
|
|
477
361
|
} else if (hasPentaxType1Data(parsedExifTags)) {
|
|
478
362
|
const readPentaxTags = PentaxTags.read(
|
|
479
|
-
dataView,
|
|
363
|
+
exifDataView || dataView,
|
|
480
364
|
tiffHeaderOffset,
|
|
481
365
|
parsedExifTags['MakerNote'].__offset,
|
|
482
366
|
includeUnknown,
|
|
@@ -536,7 +420,7 @@ export function loadView(
|
|
|
536
420
|
&& hasXmpData(xmpChunks)
|
|
537
421
|
&& tagFilter.shouldParseGroup('xmp')
|
|
538
422
|
) {
|
|
539
|
-
const readTags = XmpTags.read(dataView, xmpChunks, domParser);
|
|
423
|
+
const readTags = XmpTags.read(xmpDataView || dataView, xmpChunks, domParser);
|
|
540
424
|
const parsedXmpTags = filterTagsForParse('xmp', readTags, tagFilter);
|
|
541
425
|
parsedGroups.xmp = parsedXmpTags;
|
|
542
426
|
|
|
@@ -805,6 +689,14 @@ export function loadView(
|
|
|
805
689
|
mergeSteps.push({type: 'thumbnail'});
|
|
806
690
|
mergeSteps.push({type: 'fileType'});
|
|
807
691
|
|
|
692
|
+
if (expanded && includeOffsets) {
|
|
693
|
+
mergeSteps.push({
|
|
694
|
+
type: 'metadataRange',
|
|
695
|
+
metadataBlocks,
|
|
696
|
+
metadataTruncated: !!metadataTruncated,
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
|
|
808
700
|
if (!fileHasMetaData) {
|
|
809
701
|
throw new exifErrors.MetadataMissingError();
|
|
810
702
|
}
|
|
@@ -834,6 +726,7 @@ export function loadView(
|
|
|
834
726
|
tagFilter,
|
|
835
727
|
dataView,
|
|
836
728
|
tiffHeaderOffset,
|
|
729
|
+
exifDataView,
|
|
837
730
|
fileType,
|
|
838
731
|
pngTextChunks,
|
|
839
732
|
pngTextIsAsync,
|
|
@@ -853,6 +746,7 @@ export function loadView(
|
|
|
853
746
|
tagFilter,
|
|
854
747
|
dataView,
|
|
855
748
|
tiffHeaderOffset,
|
|
749
|
+
exifDataView,
|
|
856
750
|
fileType,
|
|
857
751
|
pngTextChunks,
|
|
858
752
|
pngTextIsAsync,
|