exifreader 4.50.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/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`, `Buffer`, or `File`) instead.
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`, `Buffer`, or `File`) instead.
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`, `Buffer`, or `File`) instead.
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`, `Buffer`, or `File`) instead.
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.50.0",
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": {
@@ -49,7 +49,7 @@
49
49
  "@babel/preset-env": "^7.29.7",
50
50
  "@cypress/webpack-preprocessor": "^8.0.0",
51
51
  "@eslint/js": "^9.39.5",
52
- "@types/node": "^26.6.4",
52
+ "@types/node": "^26.6.5",
53
53
  "babel-loader": "^10.0.0",
54
54
  "c8": "^12.0.0",
55
55
  "chai": "^6.2.2",
@@ -68,7 +68,7 @@
68
68
  "typescript": "^7.0.2",
69
69
  "webpack": "5.111.1",
70
70
  "webpack-cli": "^7.2.3",
71
- "webpack-dev-server": "^5.2.6"
71
+ "webpack-dev-server": "^6.1.0"
72
72
  },
73
73
  "scripts": {
74
74
  "build": "node bin/build.js",
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 {IFD_TYPE_CANON} from './tag-names.js';
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 TagNamesCommon from './tag-names-common.js';
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: TagNamesCommon.FocalLengthIn35mmFilm(focalLengthIn35mmFilm)
40
+ description: FocalLengthIn35mmFilm(focalLengthIn35mmFilm)
41
41
  };
42
42
  hasCompositeTags = true;
43
43
  }
@@ -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
- if (isNodeBuffer(data)) {
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} = Tags.read(
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
- Thumbnail,
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 and the Node Buffer
840
- // wrapper has no byteOffset, so neither is treated as a window here.
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
- if (isDataViewLike(dataView)) {
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} = Tags.read(dataView, tiffHeaderOffset, includeUnknown, computed, tagFilter, valueBudget);
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
@@ -8,7 +8,7 @@
8
8
  */
9
9
  /* global Buffer */
10
10
 
11
- import {dataUriToBuffer} from './utils.js';
11
+ import {dataUriToBuffer, isArrayBufferViewLike} from './utils.js';
12
12
  import NodeRequire from './node-require.js';
13
13
 
14
14
  export const HTTP_STATUS_OK = 200;
@@ -423,7 +423,8 @@ function finishLocalRead(filename, closeErr, buffer, total, resolve) {
423
423
  }
424
424
 
425
425
  /**
426
- * Range-aware browser `File` reader. Uses `file.slice(start, end)` plus
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
427
428
  * `FileReader.readAsArrayBuffer`.
428
429
  *
429
430
  * @param {File} file
@@ -431,18 +432,33 @@ function finishLocalRead(filename, closeErr, buffer, total, resolve) {
431
432
  * @returns {Promise<{buffer: ArrayBuffer, totalSize: number|undefined}>}
432
433
  */
433
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.
434
457
  return new Promise((resolve, reject) => {
435
458
  const reader = new FileReader();
436
- const totalSize = typeof file.size === 'number' ? file.size : undefined;
437
- reader.onload = (readerEvent) => resolve({buffer: readerEvent.target.result, totalSize});
459
+ reader.onload = (readerEvent) => resolve(readerEvent.target.result);
438
460
  reader.onerror = () => reject(reader.error);
439
- const hasSlice = file && typeof file.slice === 'function';
440
- if (hasSlice && (start > 0 || (end !== undefined && end !== Infinity))) {
441
- const sliceEnd = (end === undefined || end === Infinity) ? totalSize : end;
442
- reader.readAsArrayBuffer(file.slice(start, sliceEnd));
443
- } else {
444
- reader.readAsArrayBuffer(file);
445
- }
461
+ reader.readAsArrayBuffer(blob);
446
462
  });
447
463
  }
448
464
 
@@ -480,7 +496,7 @@ function bufferToBytes(b) {
480
496
  if (typeof Buffer !== 'undefined' && Buffer.isBuffer(b)) {
481
497
  return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
482
498
  }
483
- if (ArrayBuffer.isView(b)) {
499
+ if (isArrayBufferViewLike(b)) {
484
500
  return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
485
501
  }
486
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
- // On the Node Buffer wrapper, slice() returns a Buffer, which DataView
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(() => ({}));
@@ -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
- if (Constants.USE_EXIF || Constants.USE_XMP || Constants.USE_ICC) {
291
- const offsets = {};
289
+ const offsets = {};
292
290
 
293
- if (!metaBox) {
294
- return {hasAppMarkers: false};
295
- }
291
+ if (!metaBox) {
292
+ return {hasAppMarkers: false};
293
+ }
296
294
 
297
- warnIfUnsupportedFieldSize(metaBox);
295
+ warnIfUnsupportedFieldSize(metaBox);
298
296
 
299
- if (Constants.USE_EXIF) {
300
- const exif = findExifOffset(dataView, metaBox, metadataBlocks);
301
- if (exif !== undefined) {
302
- offsets.tiffHeaderOffset = exif.tiffHeaderOffset;
303
- if (exif.dataView !== undefined) {
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
- if (Constants.USE_XMP) {
309
- const xmp = findXmpChunks(dataView, metaBox, metadataBlocks);
310
- if (xmp !== undefined) {
311
- offsets.xmpChunks = xmp.chunks;
312
- if (xmp.dataView !== undefined) {
313
- offsets.xmpDataView = xmp.dataView;
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
- return {};
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) {
@@ -3,7 +3,6 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import {getStringFromDataView, pushMetadataBlock} from './utils.js';
6
- import Constants from './constants.js';
7
6
  import ByteOrder from './byte-order.js';
8
7
  import {
9
8
  IFD_ENTRY_COUNT_LENGTH,
@@ -112,19 +111,19 @@ function findJpegOffsets(dataView, metadataBlocks) {
112
111
  // Reaching SOS means the metadata region is closed.
113
112
  sawSos = true;
114
113
  }
115
- if (Constants.USE_FILE && isSOF0Marker(dataView, appMarkerPosition)) {
114
+ if (isSOF0Marker(dataView, appMarkerPosition)) {
116
115
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
117
116
  sof0DataOffset = appMarkerPosition + APP_MARKER_SIZE;
118
117
  blockType = 'file';
119
- } else if (Constants.USE_FILE && isSOF2Marker(dataView, appMarkerPosition)) {
118
+ } else if (isSOF2Marker(dataView, appMarkerPosition)) {
120
119
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
121
120
  sof2DataOffset = appMarkerPosition + APP_MARKER_SIZE;
122
121
  blockType = 'file';
123
- } else if (Constants.USE_JFIF && isApp0JfifMarker(dataView, appMarkerPosition)) {
122
+ } else if (isApp0JfifMarker(dataView, appMarkerPosition)) {
124
123
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
125
124
  jfifDataOffset = appMarkerPosition + JFIF_DATA_OFFSET;
126
125
  blockType = 'jfif';
127
- } else if (Constants.USE_EXIF && isApp1ExifMarker(dataView, appMarkerPosition)) {
126
+ } else if (isApp1ExifMarker(dataView, appMarkerPosition)) {
128
127
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
129
128
  exifSegmentCount++;
130
129
 
@@ -166,7 +165,7 @@ function findJpegOffsets(dataView, metadataBlocks) {
166
165
 
167
166
  tiffHeaderOffset = bestExifSegment.tiffHeaderOffset;
168
167
  blockType = 'exif';
169
- } else if (Constants.USE_XMP && isApp1XmpMarker(dataView, appMarkerPosition)) {
168
+ } else if (isApp1XmpMarker(dataView, appMarkerPosition)) {
170
169
  if (!xmpChunks) {
171
170
  xmpChunks = [];
172
171
  }
@@ -175,7 +174,7 @@ function findJpegOffsets(dataView, metadataBlocks) {
175
174
  xmpChunks.push(getXmpChunkDetails(appMarkerPosition, fieldLength));
176
175
  }
177
176
  blockType = 'xmp';
178
- } else if (Constants.USE_XMP && isApp1ExtendedXmpMarker(dataView, appMarkerPosition)) {
177
+ } else if (isApp1ExtendedXmpMarker(dataView, appMarkerPosition)) {
179
178
  if (!xmpChunks) {
180
179
  xmpChunks = [];
181
180
  }
@@ -184,11 +183,11 @@ function findJpegOffsets(dataView, metadataBlocks) {
184
183
  xmpChunks.push(getExtendedXmpChunkDetails(appMarkerPosition, fieldLength));
185
184
  }
186
185
  blockType = 'xmp';
187
- } else if (Constants.USE_IPTC && isApp13PhotoshopMarker(dataView, appMarkerPosition)) {
186
+ } else if (isApp13PhotoshopMarker(dataView, appMarkerPosition)) {
188
187
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
189
188
  iptcDataOffset = appMarkerPosition + IPTC_DATA_OFFSET;
190
189
  blockType = 'iptc';
191
- } else if (Constants.USE_ICC && isApp2ICCMarker(dataView, appMarkerPosition)) {
190
+ } else if (isApp2ICCMarker(dataView, appMarkerPosition)) {
192
191
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
193
192
  if (!iccChunks) {
194
193
  iccChunks = [];
@@ -202,7 +201,7 @@ function findJpegOffsets(dataView, metadataBlocks) {
202
201
  iccChunks.push({offset: iccDataOffset, length: iccDataLength, chunkNumber: iccChunkNumber, chunksTotal: iccChunksTotal});
203
202
  }
204
203
  blockType = 'icc';
205
- } else if (Constants.USE_MPF && isApp2MPFMarker(dataView, appMarkerPosition)) {
204
+ } else if (isApp2MPFMarker(dataView, appMarkerPosition)) {
206
205
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
207
206
  mpfDataOffset = appMarkerPosition + MPF_DATA_OFFSET;
208
207
  blockType = 'mpf';
@@ -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 {getBoxLength, getTiffHeaderOffset, BOX_TYPE_OFFSET, BOX_MIN_LENGTH} from './image-header-iso-bmff.js';
7
6
  import {pushMetadataBlock} from './utils.js';
8
7
 
@@ -107,14 +106,14 @@ function findJxlOffsets(dataView, metadataBlocks) {
107
106
  const boxType = dataView.getUint32(offset + BOX_TYPE_OFFSET);
108
107
  let blockType;
109
108
 
110
- if (Constants.USE_EXIF && boxType === TYPE_EXIF) {
109
+ if (boxType === TYPE_EXIF) {
111
110
  if (contentOffset + EXIF_TIFF_HEADER_OFFSET_SIZE <= contentEnd) {
112
111
  tiffHeaderOffset = getTiffHeaderOffset(dataView, contentOffset);
113
112
  }
114
113
  blockType = 'exif';
115
114
  }
116
115
 
117
- if (Constants.USE_XMP && boxType === TYPE_XML) {
116
+ if (boxType === TYPE_XML) {
118
117
  xmpChunks = [{
119
118
  dataOffset: contentOffset,
120
119
  length: length - (contentOffset - offset)
@@ -146,7 +145,7 @@ function findJxlOffsets(dataView, metadataBlocks) {
146
145
  // brob(Exif) box must surface as an `exif` block even if a
147
146
  // plain Exif box already won the parsing race. The brob*Chunk
148
147
  // variables stay guarded to avoid double-parsing.
149
- if (Constants.USE_EXIF && originalType === TYPE_EXIF) {
148
+ if (originalType === TYPE_EXIF) {
150
149
  blockType = 'exif';
151
150
  if (tiffHeaderOffset === undefined && !brobExifChunk) {
152
151
  brobExifChunk = {
@@ -155,7 +154,7 @@ function findJxlOffsets(dataView, metadataBlocks) {
155
154
  };
156
155
  }
157
156
  }
158
- if (Constants.USE_XMP && originalType === TYPE_XML) {
157
+ if (originalType === TYPE_XML) {
159
158
  blockType = 'xmp';
160
159
  if (!xmpChunks && !brobXmpChunk) {
161
160
  brobXmpChunk = {
@@ -5,7 +5,6 @@
5
5
  // Specification: http://www.libpng.org/pub/png/spec/1.2/
6
6
 
7
7
  import {getStringFromDataView, pushMetadataBlock} from './utils.js';
8
- import Constants from './constants.js';
9
8
 
10
9
  export default {
11
10
  isPngFile,
@@ -70,11 +69,11 @@ function findPngOffsets(dataView, async, metadataBlocks) {
70
69
  && getStringFromDataView(dataView, offset + PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_TYPE_SIZE) === TYPE_IEND) {
71
70
  sawIEnd = true;
72
71
  }
73
- if (Constants.USE_PNG_FILE && isPngImageHeaderChunk(dataView, offset)) {
72
+ if (isPngImageHeaderChunk(dataView, offset)) {
74
73
  offsets.hasAppMarkers = true;
75
74
  offsets.pngHeaderOffset = offset + PNG_CHUNK_DATA_OFFSET;
76
75
  blockType = 'file';
77
- } else if (Constants.USE_XMP && isPngXmpChunk(dataView, offset)) {
76
+ } else if (isPngXmpChunk(dataView, offset)) {
78
77
  const dataOffset = getPngXmpDataOffset(dataView, offset);
79
78
  if (dataOffset !== undefined) {
80
79
  offsets.hasAppMarkers = true;
@@ -95,7 +94,7 @@ function findPngOffsets(dataView, async, metadataBlocks) {
95
94
  offsets.hasAppMarkers = true;
96
95
  offsets.tiffHeaderOffset = offset + PNG_CHUNK_DATA_OFFSET;
97
96
  blockType = 'exif';
98
- } else if (Constants.USE_ICC && async && isPngIccpChunk(dataView, offset)) {
97
+ } else if (async && isPngIccpChunk(dataView, offset)) {
99
98
  const iccHeaderOffset = offset + PNG_CHUNK_DATA_OFFSET;
100
99
  const iccHeader = parseIccHeader(dataView, iccHeaderOffset, chunkDataLength);
101
100
  if (iccHeader !== undefined) {