exifreader 4.49.0 → 4.51.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 +15 -9
- package/bin/cli.js +4 -1
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +14 -10
- package/package.json +22 -3
- package/src/canon-tags.js +11 -2
- package/src/composite.js +2 -2
- package/src/dom-parser.js +3 -2
- package/src/exif-reader.js +91 -32
- package/src/file-loaders.js +39 -26
- package/src/icc-tags.js +1 -3
- package/src/ifd-types.js +14 -0
- package/src/image-header-iso-bmff.js +19 -30
- package/src/image-header-jpeg.js +9 -10
- package/src/image-header-jxl.js +4 -5
- package/src/image-header-png.js +3 -4
- package/src/image-header-tiff.js +4 -8
- package/src/image-header-webp.js +3 -4
- package/src/jfif-tags.js +1 -1
- package/src/load-auto.js +2 -2
- package/src/mpf-tags.js +12 -3
- package/src/node-require.js +84 -0
- package/src/pentax-tags.js +11 -2
- package/src/png-text-tags.js +22 -18
- package/src/tag-names-common.js +8 -6
- package/src/tag-names.js +27 -16
- package/src/tags-helpers.js +41 -32
- package/src/tags.js +13 -8
- package/src/thumbnail.js +1 -1
- package/src/utils.js +26 -4
- package/src/xmp-tags.js +4 -6
- package/webpack.config.js +1 -1
- package/src/dataview.js +0 -51
package/exif-reader.d.ts
CHANGED
|
@@ -439,18 +439,19 @@ type AutoLengthOptions = {
|
|
|
439
439
|
async?: boolean,
|
|
440
440
|
};
|
|
441
441
|
|
|
442
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer): Tags;
|
|
443
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & AutoLengthOptions): Promise<ExpandedTags>;
|
|
444
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & ExpandedOnly & {length?: number, async?: false}): ExpandedTags;
|
|
445
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & FlatOnly & {length?: number, async?: false}): Tags;
|
|
446
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & ExpandedOnly & {length?: number, async: true}): Promise<ExpandedTags>;
|
|
447
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & FlatOnly & {length?: number, async: true}): Promise<Tags>;
|
|
442
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer | ArrayBufferView): Tags;
|
|
443
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer | ArrayBufferView, options: CommonOptions & AutoLengthOptions): Promise<ExpandedTags>;
|
|
444
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer | ArrayBufferView, options: CommonOptions & ExpandedOnly & {length?: number, async?: false}): ExpandedTags;
|
|
445
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer | ArrayBufferView, options: CommonOptions & FlatOnly & {length?: number, async?: false}): Tags;
|
|
446
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer | ArrayBufferView, options: CommonOptions & ExpandedOnly & {length?: number, async: true}): Promise<ExpandedTags>;
|
|
447
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer | ArrayBufferView, options: CommonOptions & FlatOnly & {length?: number, async: true}): Promise<Tags>;
|
|
448
448
|
/**
|
|
449
449
|
* Security: a string argument is treated as a URL or a local file path, so
|
|
450
450
|
* `load()` will make a network request or read from the file system. Never pass
|
|
451
451
|
* an untrusted or user-controlled string, since it enables server-side request
|
|
452
452
|
* forgery (SSRF) and reads of arbitrary local files. For untrusted image data,
|
|
453
|
-
* pass the bytes (`ArrayBuffer`,
|
|
453
|
+
* pass the bytes (`ArrayBuffer`, a typed array such as `Uint8Array` or
|
|
454
|
+
* `Buffer`, or `File`) instead.
|
|
454
455
|
*/
|
|
455
456
|
export function load(data: string | File): Promise<Tags>;
|
|
456
457
|
/**
|
|
@@ -458,7 +459,8 @@ export function load(data: string | File): Promise<Tags>;
|
|
|
458
459
|
* `load()` will make a network request or read from the file system. Never pass
|
|
459
460
|
* an untrusted or user-controlled string, since it enables server-side request
|
|
460
461
|
* forgery (SSRF) and reads of arbitrary local files. For untrusted image data,
|
|
461
|
-
* pass the bytes (`ArrayBuffer`,
|
|
462
|
+
* pass the bytes (`ArrayBuffer`, a typed array such as `Uint8Array` or
|
|
463
|
+
* `Buffer`, or `File`) instead.
|
|
462
464
|
*/
|
|
463
465
|
export function load(data: string | File, options: CommonOptions & AutoLengthOptions): Promise<ExpandedTags>;
|
|
464
466
|
/**
|
|
@@ -466,7 +468,8 @@ export function load(data: string | File, options: CommonOptions & AutoLengthOpt
|
|
|
466
468
|
* `load()` will make a network request or read from the file system. Never pass
|
|
467
469
|
* an untrusted or user-controlled string, since it enables server-side request
|
|
468
470
|
* forgery (SSRF) and reads of arbitrary local files. For untrusted image data,
|
|
469
|
-
* pass the bytes (`ArrayBuffer`,
|
|
471
|
+
* pass the bytes (`ArrayBuffer`, a typed array such as `Uint8Array` or
|
|
472
|
+
* `Buffer`, or `File`) instead.
|
|
470
473
|
*/
|
|
471
474
|
export function load(data: string | File, options: CommonOptions & ExpandedOnly & {length?: number, async?: boolean }): Promise<ExpandedTags>;
|
|
472
475
|
/**
|
|
@@ -474,7 +477,8 @@ export function load(data: string | File, options: CommonOptions & ExpandedOnly
|
|
|
474
477
|
* `load()` will make a network request or read from the file system. Never pass
|
|
475
478
|
* an untrusted or user-controlled string, since it enables server-side request
|
|
476
479
|
* forgery (SSRF) and reads of arbitrary local files. For untrusted image data,
|
|
477
|
-
* pass the bytes (`ArrayBuffer`,
|
|
480
|
+
* pass the bytes (`ArrayBuffer`, a typed array such as `Uint8Array` or
|
|
481
|
+
* `Buffer`, or `File`) instead.
|
|
478
482
|
*/
|
|
479
483
|
export function load(data: string | File, options: CommonOptions & FlatOnly & {length?: number, async?: boolean }): Promise<Tags>;
|
|
480
484
|
export function loadView(data: DataView): Tags;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.51.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,23 @@
|
|
|
21
21
|
"webpack.config.js"
|
|
22
22
|
],
|
|
23
23
|
"types": "./exif-reader.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./exif-reader.d.ts",
|
|
27
|
+
"browser": "./src/exif-reader.js",
|
|
28
|
+
"node": "./dist/exif-reader.js",
|
|
29
|
+
"module": "./src/exif-reader.js",
|
|
30
|
+
"import": "./dist/exif-reader.js",
|
|
31
|
+
"require": "./dist/exif-reader.js",
|
|
32
|
+
"default": "./dist/exif-reader.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json",
|
|
35
|
+
"./src/exif-reader": "./src/exif-reader.js",
|
|
36
|
+
"./dist/exif-reader": "./dist/exif-reader.js",
|
|
37
|
+
"./src/composable/*": null,
|
|
38
|
+
"./src/*": "./src/*",
|
|
39
|
+
"./dist/*": "./dist/*"
|
|
40
|
+
},
|
|
24
41
|
"bin": {
|
|
25
42
|
"exifreader": "bin/cli.js"
|
|
26
43
|
},
|
|
@@ -32,7 +49,7 @@
|
|
|
32
49
|
"@babel/preset-env": "^7.29.7",
|
|
33
50
|
"@cypress/webpack-preprocessor": "^8.0.0",
|
|
34
51
|
"@eslint/js": "^9.39.5",
|
|
35
|
-
"@types/node": "^26.6.
|
|
52
|
+
"@types/node": "^26.6.5",
|
|
36
53
|
"babel-loader": "^10.0.0",
|
|
37
54
|
"c8": "^12.0.0",
|
|
38
55
|
"chai": "^6.2.2",
|
|
@@ -51,7 +68,7 @@
|
|
|
51
68
|
"typescript": "^7.0.2",
|
|
52
69
|
"webpack": "5.111.1",
|
|
53
70
|
"webpack-cli": "^7.2.3",
|
|
54
|
-
"webpack-dev-server": "^
|
|
71
|
+
"webpack-dev-server": "^6.1.0"
|
|
55
72
|
},
|
|
56
73
|
"scripts": {
|
|
57
74
|
"build": "node bin/build.js",
|
|
@@ -69,6 +86,8 @@
|
|
|
69
86
|
"test:e2e:chrome": "cypress run",
|
|
70
87
|
"test:e2e:firefox": "cypress run --browser firefox",
|
|
71
88
|
"test:types": "tsc --noEmit --project test/types",
|
|
89
|
+
"test:packaging:install": "npm install --prefix test/packaging/tools --no-package-lock --no-audit --no-fund --ignore-scripts",
|
|
90
|
+
"test:packaging": "node test/packaging/resolver-matrix.mjs",
|
|
72
91
|
"test:all": "npm-run-all2 lint test:types coverage test:e2e:chrome test:integration test:build test:build:custom",
|
|
73
92
|
"pre-commit": "npm-run-all2 lint test:types coverage test:build",
|
|
74
93
|
"postinstall": "node bin/build.js --only-with-config",
|
package/src/canon-tags.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
import {objectAssign} from './utils.js';
|
|
13
13
|
import {readIfd} from './tags-helpers.js';
|
|
14
|
-
import
|
|
14
|
+
import TagNamesCanonIfd from './tag-names-canon-ifd.js';
|
|
15
|
+
import {IFD_TYPE_CANON} from './ifd-types.js';
|
|
15
16
|
|
|
16
17
|
const SHOT_INFO_AUTO_ROTATE = 27; // First position is size.
|
|
17
18
|
const CAMERA_SETTINGS_LENS_TYPE = 22; // First position is size.
|
|
@@ -42,7 +43,8 @@ function read(
|
|
|
42
43
|
computed,
|
|
43
44
|
tagFilter,
|
|
44
45
|
'makerNotes',
|
|
45
|
-
valueBudget
|
|
46
|
+
valueBudget,
|
|
47
|
+
getTagNames()
|
|
46
48
|
);
|
|
47
49
|
|
|
48
50
|
if (tags['ShotInfo']) {
|
|
@@ -57,6 +59,13 @@ function read(
|
|
|
57
59
|
return tags;
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
// Assigned rather than a computed key, which Babel compiles to a helper call.
|
|
63
|
+
function getTagNames() {
|
|
64
|
+
const tagNames = {};
|
|
65
|
+
tagNames[IFD_TYPE_CANON] = TagNamesCanonIfd;
|
|
66
|
+
return tagNames;
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
function parseShotInfo(shotInfoData) {
|
|
61
70
|
const tags = {};
|
|
62
71
|
|
package/src/composite.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import {FocalLengthIn35mmFilm} from './tag-names-common.js';
|
|
6
6
|
|
|
7
7
|
const FOCAL_PLANE_RESOLUTION_UNIT = {
|
|
8
8
|
INCHES: 2,
|
|
@@ -37,7 +37,7 @@ function get(tags, expanded) {
|
|
|
37
37
|
if (focalLengthIn35mmFilm) {
|
|
38
38
|
compositeTags.FocalLength35efl = {
|
|
39
39
|
value: focalLengthIn35mmFilm,
|
|
40
|
-
description:
|
|
40
|
+
description: FocalLengthIn35mmFilm(focalLengthIn35mmFilm)
|
|
41
41
|
};
|
|
42
42
|
hasCompositeTags = true;
|
|
43
43
|
}
|
package/src/dom-parser.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
+
import NodeRequire from './node-require.js';
|
|
6
|
+
|
|
5
7
|
export default {
|
|
6
8
|
get
|
|
7
9
|
};
|
|
@@ -15,8 +17,7 @@ function get(domParser) {
|
|
|
15
17
|
return new DOMParser();
|
|
16
18
|
}
|
|
17
19
|
try {
|
|
18
|
-
|
|
19
|
-
const {DOMParser, onErrorStopParsing} = __non_webpack_require__('@xmldom/xmldom');
|
|
20
|
+
const {DOMParser, onErrorStopParsing} = NodeRequire.optionalPackage('@xmldom/xmldom');
|
|
20
21
|
return new DOMParser({onError: onErrorStopParsing});
|
|
21
22
|
} catch (error) {
|
|
22
23
|
return undefined;
|
package/src/exif-reader.js
CHANGED
|
@@ -6,9 +6,8 @@
|
|
|
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 */
|
|
10
9
|
|
|
11
|
-
import {objectAssign, decompress, withDecompressBudget, COMPRESSION_METHOD_BROTLI, getDataView, getByteString, getStringValueFromArray, assertPromiseSupport, setProperty} from './utils.js';
|
|
10
|
+
import {objectAssign, decompress, withDecompressBudget, COMPRESSION_METHOD_BROTLI, getDataView, getDataViewFromBytes, getByteString, getStringValueFromArray, assertPromiseSupport, setProperty, MAX_METADATA_BLOCKS} from './utils.js';
|
|
12
11
|
import {isFilePathOrURL, isBrowserFileObject, loadFile, loadFileObject} from './file-loaders.js';
|
|
13
12
|
import {makeLoadAuto, validateAutoOptions} from './load-auto.js';
|
|
14
13
|
import Constants from './constants.js';
|
|
@@ -17,6 +16,11 @@ import ByteOrder from './byte-order.js';
|
|
|
17
16
|
import {getTiffHeaderOffset} from './image-header-iso-bmff.js';
|
|
18
17
|
import ImageHeader from './image-header.js';
|
|
19
18
|
import Tags from './tags.js';
|
|
19
|
+
import TagNames0thIfd from './tag-names-0th-ifd.js';
|
|
20
|
+
import TagNamesExifIfd from './tag-names-exif-ifd.js';
|
|
21
|
+
import TagNamesGpsIfd from './tag-names-gps-ifd.js';
|
|
22
|
+
import TagNamesInteroperabilityIfd from './tag-names-interoperability-ifd.js';
|
|
23
|
+
import {IFD_TYPE_0TH, IFD_TYPE_1ST, IFD_TYPE_EXIF, IFD_TYPE_GPS, IFD_TYPE_INTEROPERABILITY} from './ifd-types.js';
|
|
20
24
|
import {getValueBudget, addDecompressedValueAllowance, takeEmbeddedExifThumbnail} from './tags-helpers.js';
|
|
21
25
|
import MpfTags from './mpf-tags.js';
|
|
22
26
|
import FileTags from './file-tags.js';
|
|
@@ -50,6 +54,8 @@ const BROB_XMP_SIZE_ALLOWANCE = 64 * 1024;
|
|
|
50
54
|
// total, plus room for a typical thumbnail.
|
|
51
55
|
const EMBEDDED_THUMBNAIL_SIZE_PER_INPUT_SIZE = 2;
|
|
52
56
|
const EMBEDDED_THUMBNAIL_SIZE_ALLOWANCE = 64 * 1024;
|
|
57
|
+
// The USE_EXIF gate is what lets a build without Exif drop the dictionaries.
|
|
58
|
+
const TAG_NAMES_0TH_AND_EXIF_IFDS = Constants.USE_EXIF ? objectAssign({}, TagNames0thIfd, TagNamesExifIfd) : {};
|
|
53
59
|
|
|
54
60
|
export default {
|
|
55
61
|
load,
|
|
@@ -75,20 +81,7 @@ export function load(data, options = {}) {
|
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
function loadFromData(data, options) {
|
|
78
|
-
|
|
79
|
-
// File data read in Node can share the underlying buffer with other
|
|
80
|
-
// data. Therefore it's safest to get a new one to avoid weird bugs.
|
|
81
|
-
data = (new Uint8Array(data)).buffer;
|
|
82
|
-
}
|
|
83
|
-
return loadView(getDataView(data), options);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function isNodeBuffer(data) {
|
|
87
|
-
try {
|
|
88
|
-
return Buffer.isBuffer(data);
|
|
89
|
-
} catch (error) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
84
|
+
return loadView(getDataViewFromBytes(data), options);
|
|
92
85
|
}
|
|
93
86
|
|
|
94
87
|
export function loadView(
|
|
@@ -328,7 +321,7 @@ export function loadView(
|
|
|
328
321
|
.then((decompressedDataView) => {
|
|
329
322
|
const brobTiffHeaderOffset = getTiffHeaderOffset(decompressedDataView, 0);
|
|
330
323
|
addDecompressedValueAllowance(valueBudget, decompressedDataView.byteLength);
|
|
331
|
-
const {tags: readTags, byteOrder: brobByteOrder} =
|
|
324
|
+
const {tags: readTags, byteOrder: brobByteOrder} = readExifTags(
|
|
332
325
|
decompressedDataView,
|
|
333
326
|
brobTiffHeaderOffset,
|
|
334
327
|
includeUnknown,
|
|
@@ -487,7 +480,11 @@ export function loadView(
|
|
|
487
480
|
decompressConfig,
|
|
488
481
|
valueBudget,
|
|
489
482
|
readEmbeddedExifThumbnail,
|
|
490
|
-
readEmbeddedExifCarriedGroups
|
|
483
|
+
readEmbeddedExifCarriedGroups,
|
|
484
|
+
{
|
|
485
|
+
exif: Constants.USE_EXIF ? readExifTags : undefined,
|
|
486
|
+
iptc: Constants.USE_IPTC ? IptcTags.read : undefined,
|
|
487
|
+
}
|
|
491
488
|
);
|
|
492
489
|
pngTextIsAsync = !!readTagsPromise;
|
|
493
490
|
|
|
@@ -612,7 +609,7 @@ export function loadView(
|
|
|
612
609
|
if (expanded && includeOffsets) {
|
|
613
610
|
mergeSteps.push({
|
|
614
611
|
type: 'metadataRange',
|
|
615
|
-
metadataBlocks,
|
|
612
|
+
metadataBlocks: getParsedMetadataBlocks(metadataBlocks, fileType),
|
|
616
613
|
metadataTruncated: !!metadataTruncated,
|
|
617
614
|
});
|
|
618
615
|
}
|
|
@@ -632,7 +629,9 @@ export function loadView(
|
|
|
632
629
|
// A plain property here would keep the import alive for the bundler, so
|
|
633
630
|
// a build with neither Exif nor XMP would still carry composite.js.
|
|
634
631
|
Composite: (Constants.USE_EXIF || Constants.USE_XMP) ? Composite : undefined,
|
|
635
|
-
|
|
632
|
+
// A plain property here would keep the import alive for the bundler, so
|
|
633
|
+
// a build without Exif thumbnails would still carry thumbnail.js.
|
|
634
|
+
Thumbnail: (Constants.USE_EXIF && Constants.USE_THUMBNAIL) ? Thumbnail : undefined,
|
|
636
635
|
};
|
|
637
636
|
|
|
638
637
|
if (async) {
|
|
@@ -836,8 +835,8 @@ function isWindowIntoLargerBuffer(dataView) {
|
|
|
836
835
|
}
|
|
837
836
|
|
|
838
837
|
// A DataView from another realm, an iframe for example, fails instanceof, so
|
|
839
|
-
// match on the shape instead. A typed array has no getUint8
|
|
840
|
-
//
|
|
838
|
+
// match on the shape instead. A typed array has no getUint8, so it is not
|
|
839
|
+
// treated as a window here.
|
|
841
840
|
function isDataViewLike(dataView) {
|
|
842
841
|
return !!dataView
|
|
843
842
|
&& (typeof dataView.getUint8 === 'function')
|
|
@@ -851,15 +850,7 @@ function getBrobDataView(dataView, brobChunk) {
|
|
|
851
850
|
// The box length is untrusted, so bound the view by the bytes present. The
|
|
852
851
|
// JXL header parser never reports a dataOffset past the end of the view.
|
|
853
852
|
const length = Math.max(0, Math.min(brobChunk.length, dataView.byteLength - brobChunk.dataOffset));
|
|
854
|
-
|
|
855
|
-
return new DataView(dataView.buffer, dataView.byteOffset + brobChunk.dataOffset, length);
|
|
856
|
-
}
|
|
857
|
-
// The Node Buffer wrapper has no ArrayBuffer to view, so copy the bytes out.
|
|
858
|
-
const bytes = new Uint8Array(length);
|
|
859
|
-
for (let i = 0; i < length; i++) {
|
|
860
|
-
bytes[i] = dataView.getUint8(brobChunk.dataOffset + i);
|
|
861
|
-
}
|
|
862
|
-
return new DataView(bytes.buffer);
|
|
853
|
+
return new DataView(dataView.buffer, dataView.byteOffset + brobChunk.dataOffset, length);
|
|
863
854
|
}
|
|
864
855
|
|
|
865
856
|
function exceedsBrobXmpSizeBound(byteLength, inputDataView) {
|
|
@@ -872,7 +863,7 @@ function readExifTagsSafely(dataView, tiffHeaderOffset, includeUnknown, computed
|
|
|
872
863
|
// view is only missing in unit tests that fake the tag readers.
|
|
873
864
|
const valueBudget = dataView === undefined ? undefined : getValueBudget(dataView);
|
|
874
865
|
try {
|
|
875
|
-
const {tags, byteOrder} =
|
|
866
|
+
const {tags, byteOrder} = readExifTags(dataView, tiffHeaderOffset, includeUnknown, computed, tagFilter, valueBudget);
|
|
876
867
|
return {tags, byteOrder, valueBudget};
|
|
877
868
|
} catch (error) {
|
|
878
869
|
// A malformed TIFF header (an out-of-bounds offset or an invalid byte
|
|
@@ -884,6 +875,74 @@ function readExifTagsSafely(dataView, tiffHeaderOffset, includeUnknown, computed
|
|
|
884
875
|
}
|
|
885
876
|
}
|
|
886
877
|
|
|
878
|
+
function readExifTags(dataView, tiffHeaderOffset, includeUnknown, computed, tagFilter, valueBudget) {
|
|
879
|
+
return Tags.read(
|
|
880
|
+
dataView,
|
|
881
|
+
tiffHeaderOffset,
|
|
882
|
+
includeUnknown,
|
|
883
|
+
computed,
|
|
884
|
+
tagFilter,
|
|
885
|
+
valueBudget,
|
|
886
|
+
getExifTagNames(),
|
|
887
|
+
shouldReadThumbnailIfd(tagFilter)
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// Only the IFDs Tags.read walks; the MPF and maker note readers carry their own
|
|
892
|
+
// dictionaries. The thumbnail one must be there whenever shouldReadThumbnailIfd
|
|
893
|
+
// is true, since reading an IFD without its dictionary throws.
|
|
894
|
+
function getExifTagNames() {
|
|
895
|
+
// Assigned rather than computed keys, which Babel compiles to a helper call each.
|
|
896
|
+
const tagNames = {};
|
|
897
|
+
tagNames[IFD_TYPE_0TH] = TAG_NAMES_0TH_AND_EXIF_IFDS;
|
|
898
|
+
tagNames[IFD_TYPE_EXIF] = TAG_NAMES_0TH_AND_EXIF_IFDS;
|
|
899
|
+
tagNames[IFD_TYPE_GPS] = TagNamesGpsIfd;
|
|
900
|
+
tagNames[IFD_TYPE_INTEROPERABILITY] = TagNamesInteroperabilityIfd;
|
|
901
|
+
if (Constants.USE_THUMBNAIL) {
|
|
902
|
+
tagNames[IFD_TYPE_1ST] = TagNames0thIfd;
|
|
903
|
+
}
|
|
904
|
+
return tagNames;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
function shouldReadThumbnailIfd(tagFilter) {
|
|
908
|
+
return Constants.USE_THUMBNAIL && tagFilter.shouldParseGroup('thumbnail');
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// Finders report every kind they find; list only the kinds this build parses.
|
|
912
|
+
function getParsedMetadataBlocks(metadataBlocks, fileType) {
|
|
913
|
+
if (!metadataBlocks) {
|
|
914
|
+
return metadataBlocks;
|
|
915
|
+
}
|
|
916
|
+
const format = fileType && fileType.value;
|
|
917
|
+
const isCapped = metadataBlocks.length >= MAX_METADATA_BLOCKS;
|
|
918
|
+
const lastIndex = metadataBlocks.length - 1;
|
|
919
|
+
return metadataBlocks.filter((block, index) => isParsedMetadataBlock(format, block.type)
|
|
920
|
+
// At the cap the last block was widened over every later block, so it stays.
|
|
921
|
+
|| (isCapped && index === lastIndex));
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
function isParsedMetadataBlock(format, blockType) {
|
|
925
|
+
switch (blockType) {
|
|
926
|
+
case 'file':
|
|
927
|
+
return format === 'png' ? Constants.USE_PNG_FILE : Constants.USE_FILE;
|
|
928
|
+
case 'exif':
|
|
929
|
+
// The PNG finder never gated eXIf, so it is listed in every build.
|
|
930
|
+
return format === 'png' || Constants.USE_EXIF;
|
|
931
|
+
case 'jfif':
|
|
932
|
+
return Constants.USE_JFIF;
|
|
933
|
+
case 'xmp':
|
|
934
|
+
return Constants.USE_XMP;
|
|
935
|
+
case 'iptc':
|
|
936
|
+
return Constants.USE_IPTC;
|
|
937
|
+
case 'icc':
|
|
938
|
+
return Constants.USE_ICC;
|
|
939
|
+
case 'mpf':
|
|
940
|
+
return Constants.USE_MPF;
|
|
941
|
+
default:
|
|
942
|
+
return true;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
887
946
|
function getEmbeddedExifThumbnailReader(tagFilter, inputDataView) {
|
|
888
947
|
if (
|
|
889
948
|
!Constants.USE_EXIF
|
package/src/file-loaders.js
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
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 {dataUriToBuffer} from './utils.js';
|
|
11
|
+
import {dataUriToBuffer, isArrayBufferViewLike} from './utils.js';
|
|
12
|
+
import NodeRequire from './node-require.js';
|
|
12
13
|
|
|
13
14
|
export const HTTP_STATUS_OK = 200;
|
|
14
15
|
export const HTTP_STATUS_SUCCESS_MAX = 299;
|
|
@@ -271,6 +272,9 @@ export function nodeGetRange(url, {start = 0, end, maxBytes} = {}) {
|
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
const get = requireNodeGet(url);
|
|
275
|
+
if (!get) {
|
|
276
|
+
return reject(new Error('Node http support is not available.'));
|
|
277
|
+
}
|
|
274
278
|
get(url, options, (response) => {
|
|
275
279
|
if ((response.statusCode >= HTTP_STATUS_OK) && (response.statusCode <= HTTP_STATUS_SUCCESS_MAX)) {
|
|
276
280
|
const totalSize = totalSizeFromNodeResponse(response);
|
|
@@ -358,10 +362,8 @@ function totalSizeFromRangeHeaders(contentRange, contentLength) {
|
|
|
358
362
|
}
|
|
359
363
|
|
|
360
364
|
function requireNodeGet(url) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
return __non_webpack_require__('http').get;
|
|
365
|
+
const http = NodeRequire.builtin(/^https:\/\//.test(url) ? 'https' : 'http');
|
|
366
|
+
return http && http.get;
|
|
365
367
|
}
|
|
366
368
|
|
|
367
369
|
/**
|
|
@@ -376,7 +378,10 @@ function requireNodeGet(url) {
|
|
|
376
378
|
*/
|
|
377
379
|
export function readLocalFileRange(filename, {start = 0, end, totalSize} = {}) {
|
|
378
380
|
return new Promise((resolve, reject) => {
|
|
379
|
-
const fs =
|
|
381
|
+
const fs = NodeRequire.builtin('fs');
|
|
382
|
+
if (!fs) {
|
|
383
|
+
return reject(new Error('Node file system support is not available.'));
|
|
384
|
+
}
|
|
380
385
|
fs.open(filename, (openErr, fd) => {
|
|
381
386
|
if (openErr) {
|
|
382
387
|
return reject(openErr);
|
|
@@ -417,16 +422,9 @@ function finishLocalRead(filename, closeErr, buffer, total, resolve) {
|
|
|
417
422
|
resolve({buffer, totalSize: total});
|
|
418
423
|
}
|
|
419
424
|
|
|
420
|
-
function requireNodeFs() {
|
|
421
|
-
try {
|
|
422
|
-
return __non_webpack_require__('fs');
|
|
423
|
-
} catch (error) {
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
425
|
/**
|
|
429
|
-
* Range-aware
|
|
426
|
+
* Range-aware `File`/`Blob` reader. Slices with `file.slice(start, end)` for a
|
|
427
|
+
* partial range, then reads with `Blob.prototype.arrayBuffer`, falling back to
|
|
430
428
|
* `FileReader.readAsArrayBuffer`.
|
|
431
429
|
*
|
|
432
430
|
* @param {File} file
|
|
@@ -434,18 +432,33 @@ function requireNodeFs() {
|
|
|
434
432
|
* @returns {Promise<{buffer: ArrayBuffer, totalSize: number|undefined}>}
|
|
435
433
|
*/
|
|
436
434
|
export function readFileObjectRange(file, {start = 0, end} = {}) {
|
|
435
|
+
return new Promise((resolve) => {
|
|
436
|
+
const totalSize = typeof file.size === 'number' ? file.size : undefined;
|
|
437
|
+
const blob = sliceFileObject(file, start, end, totalSize);
|
|
438
|
+
resolve(readBlob(blob).then((buffer) => ({buffer, totalSize})));
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function sliceFileObject(file, start, end, totalSize) {
|
|
443
|
+
const hasSlice = file && typeof file.slice === 'function';
|
|
444
|
+
if (hasSlice && (start > 0 || (end !== undefined && end !== Infinity))) {
|
|
445
|
+
const sliceEnd = (end === undefined || end === Infinity) ? totalSize : end;
|
|
446
|
+
return file.slice(start, sliceEnd);
|
|
447
|
+
}
|
|
448
|
+
return file;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function readBlob(blob) {
|
|
452
|
+
if (typeof blob.arrayBuffer === 'function') {
|
|
453
|
+
return Promise.resolve(blob.arrayBuffer());
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// IE, Safari before 14, Chrome before 76 and Firefox before 69 lack Blob.prototype.arrayBuffer.
|
|
437
457
|
return new Promise((resolve, reject) => {
|
|
438
458
|
const reader = new FileReader();
|
|
439
|
-
|
|
440
|
-
reader.onload = (readerEvent) => resolve({buffer: readerEvent.target.result, totalSize});
|
|
459
|
+
reader.onload = (readerEvent) => resolve(readerEvent.target.result);
|
|
441
460
|
reader.onerror = () => reject(reader.error);
|
|
442
|
-
|
|
443
|
-
if (hasSlice && (start > 0 || (end !== undefined && end !== Infinity))) {
|
|
444
|
-
const sliceEnd = (end === undefined || end === Infinity) ? totalSize : end;
|
|
445
|
-
reader.readAsArrayBuffer(file.slice(start, sliceEnd));
|
|
446
|
-
} else {
|
|
447
|
-
reader.readAsArrayBuffer(file);
|
|
448
|
-
}
|
|
461
|
+
reader.readAsArrayBuffer(blob);
|
|
449
462
|
});
|
|
450
463
|
}
|
|
451
464
|
|
|
@@ -483,7 +496,7 @@ function bufferToBytes(b) {
|
|
|
483
496
|
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(b)) {
|
|
484
497
|
return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
485
498
|
}
|
|
486
|
-
if (
|
|
499
|
+
if (isArrayBufferViewLike(b)) {
|
|
487
500
|
return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
488
501
|
}
|
|
489
502
|
return new Uint8Array(b);
|
package/src/icc-tags.js
CHANGED
|
@@ -42,9 +42,7 @@ function readCompressedIcc(dataView, iccData, decompressConfig) {
|
|
|
42
42
|
}
|
|
43
43
|
const byteOffset = dataView.byteOffset || 0;
|
|
44
44
|
const slice = dataView.buffer.slice(byteOffset + iccData[0].offset, byteOffset + iccData[0].offset + iccData[0].length);
|
|
45
|
-
|
|
46
|
-
// rejects. Uint8Array copies a Buffer and leaves an ArrayBuffer as is.
|
|
47
|
-
const compressedDataView = new DataView(new Uint8Array(slice).buffer);
|
|
45
|
+
const compressedDataView = new DataView(slice);
|
|
48
46
|
return decompress(compressedDataView, iccData[0].compressionMethod, 'utf-8', 'dataview', decompressConfig)
|
|
49
47
|
.then(parseTags)
|
|
50
48
|
.catch(() => ({}));
|
package/src/ifd-types.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
// Kept apart from tag-names.js so that a module needing only an IFD type can
|
|
6
|
+
// import it without pulling in the tag dictionaries.
|
|
7
|
+
export const IFD_TYPE_0TH = '0th';
|
|
8
|
+
export const IFD_TYPE_1ST = '1st';
|
|
9
|
+
export const IFD_TYPE_EXIF = 'exif';
|
|
10
|
+
export const IFD_TYPE_GPS = 'gps';
|
|
11
|
+
export const IFD_TYPE_INTEROPERABILITY = 'interoperability';
|
|
12
|
+
export const IFD_TYPE_MPF = 'mpf';
|
|
13
|
+
export const IFD_TYPE_CANON = 'canon';
|
|
14
|
+
export const IFD_TYPE_PENTAX = 'pentax';
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
-
import Constants from './constants.js';
|
|
6
5
|
import {getNullTerminatedStringFromDataView, getStringFromDataView, pushMetadataBlock} from './utils.js';
|
|
7
6
|
// import {get64BitValue} from './image-header-iso-bmff-utils.js';
|
|
8
7
|
import {parseItemLocationBox} from './image-header-iso-bmff-iloc.js';
|
|
@@ -287,41 +286,31 @@ function findMetaBox(dataView) {
|
|
|
287
286
|
}
|
|
288
287
|
|
|
289
288
|
function findMetadataOffsets(dataView, metaBox, metadataBlocks) {
|
|
290
|
-
|
|
291
|
-
const offsets = {};
|
|
289
|
+
const offsets = {};
|
|
292
290
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
291
|
+
if (!metaBox) {
|
|
292
|
+
return {hasAppMarkers: false};
|
|
293
|
+
}
|
|
296
294
|
|
|
297
|
-
|
|
295
|
+
warnIfUnsupportedFieldSize(metaBox);
|
|
298
296
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
offsets.exifDataView = exif.dataView;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
297
|
+
const exif = findExifOffset(dataView, metaBox, metadataBlocks);
|
|
298
|
+
if (exif !== undefined) {
|
|
299
|
+
offsets.tiffHeaderOffset = exif.tiffHeaderOffset;
|
|
300
|
+
if (exif.dataView !== undefined) {
|
|
301
|
+
offsets.exifDataView = exif.dataView;
|
|
307
302
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (Constants.USE_ICC) {
|
|
318
|
-
offsets.iccChunks = findIccChunks(metaBox, metadataBlocks);
|
|
303
|
+
}
|
|
304
|
+
const xmp = findXmpChunks(dataView, metaBox, metadataBlocks);
|
|
305
|
+
if (xmp !== undefined) {
|
|
306
|
+
offsets.xmpChunks = xmp.chunks;
|
|
307
|
+
if (xmp.dataView !== undefined) {
|
|
308
|
+
offsets.xmpDataView = xmp.dataView;
|
|
319
309
|
}
|
|
320
|
-
offsets.hasAppMarkers = (offsets.tiffHeaderOffset !== undefined) || (offsets.xmpChunks !== undefined) || (offsets.iccChunks !== undefined);
|
|
321
|
-
return offsets;
|
|
322
310
|
}
|
|
323
|
-
|
|
324
|
-
|
|
311
|
+
offsets.iccChunks = findIccChunks(metaBox, metadataBlocks);
|
|
312
|
+
offsets.hasAppMarkers = (offsets.tiffHeaderOffset !== undefined) || (offsets.xmpChunks !== undefined) || (offsets.iccChunks !== undefined);
|
|
313
|
+
return offsets;
|
|
325
314
|
}
|
|
326
315
|
|
|
327
316
|
function warnIfUnsupportedFieldSize(metaBox) {
|