exifreader 4.1.0 → 4.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "Library that parses Exif metadata in images.",
5
5
  "author": "Mattias Wallander <mattias@wallander.eu>",
6
6
  "repository": {
@@ -47,14 +47,12 @@ function isFilePathOrURL(data) {
47
47
  }
48
48
 
49
49
  function loadFile(filename) {
50
- if (typeof window !== 'undefined') {
50
+ if (typeof fetch !== 'undefined') {
51
51
  return browserFetchRemoteFile(filename);
52
52
  }
53
53
 
54
54
  if (/^https?:\/\//.test(filename)) {
55
- return nodeFetchRemoteFile(filename).then((buffer) => {
56
- return buffer;
57
- });
55
+ return nodeFetchRemoteFile(filename);
58
56
  }
59
57
 
60
58
  return loadLocalFile(filename);
@@ -229,6 +227,7 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
229
227
  if (expanded) {
230
228
  tags.xmp = readXmpTags;
231
229
  } else {
230
+ delete readXmpTags._raw;
232
231
  tags = objectAssign({}, tags, readXmpTags);
233
232
  }
234
233
  }
@@ -267,6 +266,7 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
267
266
  if (expanded) {
268
267
  tags.xmp = readTags;
269
268
  } else {
269
+ delete readTags._raw;
270
270
  tags = objectAssign({}, tags, readTags);
271
271
  }
272
272
  }
@@ -11,6 +11,10 @@ export default {
11
11
  };
12
12
 
13
13
  function isHeicFile(dataView) {
14
+ if (!dataView) {
15
+ return false;
16
+ }
17
+
14
18
  const HEIC_ID = 'ftyp';
15
19
  const HEIC_ID_OFFSET = 4;
16
20
  const HEIC_MAJOR_BRANDS = ['heic', 'heix', 'hevc', 'hevx', 'heim', 'heis', 'hevm', 'hevs', 'mif1'];
@@ -50,7 +50,7 @@ const APP1_XMP_EXTENDED_IDENTIFIER = 'http://ns.adobe.com/xmp/extension/\x00';
50
50
  const APP13_IPTC_IDENTIFIER = 'Photoshop 3.0';
51
51
 
52
52
  function isJpegFile(dataView) {
53
- return (dataView.byteLength >= MIN_JPEG_DATA_BUFFER_LENGTH) && (dataView.getUint16(0) === JPEG_ID);
53
+ return !!dataView && (dataView.byteLength >= MIN_JPEG_DATA_BUFFER_LENGTH) && (dataView.getUint16(0) === JPEG_ID);
54
54
  }
55
55
 
56
56
  function findJpegOffsets(dataView) {
@@ -19,7 +19,7 @@ const PNG_CHUNK_DATA_OFFSET = PNG_CHUNK_LENGTH_SIZE + PNG_CHUNK_TYPE_SIZE;
19
19
  const PNG_XMP_PREFIX = 'XML:com.adobe.xmp\x00';
20
20
 
21
21
  function isPngFile(dataView) {
22
- return getStringFromDataView(dataView, 0, PNG_ID.length) === PNG_ID;
22
+ return !!dataView && getStringFromDataView(dataView, 0, PNG_ID.length) === PNG_ID;
23
23
  }
24
24
 
25
25
  function findPngOffsets(dataView) {
@@ -13,7 +13,7 @@ export default {
13
13
  function isTiffFile(dataView) {
14
14
  const MIN_TIFF_DATA_BUFFER_LENGTH = 4;
15
15
 
16
- return (dataView.byteLength >= MIN_TIFF_DATA_BUFFER_LENGTH) && hasTiffMarker(dataView);
16
+ return !!dataView && (dataView.byteLength >= MIN_TIFF_DATA_BUFFER_LENGTH) && hasTiffMarker(dataView);
17
17
  }
18
18
 
19
19
  function hasTiffMarker(dataView) {
@@ -16,7 +16,7 @@ function isWebpFile(dataView) {
16
16
  const WEBP_MARKER_OFFSET = 8;
17
17
  const WEBP_MARKER = 'WEBP';
18
18
 
19
- return getStringFromDataView(dataView, RIFF_ID_OFFSET, RIFF_ID.length) === RIFF_ID
19
+ return !!dataView && getStringFromDataView(dataView, RIFF_ID_OFFSET, RIFF_ID.length) === RIFF_ID
20
20
  && getStringFromDataView(dataView, WEBP_MARKER_OFFSET, WEBP_MARKER.length) === WEBP_MARKER;
21
21
  }
22
22
 
package/src/xmp-tags.js CHANGED
@@ -50,7 +50,8 @@ function combineChunks(dataView, chunks) {
50
50
 
51
51
  function readTags(tags, chunkDataView) {
52
52
  try {
53
- const doc = getDocument(chunkDataView);
53
+ const {doc, raw} = getDocument(chunkDataView);
54
+ tags._raw = (tags._raw || '') + raw;
54
55
  const rdf = getRDF(doc);
55
56
 
56
57
  return objectAssign(tags, parseXMPObject(convertToObject(rdf, true)));
@@ -74,7 +75,10 @@ function getDocument(chunkDataView) {
74
75
  throw new Error(doc.documentElement.textContent);
75
76
  }
76
77
 
77
- return doc;
78
+ return {
79
+ doc,
80
+ raw: xmlString,
81
+ };
78
82
  }
79
83
 
80
84
  function trimXmlSource(xmlSource) {