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.
@@ -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) {
@@ -3,7 +3,6 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import ByteOrder from './byte-order.js';
6
- import Constants from './constants.js';
7
6
  import {TIFF_ID, TIFF_ID_OFFSET} from './tiff-constants.js';
8
7
 
9
8
  export default {
@@ -25,11 +24,8 @@ function hasTiffMarker(dataView) {
25
24
  function findTiffOffsets() {
26
25
  const TIFF_FILE_HEADER_OFFSET = 0;
27
26
 
28
- if (Constants.USE_EXIF) {
29
- return {
30
- hasAppMarkers: true,
31
- tiffHeaderOffset: TIFF_FILE_HEADER_OFFSET
32
- };
33
- }
34
- return {};
27
+ return {
28
+ hasAppMarkers: true,
29
+ tiffHeaderOffset: TIFF_FILE_HEADER_OFFSET
30
+ };
35
31
  }
@@ -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
 
8
7
  export default {
9
8
  isWebpFile,
@@ -53,7 +52,7 @@ function findOffsets(dataView, metadataBlocks) {
53
52
  const chunkSize = dataView.getUint32(offset + CHUNK_SIZE_OFFSET, true);
54
53
  let blockType;
55
54
 
56
- if (Constants.USE_EXIF && (chunkId === 'EXIF')) {
55
+ if (chunkId === 'EXIF') {
57
56
  hasAppMarkers = true;
58
57
  if (getStringFromDataView(dataView, offset + CHUNK_HEADER_SIZE, EXIF_IDENTIFIER.length) === EXIF_IDENTIFIER) {
59
58
  tiffHeaderOffset = offset + CHUNK_HEADER_SIZE + EXIF_IDENTIFIER.length;
@@ -61,14 +60,14 @@ function findOffsets(dataView, metadataBlocks) {
61
60
  tiffHeaderOffset = offset + CHUNK_HEADER_SIZE;
62
61
  }
63
62
  blockType = 'exif';
64
- } else if (Constants.USE_XMP && (chunkId === 'XMP ')) {
63
+ } else if (chunkId === 'XMP ') {
65
64
  hasAppMarkers = true;
66
65
  xmpChunks = [{
67
66
  dataOffset: offset + CHUNK_HEADER_SIZE,
68
67
  length: chunkSize
69
68
  }];
70
69
  blockType = 'xmp';
71
- } else if (Constants.USE_ICC && (chunkId === 'ICCP')) {
70
+ } else if (chunkId === 'ICCP') {
72
71
  hasAppMarkers = true;
73
72
  iccChunks = [{
74
73
  offset: offset + CHUNK_HEADER_SIZE,
package/src/jfif-tags.js CHANGED
@@ -153,7 +153,7 @@ function getThumbnail(dataView, jfifDataOffset, thumbnailLength, length) {
153
153
  return undefined;
154
154
  }
155
155
 
156
- const byteOffset = dataView.byteOffset || 0;
156
+ const byteOffset = dataView.byteOffset;
157
157
  const value = dataView.buffer.slice(byteOffset + jfifDataOffset + OFFSET, byteOffset + jfifDataOffset + OFFSET + thumbnailLength);
158
158
  return {
159
159
  value,
package/src/load-auto.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  concatBuffers, isFilePathOrURL, isBrowserFileObject, isDataUri,
10
10
  HTTP_STATUS_OK, HTTP_STATUS_RANGE_NOT_SATISFIABLE,
11
11
  } from './file-loaders.js';
12
- import {objectAssign, dataUriToBuffer, assertPromiseSupport} from './utils.js';
12
+ import {objectAssign, dataUriToBuffer, assertPromiseSupport, isArrayBufferViewLike} from './utils.js';
13
13
 
14
14
  const AUTO_INITIAL_LENGTH = 128 * 1024;
15
15
  const AUTO_MAX_ITERATIONS = 4;
@@ -286,7 +286,7 @@ function sliceInputBuffer(data, end) {
286
286
  if (typeof SharedArrayBuffer !== 'undefined' && data instanceof SharedArrayBuffer) {
287
287
  return data.slice(0, end);
288
288
  }
289
- if (ArrayBuffer.isView(data)) {
289
+ if (isArrayBufferViewLike(data)) {
290
290
  const viewEnd = Math.max(0, Math.min(end, data.byteLength));
291
291
  return data.buffer.slice(data.byteOffset, data.byteOffset + viewEnd);
292
292
  }
package/src/mpf-tags.js CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  import ByteOrder from './byte-order.js';
6
6
  import Types from './types.js';
7
- import {IFD_TYPE_MPF} from './tag-names.js';
7
+ import TagNamesMpfIfd from './tag-names-mpf-ifd.js';
8
+ import {IFD_TYPE_MPF} from './ifd-types.js';
8
9
  import {deferInit, getBase64Image} from './utils.js';
9
10
  import {readIfd, get0thIfdOffset} from './tags-helpers.js';
10
11
 
@@ -48,7 +49,8 @@ function read(
48
49
  computed,
49
50
  tagFilter,
50
51
  'mpf',
51
- valueBudget
52
+ valueBudget,
53
+ getTagNames()
52
54
  );
53
55
  return addMpfImages(dataView, dataOffset, tags, byteOrder);
54
56
  } catch (error) {
@@ -56,6 +58,13 @@ function read(
56
58
  }
57
59
  }
58
60
 
61
+ // Assigned rather than a computed key, which Babel compiles to a helper call.
62
+ function getTagNames() {
63
+ const tagNames = {};
64
+ tagNames[IFD_TYPE_MPF] = TagNamesMpfIfd;
65
+ return tagNames;
66
+ }
67
+
59
68
  function addMpfImages(dataView, dataOffset, tags, byteOrder) {
60
69
  if (!tags['MPEntry']) {
61
70
  return tags;
@@ -64,7 +73,7 @@ function addMpfImages(dataView, dataOffset, tags, byteOrder) {
64
73
  // The bound is the view's own extent, not the buffer's, since the slice
65
74
  // starts at the view's byteOffset.
66
75
  const bufferLength = dataView.byteLength;
67
- const byteOffset = dataView.byteOffset || 0;
76
+ const byteOffset = dataView.byteOffset;
68
77
  let remainingImageBytes = bufferLength * MAX_IMAGE_SIZE_PER_BUFFER_SIZE;
69
78
  const images = [];
70
79
  const imageCount = Math.min(Math.ceil(tags['MPEntry'].value.length / ENTRY_SIZE), MAX_IMAGES);
@@ -0,0 +1,84 @@
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
+ /* global globalThis, __non_webpack_require__ */
6
+
7
+ export default {
8
+ builtin,
9
+ optionalPackage
10
+ };
11
+
12
+ /**
13
+ * Loads a Node builtin module such as `fs`, `http` or `https`.
14
+ *
15
+ * @param {string} name
16
+ * @returns {Object|undefined} The module, or undefined where none is reachable
17
+ * (browsers, workers).
18
+ */
19
+ function builtin(name) {
20
+ return firstLoaded(name, [webpackRequire, getBuiltinModule, mainModuleRequire]);
21
+ }
22
+
23
+ /**
24
+ * Loads an installed package through the literal require that webpack emits,
25
+ * which Node and bundlers resolve from the UMD. The ES module source outside
26
+ * webpack gets none: programs pass the domParser option instead.
27
+ *
28
+ * @param {string} name
29
+ * @returns {Object|undefined} The package, or undefined where none is reachable.
30
+ */
31
+ function optionalPackage(name) {
32
+ return firstLoaded(name, [webpackRequire]);
33
+ }
34
+
35
+ // A loader throws where its mechanism is missing (no process, no
36
+ // getBuiltinModule, no mainModule), which moves on to the next one. process is
37
+ // never named as a free variable: Parcel 2 and webpack 4 would then bundle a
38
+ // process polyfill into browser builds of the source.
39
+ function firstLoaded(name, loaders) {
40
+ for (let i = 0; i < loaders.length; i++) {
41
+ try {
42
+ return loaders[i](name);
43
+ } catch (error) {
44
+ // Try the next loader.
45
+ }
46
+ }
47
+ return undefined;
48
+ }
49
+
50
+ // Literal names make webpack emit require('fs') and so on, which bundlers and
51
+ // file tracers follow. No typeof guard: webpack may not rewrite the identifier there.
52
+ // A try in this function makes bundlers treat fs and @xmldom/xmldom as optional.
53
+ function webpackRequire(name) {
54
+ switch (name) {
55
+ case 'fs':
56
+ // eslint-disable-next-line no-useless-catch
57
+ try {
58
+ return __non_webpack_require__('fs');
59
+ } catch (error) {
60
+ throw error;
61
+ }
62
+ case 'http':
63
+ return __non_webpack_require__('http');
64
+ case 'https':
65
+ return __non_webpack_require__('https');
66
+ case '@xmldom/xmldom':
67
+ // eslint-disable-next-line no-useless-catch
68
+ try {
69
+ return __non_webpack_require__('@xmldom/xmldom');
70
+ } catch (error) {
71
+ throw error;
72
+ }
73
+ default:
74
+ throw new Error(`No webpack require for ${name}.`);
75
+ }
76
+ }
77
+
78
+ function getBuiltinModule(name) {
79
+ return globalThis.process.getBuiltinModule(name);
80
+ }
81
+
82
+ function mainModuleRequire(name) {
83
+ return globalThis.process.mainModule.require(name);
84
+ }
@@ -10,7 +10,8 @@
10
10
  import ByteOrder from './byte-order.js';
11
11
  import {objectAssign} from './utils.js';
12
12
  import {readIfd} from './tags-helpers.js';
13
- import {IFD_TYPE_PENTAX} from './tag-names.js';
13
+ import TagNamesPentaxIfd from './tag-names-pentax-ifd.js';
14
+ import {IFD_TYPE_PENTAX} from './ifd-types.js';
14
15
 
15
16
  const BYTE_ORDER_OFFSET = 8; // Pentax5: https://exiftool.org/makernote_types.html
16
17
  const PENTAX_IFD_OFFSET = BYTE_ORDER_OFFSET + 2; // https://exiftool.org/makernote_types.html
@@ -58,7 +59,8 @@ function read(
58
59
  computed,
59
60
  tagFilter,
60
61
  'makerNotes',
61
- valueBudget
62
+ valueBudget,
63
+ getTagNames()
62
64
  );
63
65
 
64
66
  if (hasLevelInfoK3III(tags)) {
@@ -79,6 +81,13 @@ function read(
79
81
  }
80
82
  }
81
83
 
84
+ // Assigned rather than a computed key, which Babel compiles to a helper call.
85
+ function getTagNames() {
86
+ const tagNames = {};
87
+ tagNames[IFD_TYPE_PENTAX] = TagNamesPentaxIfd;
88
+ return tagNames;
89
+ }
90
+
82
91
  function hasLevelInfoK3III(tags) {
83
92
  return tags['PentaxModelID'] && tags['PentaxModelID'].value === MODEL_ID.K3_III && tags['LevelInfo'];
84
93
  }
@@ -7,9 +7,6 @@
7
7
  import {getStringValueFromArray, getStringFromDataView, decompress, setProperty, getTagKey, objectAssign, COMPRESSION_METHOD_NONE, getHexDigitValue} from './utils.js';
8
8
  import TagDecoder from './tag-decoder.js';
9
9
  import {PNG_CHUNK_LENGTH_OFFSET, PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_DATA_OFFSET, PNG_CHUNK_TYPE_SIZE, TYPE_TEXT, TYPE_ITXT, TYPE_ZTXT} from './image-header-png.js';
10
- import Tags from './tags.js';
11
- import IptcTags from './iptc-tags.js';
12
- import Constants from './constants.js';
13
10
  import {NOOP_TAG_FILTER} from './tag-filter.js';
14
11
  import {addDecompressedValueAllowance, addDecompressedIptcAllowance, takeEmbeddedExifThumbnail} from './tags-helpers.js';
15
12
 
@@ -45,6 +42,12 @@ const MAX_LANGUAGE_TAG_LENGTH = 79;
45
42
  * from: `decompressed` when the chunk was compressed, `hasIptcBlock` when the
46
43
  * file has a `Raw profile type iptc` chunk. Returns the parsed groups the Exif
47
44
  * carries, keyed by group name. No groups are read when it is not passed.
45
+ * @param {{exif?: function(DataView, number, boolean, boolean, object, object): {tags: object, byteOrder: number}, iptc?: function(DataView, number, boolean, object, object): object}} [rawProfileReaders]
46
+ * Read the decoded `Raw profile type exif` and `Raw profile type iptc`
47
+ * profiles: `exif(dataView, tiffHeaderOffset, includeUnknown, computed,
48
+ * tagFilter, valueBudget)` as Tags.read and `iptc(dataView, offset,
49
+ * includeUnknown, tagFilter, valueBudget)` as IptcTags.read. A profile
50
+ * whose reader is missing is neither decoded nor read.
48
51
  * @returns {{readTags: object, embeddedExifTags: object|undefined, embeddedIptcTags: object|undefined, embeddedExifThumbnail: object|undefined, exifCarriedGroups: object|undefined, readTagsPromise: Promise<object[]>|undefined}}
49
52
  * `readTags`, the two embedded groups, `exifCarriedGroups` and
50
53
  * `embeddedExifThumbnail` come from uncompressed chunks and are ready at
@@ -65,7 +68,8 @@ function read(
65
68
  decompressConfig,
66
69
  valueBudget,
67
70
  getThumbnail,
68
- readCarriedGroups
71
+ readCarriedGroups,
72
+ rawProfileReaders = {}
69
73
  ) {
70
74
  const tags = {};
71
75
  let embeddedExifTags;
@@ -111,7 +115,8 @@ function read(
111
115
  embeddedExifThumbnail ? undefined : getThumbnail,
112
116
  readCarriedGroups,
113
117
  false,
114
- hasIptcProfile
118
+ hasIptcProfile,
119
+ rawProfileReaders
115
120
  );
116
121
  if (rawProfileTags.embeddedExifTags) {
117
122
  embeddedExifTags = objectAssign(embeddedExifTags || {}, rawProfileTags.embeddedExifTags);
@@ -138,7 +143,8 @@ function read(
138
143
  compressedThumbnailReader,
139
144
  readCarriedGroups,
140
145
  true,
141
- hasIptcProfile
146
+ hasIptcProfile,
147
+ rawProfileReaders
142
148
  )));
143
149
 
144
150
  return {
@@ -170,7 +176,7 @@ function parseTextChunk(dataView, offset, length, type) {
170
176
  let valueChars;
171
177
  let parsingState = STATE_KEYWORD;
172
178
  let compressionMethod = COMPRESSION_METHOD_NONE;
173
- const byteOffset = dataView.byteOffset || 0;
179
+ const byteOffset = dataView.byteOffset;
174
180
  const chunkEnd = Math.min(offset + length, dataView.byteLength);
175
181
 
176
182
  for (let i = 0; i < length && offset + i < dataView.byteLength; i++) {
@@ -183,9 +189,7 @@ function parseTextChunk(dataView, offset, length, type) {
183
189
  continue;
184
190
  } else if (parsingState === STATE_TEXT) {
185
191
  const slice = dataView.buffer.slice(byteOffset + offset + i, byteOffset + offset + length);
186
- // On the Node Buffer wrapper, slice() returns a Buffer, which DataView
187
- // rejects. Uint8Array copies a Buffer and leaves an ArrayBuffer as is.
188
- valueChars = new DataView(new Uint8Array(slice).buffer);
192
+ valueChars = new DataView(slice);
189
193
  break;
190
194
  }
191
195
  const byte = dataView.getUint8(offset + i);
@@ -216,17 +220,17 @@ function isRawProfileTag({name, value}) {
216
220
  return isExifGroupTag(name, value) || isIptcGroupTag(name, value);
217
221
  }
218
222
 
219
- function getTagsFromTextTag({name, value, description}, includeUnknown, computed, tagFilter, valueBudget, getThumbnail, readCarriedGroups, isDecompressed, hasIptcProfile) {
223
+ function getTagsFromTextTag({name, value, description}, includeUnknown, computed, tagFilter, valueBudget, getThumbnail, readCarriedGroups, isDecompressed, hasIptcProfile, rawProfileReaders) {
220
224
  try {
221
- if (Constants.USE_EXIF && isExifGroupTag(name, value)) {
222
- if (!tagFilter.shouldParseGroup('exif')) {
225
+ if (isExifGroupTag(name, value)) {
226
+ if (!rawProfileReaders.exif || !tagFilter.shouldParseGroup('exif')) {
223
227
  return {};
224
228
  }
225
229
  const exifDataView = decodeRawData(value);
226
230
  if (isDecompressed) {
227
231
  addDecompressedValueAllowance(valueBudget, exifDataView.byteLength);
228
232
  }
229
- const {tags: embeddedExifTags, byteOrder} = Tags.read(
233
+ const {tags: embeddedExifTags, byteOrder} = rawProfileReaders.exif(
230
234
  exifDataView,
231
235
  EXIF_OFFSET,
232
236
  includeUnknown,
@@ -253,8 +257,8 @@ function getTagsFromTextTag({name, value, description}, includeUnknown, computed
253
257
  result.embeddedExifThumbnail = thumbnail;
254
258
  }
255
259
  return result;
256
- } else if (Constants.USE_IPTC && isIptcGroupTag(name, value)) {
257
- if (!tagFilter.shouldParseGroup('iptc')) {
260
+ } else if (isIptcGroupTag(name, value)) {
261
+ if (!rawProfileReaders.iptc || !tagFilter.shouldParseGroup('iptc')) {
258
262
  return {};
259
263
  }
260
264
  const iptcDataView = decodeRawData(value);
@@ -262,7 +266,7 @@ function getTagsFromTextTag({name, value, description}, includeUnknown, computed
262
266
  addDecompressedIptcAllowance(valueBudget, iptcDataView.byteLength);
263
267
  }
264
268
  return {
265
- embeddedIptcTags: IptcTags.read(
269
+ embeddedIptcTags: rawProfileReaders.iptc(
266
270
  iptcDataView,
267
271
  0,
268
272
  includeUnknown,
@@ -270,7 +274,7 @@ function getTagsFromTextTag({name, value, description}, includeUnknown, computed
270
274
  valueBudget
271
275
  )
272
276
  };
273
- } else if (name && !isExifGroupTag(name, value) && !isIptcGroupTag(name, value)) {
277
+ } else if (name) {
274
278
  if (!tagFilter.shouldParseGroup('png')) {
275
279
  return {};
276
280
  }
@@ -175,12 +175,7 @@ export default {
175
175
  }
176
176
  return 'Unknown';
177
177
  },
178
- FocalLengthIn35mmFilm(value) {
179
- if (value === 0) {
180
- return 'Unknown';
181
- }
182
- return value + ' mm';
183
- },
178
+ FocalLengthIn35mmFilm,
184
179
  SceneCaptureType(value) {
185
180
  if (value === 0) {
186
181
  return 'Standard';
@@ -237,3 +232,10 @@ function getComponentText(component) {
237
232
  return 'B';
238
233
  }
239
234
  }
235
+
236
+ export function FocalLengthIn35mmFilm(value) {
237
+ if (value === 0) {
238
+ return 'Unknown';
239
+ }
240
+ return value + ' mm';
241
+ }
package/src/tag-names.js CHANGED
@@ -3,7 +3,6 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import {objectAssign} from './utils.js';
6
- import Constants from './constants.js';
7
6
  import TagNames0thIfd from './tag-names-0th-ifd.js';
8
7
  import TagNamesExifIfd from './tag-names-exif-ifd.js';
9
8
  import TagNamesGpsIfd from './tag-names-gps-ifd.js';
@@ -11,25 +10,37 @@ import TagNamesInteroperabilityIfd from './tag-names-interoperability-ifd.js';
11
10
  import TagNamesMpfIfd from './tag-names-mpf-ifd.js';
12
11
  import TagNamesCanonIfd from './tag-names-canon-ifd.js';
13
12
  import TagNamesPentaxIfd from './tag-names-pentax-ifd.js';
13
+ import {
14
+ IFD_TYPE_0TH,
15
+ IFD_TYPE_1ST,
16
+ IFD_TYPE_EXIF,
17
+ IFD_TYPE_GPS,
18
+ IFD_TYPE_INTEROPERABILITY,
19
+ IFD_TYPE_MPF,
20
+ IFD_TYPE_CANON,
21
+ IFD_TYPE_PENTAX
22
+ } from './ifd-types.js';
14
23
 
15
- const tagNames0thExifIfds = Constants.USE_EXIF ? objectAssign({}, TagNames0thIfd, TagNamesExifIfd) : {};
24
+ const tagNames0thExifIfds = objectAssign({}, TagNames0thIfd, TagNamesExifIfd);
16
25
 
17
- export const IFD_TYPE_0TH = '0th';
18
- export const IFD_TYPE_1ST = '1st';
19
- export const IFD_TYPE_EXIF = 'exif';
20
- export const IFD_TYPE_GPS = 'gps';
21
- export const IFD_TYPE_INTEROPERABILITY = 'interoperability';
22
- export const IFD_TYPE_MPF = 'mpf';
23
- export const IFD_TYPE_CANON = 'canon';
24
- export const IFD_TYPE_PENTAX = 'pentax';
26
+ export {
27
+ IFD_TYPE_0TH,
28
+ IFD_TYPE_1ST,
29
+ IFD_TYPE_EXIF,
30
+ IFD_TYPE_GPS,
31
+ IFD_TYPE_INTEROPERABILITY,
32
+ IFD_TYPE_MPF,
33
+ IFD_TYPE_CANON,
34
+ IFD_TYPE_PENTAX
35
+ };
25
36
 
26
37
  export default {
27
38
  [IFD_TYPE_0TH]: tagNames0thExifIfds,
28
- [IFD_TYPE_1ST]: Constants.USE_EXIF ? TagNames0thIfd : {},
39
+ [IFD_TYPE_1ST]: TagNames0thIfd,
29
40
  [IFD_TYPE_EXIF]: tagNames0thExifIfds,
30
- [IFD_TYPE_GPS]: Constants.USE_EXIF ? TagNamesGpsIfd : {},
31
- [IFD_TYPE_INTEROPERABILITY]: Constants.USE_EXIF ? TagNamesInteroperabilityIfd : {},
32
- [IFD_TYPE_MPF]: Constants.USE_MPF ? TagNamesMpfIfd : {},
33
- [IFD_TYPE_CANON]: Constants.USE_MAKER_NOTES ? TagNamesCanonIfd : {},
34
- [IFD_TYPE_PENTAX]: Constants.USE_MAKER_NOTES ? TagNamesPentaxIfd : {},
41
+ [IFD_TYPE_GPS]: TagNamesGpsIfd,
42
+ [IFD_TYPE_INTEROPERABILITY]: TagNamesInteroperabilityIfd,
43
+ [IFD_TYPE_MPF]: TagNamesMpfIfd,
44
+ [IFD_TYPE_CANON]: TagNamesCanonIfd,
45
+ [IFD_TYPE_PENTAX]: TagNamesPentaxIfd,
35
46
  };