exifreader 4.53.0 → 4.54.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/src/xml.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 {getStringFromDataView, pushMetadataBlock} from './utils.js';
5
+ import {getStringFromDataView, pushRange} from './utils.js';
6
6
 
7
7
  export default {
8
8
  isXMLFile,
@@ -30,24 +30,21 @@ function isXMLFile(dataView) {
30
30
  }
31
31
 
32
32
  /**
33
- * Finds the XMP chunk offset for a standalone XMP file.
33
+ * Reports a standalone XMP file as one xmp block covering the whole buffer.
34
34
  *
35
- * @param {DataView} dataView The data view to find offsets in.
36
- * @param {Array<Object>=} metadataBlocks Optional out-array. When provided,
37
- * receives one `xmp` block covering the whole buffer and gets a
35
+ * @param {DataView} dataView The data view to find blocks in.
36
+ * @param {Array<Object>=} ranges Optional out-array. When provided, receives
37
+ * one span covering the whole buffer, linked to the xmp block, and gets a
38
38
  * `truncated` property set to true if no XMP closing marker is found.
39
- * @returns {{xmpChunks: Array<{dataOffset: number, length: number}>}}
39
+ * @returns {Array<Object>} One xmp block with one chunk.
40
40
  */
41
- function findOffsets(dataView, metadataBlocks) {
42
- const xmpChunks = [];
43
- xmpChunks.push({dataOffset: XML_MARKER_OFFSET, length: dataView.byteLength});
44
- pushMetadataBlock(metadataBlocks, 'xmp', 0, dataView.byteLength);
45
- if (metadataBlocks) {
46
- metadataBlocks.truncated = !hasXmpClosingMarker(dataView);
41
+ function findOffsets(dataView, ranges) {
42
+ const block = {kind: 'xmp', chunks: [{dataOffset: XML_MARKER_OFFSET, length: dataView.byteLength}]};
43
+ pushRange(ranges, block, 0, dataView.byteLength);
44
+ if (ranges) {
45
+ ranges.truncated = !hasXmpClosingMarker(dataView);
47
46
  }
48
- return {
49
- xmpChunks,
50
- };
47
+ return [block];
51
48
  }
52
49
 
53
50
  function hasXmpClosingMarker(dataView) {
package/src/xmp-tags.js CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  import {decodeUtf8ByteString, getByteString, getTagKey, objectAssign, setProperty, tryDecodeUtf8ByteString} from './utils.js';
6
6
  import XmpTagNames from './xmp-tag-names.js';
7
- import DOMParser from './dom-parser.js';
8
7
  import TextDecoder from './text-decoder.js';
9
8
  import {isMissingNamespaceError, addMissingNamespaces} from './xmp-namespaces.js';
10
9
  import {exceedsMarkupBounds} from './xmp-element-depth.js';
@@ -48,20 +47,20 @@ class ParseError extends Error {
48
47
  }
49
48
  }
50
49
 
51
- function read(dataView, chunks, domParser) {
50
+ function read(dataView, chunks, domParser, getDomParser) {
52
51
  const tags = {};
53
52
 
54
53
  if (typeof dataView === 'string') {
55
- readTags(tags, dataView, domParser);
54
+ readTags(tags, dataView, domParser, getDomParser);
56
55
  return tags;
57
56
  }
58
57
 
59
58
  const [standardXmp, extendedXmp] = extractCompleteChunks(dataView, chunks);
60
59
 
61
- const hasStandardTags = readTags(tags, standardXmp, domParser);
60
+ const hasStandardTags = readTags(tags, standardXmp, domParser, getDomParser);
62
61
 
63
62
  if (extendedXmp) {
64
- const hasExtendedTags = readTags(tags, extendedXmp, domParser);
63
+ const hasExtendedTags = readTags(tags, extendedXmp, domParser, getDomParser);
65
64
 
66
65
  if (!hasStandardTags && !hasExtendedTags) {
67
66
  // Some writers are not spec-compliant in that they split an XMP
@@ -69,7 +68,7 @@ function read(dataView, chunks, domParser) {
69
68
  // XMP block. If we failed parsing both of the XMPs in the regular
70
69
  // way, we try to combine them to see if that works better.
71
70
  delete tags._raw;
72
- readTags(tags, combineChunks(dataView, chunks), domParser);
71
+ readTags(tags, combineChunks(dataView, chunks), domParser, getDomParser);
73
72
  }
74
73
  }
75
74
 
@@ -118,9 +117,9 @@ function getBoundedChunkBytes(dataView, chunk) {
118
117
  return new Uint8Array(dataView.buffer, byteOffset + start, end - start);
119
118
  }
120
119
 
121
- function readTags(tags, chunkDataView, domParser) {
120
+ function readTags(tags, chunkDataView, domParser, getDomParser) {
122
121
  try {
123
- const {doc, raw, decodeValue} = getDocument(chunkDataView, domParser);
122
+ const {doc, raw, decodeValue} = getDocument(chunkDataView, domParser, getDomParser);
124
123
  tags._raw = (tags._raw || '') + raw;
125
124
  const rdf = getRDF(doc);
126
125
 
@@ -138,8 +137,8 @@ function readTags(tags, chunkDataView, domParser) {
138
137
  }
139
138
  }
140
139
 
141
- function getDocument(chunkDataView, _domParser) {
142
- const {parser: domParser, warning} = DOMParser.get(_domParser);
140
+ function getDocument(chunkDataView, _domParser, getDomParser) {
141
+ const {parser: domParser, warning} = getDomParser(_domParser);
143
142
  if (!domParser) {
144
143
  console.warn(warning); // eslint-disable-line no-console
145
144
  throw new Error();