exifreader 4.37.1 → 4.38.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
@@ -9,6 +9,7 @@ type FileTypeValue =
9
9
  | 'png'
10
10
  | 'heic'
11
11
  | 'avif'
12
+ | 'jxl'
12
13
  | 'webp'
13
14
  | 'gif'
14
15
  | 'xml';
@@ -19,6 +20,7 @@ type FileTypeDescription =
19
20
  | 'PNG'
20
21
  | 'HEIC'
21
22
  | 'AVIF'
23
+ | 'JPEG XL'
22
24
  | 'WebP'
23
25
  | 'GIF'
24
26
  | 'XML';
@@ -368,12 +370,20 @@ export type IncludeTagsOptions = {
368
370
 
369
371
  export type ExcludeTagsOptions = IncludeTagsOptions;
370
372
 
373
+ type DecompressFunction = (data: Uint8Array) => Promise<Uint8Array | ArrayBuffer> | Uint8Array | ArrayBuffer;
374
+
375
+ type DecompressOptions = {
376
+ brotli?: DecompressFunction,
377
+ deflate?: DecompressFunction,
378
+ };
379
+
371
380
  type CommonOptions = {
372
381
  includeUnknown?: boolean,
373
382
  computed?: boolean,
374
383
  domParser?: XmlDomParser,
375
384
  includeTags?: IncludeTagsOptions,
376
385
  excludeTags?: ExcludeTagsOptions,
386
+ decompress?: DecompressOptions,
377
387
  };
378
388
 
379
389
  export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer): Tags;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.37.1",
3
+ "version": "4.38.0",
4
4
  "description": "Library that parses Exif metadata in images.",
5
5
  "author": "Mattias Wallander <mattias@wallander.eu>",
6
6
  "repository": {
@@ -62,9 +62,10 @@
62
62
  "test:build": "mocha test/build/test.js",
63
63
  "test:build:custom": "mocha --bail test/build/test-custom.js",
64
64
  "test:build:update": "node test/build/update.js",
65
- "test:e2e": "cypress run",
65
+ "test:e2e:chrome": "cypress run",
66
+ "test:e2e:firefox": "cypress run --browser firefox",
66
67
  "test:types": "tsc --noEmit --project test/types",
67
- "test:all": "npm-run-all lint test:types coverage test:e2e test:integration test:build test:build:custom",
68
+ "test:all": "npm-run-all lint test:types coverage test:e2e:chrome test:integration test:build test:build:custom",
68
69
  "pre-commit": "npm-run-all lint test:types coverage test:build",
69
70
  "postinstall": "node bin/build.js --only-with-config",
70
71
  "prepare": "husky"
package/src/constants.js CHANGED
@@ -18,6 +18,7 @@ export default {
18
18
  USE_PNG: true,
19
19
  USE_HEIC: true,
20
20
  USE_AVIF: true,
21
+ USE_JXL: true,
21
22
  USE_WEBP: true,
22
23
  USE_GIF: true,
23
24
  USE_MAKER_NOTES: true
@@ -8,15 +8,17 @@
8
8
  */
9
9
  /* global Buffer, __non_webpack_require__ */
10
10
 
11
- import {objectAssign, dataUriToBuffer} from './utils.js';
11
+ import {objectAssign, dataUriToBuffer, decompress, COMPRESSION_METHOD_BROTLI} from './utils.js';
12
12
  import DataViewWrapper from './dataview.js';
13
13
  import Constants from './constants.js';
14
14
  import {getStringValueFromArray} from './utils.js';
15
15
  import {getCalculatedGpsValue} from './tag-names-utils.js';
16
+ import {getTiffHeaderOffset} from './image-header-iso-bmff.js';
16
17
  import ImageHeader from './image-header.js';
17
18
  import Tags from './tags.js';
18
19
  import MpfTags from './mpf-tags.js';
19
20
  import FileTags from './file-tags.js';
21
+ import JxlFileTags from './jxl-file-tags.js';
20
22
  import JfifTags from './jfif-tags.js';
21
23
  import IptcTags from './iptc-tags.js';
22
24
  import XmpTags from './xmp-tags.js';
@@ -226,6 +228,7 @@ export function loadView(
226
228
  domParser = undefined,
227
229
  includeTags = undefined,
228
230
  excludeTags = undefined,
231
+ decompress: decompressConfig = undefined,
229
232
  } = {
230
233
  expanded: false,
231
234
  async: false,
@@ -234,6 +237,7 @@ export function loadView(
234
237
  domParser: undefined,
235
238
  includeTags: undefined,
236
239
  excludeTags: undefined,
240
+ decompress: undefined,
237
241
  }
238
242
  ) {
239
243
  const tagFilter = createTagFilter({includeTags, excludeTags});
@@ -258,7 +262,10 @@ export function loadView(
258
262
  pngTextChunks,
259
263
  pngChunkOffsets,
260
264
  vp8xChunkOffset,
261
- gifHeaderOffset
265
+ gifHeaderOffset,
266
+ brobExifChunk,
267
+ brobXmpChunk,
268
+ jxlCodestreamOffset
262
269
  } = ImageHeader.parseAppMarkers(dataView, async);
263
270
 
264
271
  const fileHasMetaData = hasPotentialMetaData({
@@ -275,6 +282,7 @@ export function loadView(
275
282
  pngChunkOffsets,
276
283
  vp8xChunkOffset,
277
284
  gifHeaderOffset,
285
+ jxlCodestreamOffset,
278
286
  });
279
287
 
280
288
  if (
@@ -540,13 +548,84 @@ export function loadView(
540
548
  }
541
549
  }
542
550
 
551
+ if (
552
+ Constants.USE_JXL
553
+ && Constants.USE_EXIF
554
+ && brobExifChunk
555
+ && !hasExifData(tiffHeaderOffset)
556
+ && tagFilter.shouldParseGroup('exif')
557
+ && async
558
+ ) {
559
+ const compressedExifData = new DataView(
560
+ dataView.buffer,
561
+ dataView.byteOffset + brobExifChunk.dataOffset,
562
+ brobExifChunk.length
563
+ );
564
+ deferredPromises.push(
565
+ decompress(compressedExifData, COMPRESSION_METHOD_BROTLI, undefined, 'dataview', decompressConfig)
566
+ .then((decompressedDataView) => {
567
+ const brobTiffHeaderOffset = getTiffHeaderOffset(decompressedDataView, 0);
568
+ const {tags: readTags} = Tags.read(
569
+ decompressedDataView,
570
+ brobTiffHeaderOffset,
571
+ includeUnknown,
572
+ computed,
573
+ tagFilter
574
+ );
575
+ if (readTags.Thumbnail) {
576
+ delete readTags.Thumbnail;
577
+ }
578
+ deferredResults.brobExif = readTags;
579
+ })
580
+ .catch(() => {
581
+ deferredResults.brobExif = {};
582
+ })
583
+ );
584
+ mergeSteps.push({
585
+ type: 'mergeBrobExifDeferred',
586
+ deferredKey: 'brobExif',
587
+ });
588
+ }
589
+
590
+ if (
591
+ Constants.USE_JXL
592
+ && Constants.USE_XMP
593
+ && brobXmpChunk
594
+ && !hasXmpData(xmpChunks)
595
+ && tagFilter.shouldParseGroup('xmp')
596
+ && async
597
+ ) {
598
+ const compressedXmpData = new DataView(
599
+ dataView.buffer,
600
+ dataView.byteOffset + brobXmpChunk.dataOffset,
601
+ brobXmpChunk.length
602
+ );
603
+ deferredPromises.push(
604
+ decompress(compressedXmpData, COMPRESSION_METHOD_BROTLI, undefined, 'dataview', decompressConfig)
605
+ .then((decompressedDataView) => {
606
+ deferredResults.brobXmp = XmpTags.read(
607
+ decompressedDataView,
608
+ [{dataOffset: 0, length: decompressedDataView.byteLength}],
609
+ domParser
610
+ );
611
+ })
612
+ .catch(() => {
613
+ deferredResults.brobXmp = {};
614
+ })
615
+ );
616
+ mergeSteps.push({
617
+ type: 'mergeBrobXmpDeferred',
618
+ deferredKey: 'brobXmp',
619
+ });
620
+ }
621
+
543
622
  if (
544
623
  (Constants.USE_JPEG || Constants.USE_WEBP)
545
624
  && Constants.USE_ICC
546
625
  && hasIccData(iccChunks)
547
626
  && tagFilter.shouldParseGroup('icc')
548
627
  ) {
549
- const readTags = IccTags.read(dataView, iccChunks, async);
628
+ const readTags = IccTags.read(dataView, iccChunks, async, decompressConfig);
550
629
  if (isThenable(readTags)) {
551
630
  if (!async) {
552
631
  throw new Error('Promise is required when async mode is enabled.');
@@ -629,7 +708,8 @@ export function loadView(
629
708
  async,
630
709
  includeUnknown,
631
710
  computed,
632
- tagFilter
711
+ tagFilter,
712
+ decompressConfig
633
713
  );
634
714
  pngTextIsAsync = !!readTagsPromise;
635
715
 
@@ -702,6 +782,24 @@ export function loadView(
702
782
  }
703
783
  }
704
784
 
785
+ if (
786
+ Constants.USE_JXL
787
+ && hasJxlCodestreamData(jxlCodestreamOffset)
788
+ && tagFilter.shouldParseGroup('file')
789
+ ) {
790
+ const readTags = JxlFileTags.read(dataView, jxlCodestreamOffset);
791
+ const parsedJxlFileTags = filterTagsForParse('file', readTags, tagFilter);
792
+ parsedGroups.file = parsedJxlFileTags;
793
+
794
+ if (tagFilter.shouldReturnGroup('file')) {
795
+ mergeSteps.push({
796
+ type: 'mergeGroupAssign',
797
+ groupKey: 'file',
798
+ parsedTags: parsedJxlFileTags,
799
+ });
800
+ }
801
+ }
802
+
705
803
  mergeSteps.push({type: 'gps'});
706
804
  mergeSteps.push({type: 'composite'});
707
805
  mergeSteps.push({type: 'thumbnail'});
@@ -859,6 +957,7 @@ function hasPotentialMetaData({
859
957
  pngChunkOffsets,
860
958
  vp8xChunkOffset,
861
959
  gifHeaderOffset,
960
+ jxlCodestreamOffset,
862
961
  }) {
863
962
  return !!fileType
864
963
  || (
@@ -913,6 +1012,10 @@ function hasPotentialMetaData({
913
1012
  || (
914
1013
  Constants.USE_GIF
915
1014
  && hasGifFileData(gifHeaderOffset)
1015
+ )
1016
+ || (
1017
+ Constants.USE_JXL
1018
+ && hasJxlCodestreamData(jxlCodestreamOffset)
916
1019
  );
917
1020
  }
918
1021
 
@@ -1022,3 +1125,7 @@ function hasVp8xData(vp8xChunkOffset) {
1022
1125
  function hasGifFileData(gifHeaderOffset) {
1023
1126
  return gifHeaderOffset !== undefined;
1024
1127
  }
1128
+
1129
+ function hasJxlCodestreamData(jxlCodestreamOffset) {
1130
+ return jxlCodestreamOffset !== undefined;
1131
+ }
package/src/icc-tags.js CHANGED
@@ -22,20 +22,20 @@ const TAG_TABLE_SINGLE_TAG_DATA = 12;
22
22
  // total chunk count and chunk number.
23
23
  // Here we read all chunks into single continuous array of bytes.
24
24
  // Compressed ICC profile data only has support for a single chunk.
25
- function read(dataView, iccData, async) {
25
+ function read(dataView, iccData, async, decompressConfig) {
26
26
  if (async && iccData[0].compressionMethod !== COMPRESSION_METHOD_NONE) {
27
- return readCompressedIcc(dataView, iccData);
27
+ return readCompressedIcc(dataView, iccData, decompressConfig);
28
28
  }
29
29
 
30
30
  return readIcc(dataView, iccData);
31
31
  }
32
32
 
33
- function readCompressedIcc(dataView, iccData) {
33
+ function readCompressedIcc(dataView, iccData, decompressConfig) {
34
34
  if (!compressionMethodIsSupported(iccData[0].compressionMethod)) {
35
35
  return {};
36
36
  }
37
37
  const compressedDataView = new DataView(dataView.buffer.slice(iccData[0].offset, iccData[0].offset + iccData[0].length));
38
- return decompress(compressedDataView, iccData[0].compressionMethod, 'utf-8', 'dataview')
38
+ return decompress(compressedDataView, iccData[0].compressionMethod, 'utf-8', 'dataview', decompressConfig)
39
39
  .then(parseTags)
40
40
  .catch(() => ({}));
41
41
  }
@@ -99,7 +99,7 @@ export function parseBox(dataView, offset) {
99
99
  * @param {number} offset
100
100
  * @returns {BoxLength}
101
101
  */
102
- function getBoxLength(dataView, offset) {
102
+ export function getBoxLength(dataView, offset) {
103
103
  const BOX_LENGTH_SIZE = 4;
104
104
  const BOX_TYPE_SIZE = 4;
105
105
  const BOX_EXTENDED_SIZE = 8;
@@ -223,7 +223,7 @@ function findIlocItem(metaBox, itemId) {
223
223
  return metaBox.subBoxes.find((box) => box.type === 'iloc').items.find((item) => item.itemId === itemId);
224
224
  }
225
225
 
226
- function getTiffHeaderOffset(dataView, exifOffset) {
226
+ export function getTiffHeaderOffset(dataView, exifOffset) {
227
227
  // ISO-BMFF formatted files store the Exif data as an "Exif block" where the
228
228
  // first 32 bits is the TIFF header offset.
229
229
  const TIFF_HEADER_OFFSET_SIZE = 4;
@@ -0,0 +1,144 @@
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
+ import Constants from './constants.js';
6
+ import {getBoxLength, getTiffHeaderOffset} from './image-header-iso-bmff.js';
7
+
8
+ export default {
9
+ isJxlFile,
10
+ findJxlOffsets
11
+ };
12
+
13
+ const JXL_CONTAINER_SIGNATURE = [
14
+ 0x00, 0x00, 0x00, 0x0C,
15
+ 0x4A, 0x58, 0x4C, 0x20,
16
+ 0x0D, 0x0A, 0x87, 0x0A
17
+ ];
18
+ const JXL_CODESTREAM_SIGNATURE = [0xFF, 0x0A];
19
+
20
+ const BOX_TYPE_OFFSET = 4;
21
+ const BOX_HEADER_MIN_SIZE = 8;
22
+ const TYPE_EXIF = 0x45786966;
23
+ const TYPE_XML = 0x786D6C20;
24
+ const TYPE_BROB = 0x62726F62;
25
+ const TYPE_JXLC = 0x6a786c63;
26
+ const TYPE_JXLP = 0x6a786c70;
27
+ const JXLP_SEQUENCE_NUMBER_SIZE = 4;
28
+ const BROB_ORIGINAL_TYPE_SIZE = 4;
29
+
30
+ function isJxlFile(dataView) {
31
+ try {
32
+ return isJxlContainer(dataView) || isJxlCodestream(dataView);
33
+ } catch (_error) {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ function isJxlContainer(dataView) {
39
+ if (!dataView || dataView.byteLength < JXL_CONTAINER_SIGNATURE.length) {
40
+ return false;
41
+ }
42
+
43
+ for (let i = 0; i < JXL_CONTAINER_SIGNATURE.length; i++) {
44
+ if (dataView.getUint8(i) !== JXL_CONTAINER_SIGNATURE[i]) {
45
+ return false;
46
+ }
47
+ }
48
+
49
+ return true;
50
+ }
51
+
52
+ function isJxlCodestream(dataView) {
53
+ if (!dataView || dataView.byteLength < JXL_CODESTREAM_SIGNATURE.length) {
54
+ return false;
55
+ }
56
+
57
+ return dataView.getUint8(0) === JXL_CODESTREAM_SIGNATURE[0]
58
+ && dataView.getUint8(1) === JXL_CODESTREAM_SIGNATURE[1];
59
+ }
60
+
61
+ function findJxlOffsets(dataView) {
62
+ let offset = 0;
63
+ let tiffHeaderOffset;
64
+ let xmpChunks;
65
+ let brobExifChunk;
66
+ let brobXmpChunk;
67
+ let jxlCodestreamOffset;
68
+
69
+ if (isJxlCodestream(dataView)) {
70
+ jxlCodestreamOffset = 0;
71
+ }
72
+
73
+ while (offset + BOX_HEADER_MIN_SIZE <= dataView.byteLength) {
74
+ const {length, contentOffset} = getBoxLength(dataView, offset);
75
+ if (length < BOX_HEADER_MIN_SIZE) {
76
+ break;
77
+ }
78
+
79
+ const boxType = dataView.getUint32(offset + BOX_TYPE_OFFSET);
80
+
81
+ if (Constants.USE_EXIF && boxType === TYPE_EXIF) {
82
+ try {
83
+ tiffHeaderOffset = getTiffHeaderOffset(dataView, contentOffset);
84
+ } catch (_error) {
85
+ // Truncated Exif data.
86
+ }
87
+ }
88
+
89
+ if (Constants.USE_XMP && boxType === TYPE_XML) {
90
+ xmpChunks = [{
91
+ dataOffset: contentOffset,
92
+ length: length - (contentOffset - offset)
93
+ }];
94
+ }
95
+
96
+ if (boxType === TYPE_JXLC && jxlCodestreamOffset === undefined) {
97
+ jxlCodestreamOffset = contentOffset;
98
+ }
99
+
100
+ if (boxType === TYPE_JXLP && jxlCodestreamOffset === undefined
101
+ && contentOffset + JXLP_SEQUENCE_NUMBER_SIZE <= dataView.byteLength) {
102
+ const sequenceNumber = dataView.getUint32(contentOffset) & 0x7FFFFFFF;
103
+ if (sequenceNumber === 0) {
104
+ jxlCodestreamOffset = contentOffset + JXLP_SEQUENCE_NUMBER_SIZE;
105
+ }
106
+ }
107
+
108
+ if (boxType === TYPE_BROB && contentOffset + BROB_ORIGINAL_TYPE_SIZE <= dataView.byteLength) {
109
+ const originalType = dataView.getUint32(contentOffset);
110
+ const compressedDataOffset = contentOffset + BROB_ORIGINAL_TYPE_SIZE;
111
+ const compressedDataLength = length - (compressedDataOffset - offset);
112
+
113
+ if (Constants.USE_EXIF && originalType === TYPE_EXIF && tiffHeaderOffset === undefined && !brobExifChunk) {
114
+ brobExifChunk = {
115
+ dataOffset: compressedDataOffset,
116
+ length: compressedDataLength
117
+ };
118
+ }
119
+ if (Constants.USE_XMP && originalType === TYPE_XML && !xmpChunks && !brobXmpChunk) {
120
+ brobXmpChunk = {
121
+ dataOffset: compressedDataOffset,
122
+ length: compressedDataLength
123
+ };
124
+ }
125
+ }
126
+
127
+ offset += length;
128
+ }
129
+
130
+ const hasAppMarkers = tiffHeaderOffset !== undefined
131
+ || xmpChunks !== undefined
132
+ || brobExifChunk !== undefined
133
+ || brobXmpChunk !== undefined
134
+ || jxlCodestreamOffset !== undefined;
135
+
136
+ return {
137
+ hasAppMarkers,
138
+ tiffHeaderOffset,
139
+ xmpChunks,
140
+ brobExifChunk,
141
+ brobXmpChunk,
142
+ jxlCodestreamOffset
143
+ };
144
+ }
@@ -8,6 +8,7 @@ import Jpeg from './image-header-jpeg.js';
8
8
  import Png from './image-header-png.js';
9
9
  import Heic from './image-header-heic.js';
10
10
  import Avif from './image-header-avif.js';
11
+ import Jxl from './image-header-jxl.js';
11
12
  import Webp from './image-header-webp.js';
12
13
  import Gif from './image-header-gif.js';
13
14
  import Xml from './xml.js';
@@ -38,6 +39,10 @@ function parseAppMarkers(dataView, async) {
38
39
  return addFileType(Avif.findAvifOffsets(dataView), 'avif', 'AVIF');
39
40
  }
40
41
 
42
+ if (Constants.USE_JXL && Jxl.isJxlFile(dataView)) {
43
+ return addFileType(Jxl.findJxlOffsets(dataView), 'jxl', 'JPEG XL');
44
+ }
45
+
41
46
  if (Constants.USE_WEBP && Webp.isWebpFile(dataView)) {
42
47
  return addFileType(Webp.findOffsets(dataView), 'webp', 'WebP');
43
48
  }
@@ -0,0 +1,74 @@
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
+ export default {
6
+ read
7
+ };
8
+
9
+ const CODESTREAM_SIGNATURE_SIZE = 2;
10
+ const SIZE_U32_BITS = [9, 13, 18, 30];
11
+ const RATIOS = [0, 1, 12 / 10, 4 / 3, 3 / 2, 16 / 9, 5 / 4, 2];
12
+
13
+ function read(dataView, codestreamOffset) {
14
+ const tags = {};
15
+
16
+ try {
17
+ const reader = createBitReader(dataView, codestreamOffset + CODESTREAM_SIGNATURE_SIZE);
18
+ const {height, width} = parseSizeHeader(reader);
19
+
20
+ tags['Image Height'] = {value: height, description: `${height}px`};
21
+ tags['Image Width'] = {value: width, description: `${width}px`};
22
+ } catch (_error) {
23
+ // Truncated or malformed data.
24
+ }
25
+
26
+ return tags;
27
+ }
28
+
29
+ function parseSizeHeader(reader) {
30
+ const small = reader.readBits(1);
31
+ let height;
32
+ let width;
33
+
34
+ if (small) {
35
+ height = (reader.readBits(5) + 1) * 8;
36
+ const ratio = reader.readBits(3);
37
+ width = ratio === 0 ? (reader.readBits(5) + 1) * 8 : Math.ceil(height * RATIOS[ratio]);
38
+ } else {
39
+ height = readSizeU32(reader);
40
+ const ratio = reader.readBits(3);
41
+ width = ratio === 0 ? readSizeU32(reader) : Math.ceil(height * RATIOS[ratio]);
42
+ }
43
+
44
+ return {height, width};
45
+ }
46
+
47
+ function readSizeU32(reader) {
48
+ const selector = reader.readBits(2);
49
+ return 1 + reader.readBits(SIZE_U32_BITS[selector]);
50
+ }
51
+
52
+ function createBitReader(dataView, byteOffset) {
53
+ let currentByte = byteOffset;
54
+ let currentBit = 0;
55
+
56
+ return {
57
+ readBits(n) {
58
+ let value = 0;
59
+ for (let i = 0; i < n; i++) {
60
+ if (currentByte >= dataView.byteLength) {
61
+ throw new Error('Unexpected end of data');
62
+ }
63
+ const bit = (dataView.getUint8(currentByte) >> currentBit) & 1;
64
+ value |= (bit << i);
65
+ currentBit++;
66
+ if (currentBit >= 8) {
67
+ currentBit = 0;
68
+ currentByte++;
69
+ }
70
+ }
71
+ return value;
72
+ }
73
+ };
74
+ }
@@ -115,6 +115,52 @@ export function applyMergeStep({
115
115
  return mergeAssignGroup(tags, 'icc', returnedIccTags, expanded, deps);
116
116
  }
117
117
 
118
+ if (step.type === 'mergeBrobExifDeferred') {
119
+ const resolvedReadTags = deferredResults[step.deferredKey];
120
+ if (!resolvedReadTags || Object.keys(resolvedReadTags).length === 0) {
121
+ return tags;
122
+ }
123
+ const parsedExifTags =
124
+ deps.filterTagsForParse('exif', resolvedReadTags, tagFilter);
125
+ parsedGroups.exif = !parsedGroups.exif ? parsedExifTags : deps.objectAssign({}, parsedGroups.exif, parsedExifTags);
126
+
127
+ if (!tagFilter.shouldReturnGroup('exif')) {
128
+ return tags;
129
+ }
130
+
131
+ const returnedTags =
132
+ deps.filterTagsForReturn('exif', parsedExifTags, tagFilter);
133
+
134
+ return mergeAssignGroup(tags, 'exif', returnedTags, expanded, deps);
135
+ }
136
+
137
+ if (step.type === 'mergeBrobXmpDeferred') {
138
+ const resolvedReadTags = deferredResults[step.deferredKey];
139
+ if (!resolvedReadTags || Object.keys(resolvedReadTags).length === 0) {
140
+ return tags;
141
+ }
142
+ const parsedXmpTags =
143
+ deps.filterTagsForParse('xmp', resolvedReadTags, tagFilter);
144
+ parsedGroups.xmp = parsedXmpTags;
145
+
146
+ if (!tagFilter.shouldReturnGroup('xmp')) {
147
+ return tags;
148
+ }
149
+
150
+ const returnedTags =
151
+ deps.filterTagsForReturn('xmp', parsedXmpTags, tagFilter);
152
+
153
+ if (expanded) {
154
+ tags.xmp = returnedTags;
155
+ return tags;
156
+ }
157
+
158
+ const returnedTagsForFlat = deps.objectAssign({}, returnedTags);
159
+ delete returnedTagsForFlat._raw;
160
+
161
+ return deps.objectAssign({}, tags, returnedTagsForFlat);
162
+ }
163
+
118
164
  if (step.type === 'mergePngFile') {
119
165
  const returnedPngFileTags =
120
166
  deps.filterTagsForReturn('png', step.parsedTags, tagFilter);
@@ -31,14 +31,15 @@ function read(
31
31
  async,
32
32
  includeUnknown,
33
33
  computed = false,
34
- tagFilter = NOOP_TAG_FILTER
34
+ tagFilter = NOOP_TAG_FILTER,
35
+ decompressConfig
35
36
  ) {
36
37
  const tags = {};
37
38
  const tagsPromises = [];
38
39
 
39
40
  for (let i = 0; i < pngTextChunks.length; i++) {
40
41
  const {offset, length, type} = pngTextChunks[i];
41
- const nameAndValue = getNameAndValue(dataView, offset, length, type, async);
42
+ const nameAndValue = getNameAndValue(dataView, offset, length, type, async, decompressConfig);
42
43
  if (nameAndValue instanceof Promise) {
43
44
  tagsPromises.push(nameAndValue.then(({name, value, description}) => {
44
45
  try {
@@ -100,7 +101,7 @@ function read(
100
101
  };
101
102
  }
102
103
 
103
- function getNameAndValue(dataView, offset, length, type, async) {
104
+ function getNameAndValue(dataView, offset, length, type, async, decompressConfig) {
104
105
  const keywordChars = [];
105
106
  const langChars = [];
106
107
  const translatedKeywordChars = [];
@@ -135,7 +136,7 @@ function getNameAndValue(dataView, offset, length, type, async) {
135
136
  if (compressionMethod !== COMPRESSION_METHOD_NONE && !async) {
136
137
  return {};
137
138
  }
138
- const decompressedValueChars = decompress(valueChars, compressionMethod, getEncodingFromType(type));
139
+ const decompressedValueChars = decompress(valueChars, compressionMethod, getEncodingFromType(type), 'string', decompressConfig);
139
140
  if (decompressedValueChars instanceof Promise) {
140
141
  return decompressedValueChars
141
142
  .then((_decompressedValueChars) => constructTag(_decompressedValueChars, type, langChars, keywordChars))