exifreader 4.46.0 → 4.47.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/README.md +78 -12
- package/bin/TagFilterPlugin.js +23 -14
- package/bin/analyze.js +345 -0
- package/bin/build.js +10 -2
- package/bin/cli.js +449 -23
- package/bin/custom-build-marker.js +78 -0
- package/bin/verify-build.js +147 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +2 -2
- package/src/canon-tags.js +4 -2
- package/src/exif-reader.js +30 -11
- package/src/file-loaders.js +146 -14
- package/src/image-header-iso-bmff-iloc.js +5 -2
- package/src/image-header-iso-bmff.js +10 -0
- package/src/loadview-pipeline.js +54 -39
- package/src/mpf-tags.js +4 -2
- package/src/pentax-tags.js +4 -2
- package/src/photoshop-tags.js +2 -2
- package/src/png-text-tags.js +95 -62
- package/src/tag-decoder.js +10 -10
- package/src/tag-filter.js +2 -0
- package/src/tag-names-0th-ifd.js +13 -1
- package/src/tags-helpers.js +71 -22
- package/src/tags.js +12 -4
- package/src/types.js +0 -5
- package/src/utils.js +111 -17
- package/src/xmp-namespaces.js +20 -5
- package/src/xmp-tags.js +259 -162
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
const MAX_SHOWN_LENGTH = 80;
|
|
6
|
+
|
|
7
|
+
module.exports = {diffResults, verifyImages, loadCustomParser};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Compare two expanded ExifReader results.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} full The result from the full parser.
|
|
13
|
+
* @param {Object} custom The result from the custom build.
|
|
14
|
+
* @returns {string[]} One line per difference, each starting with the path of
|
|
15
|
+
* the value, for example "exif.DateTime" or "mpf.Images[0].image".
|
|
16
|
+
*/
|
|
17
|
+
function diffResults(full, custom) {
|
|
18
|
+
const differences = [];
|
|
19
|
+
compareValues(full, custom, '', differences);
|
|
20
|
+
return differences;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function compareValues(full, custom, valuePath, differences) {
|
|
24
|
+
const fullBytes = bytesOf(full);
|
|
25
|
+
const customBytes = bytesOf(custom);
|
|
26
|
+
if (fullBytes && customBytes) {
|
|
27
|
+
if (!sameBytes(fullBytes, customBytes)) {
|
|
28
|
+
differences.push(`${valuePath}: bytes differ`);
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!fullBytes && !customBytes && isObject(full) && isObject(custom) && Array.isArray(full) === Array.isArray(custom)) {
|
|
33
|
+
compareKeys(full, custom, valuePath, differences);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!Object.is(full, custom)) {
|
|
37
|
+
differences.push(`${valuePath}: ${shown(full)} in the full parser, ${shown(custom)} in the custom build`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function bytesOf(value) {
|
|
42
|
+
if (Object.prototype.toString.call(value) === '[object ArrayBuffer]') {
|
|
43
|
+
return new Uint8Array(value);
|
|
44
|
+
}
|
|
45
|
+
if (ArrayBuffer.isView(value)) {
|
|
46
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function sameBytes(bytes0, bytes1) {
|
|
52
|
+
if (bytes0.length !== bytes1.length) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return bytes0.every((byte, index) => byte === bytes1[index]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isObject(value) {
|
|
59
|
+
return value !== null && typeof value === 'object';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function compareKeys(full, custom, valuePath, differences) {
|
|
63
|
+
const isArray = Array.isArray(full);
|
|
64
|
+
for (const key of Object.keys(full)) {
|
|
65
|
+
const keyPath = childPath(valuePath, key, isArray);
|
|
66
|
+
if (Object.prototype.hasOwnProperty.call(custom, key)) {
|
|
67
|
+
compareValues(full[key], custom[key], keyPath, differences);
|
|
68
|
+
} else {
|
|
69
|
+
differences.push(`${keyPath}: missing from the custom build`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const key of Object.keys(custom)) {
|
|
73
|
+
if (!Object.prototype.hasOwnProperty.call(full, key)) {
|
|
74
|
+
differences.push(`${childPath(valuePath, key, isArray)}: only in the custom build`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function childPath(valuePath, key, isArray) {
|
|
80
|
+
if (isArray) {
|
|
81
|
+
return `${valuePath}[${key}]`;
|
|
82
|
+
}
|
|
83
|
+
return valuePath === '' ? key : `${valuePath}.${key}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function shown(value) {
|
|
87
|
+
const bytes = bytesOf(value);
|
|
88
|
+
if (bytes) {
|
|
89
|
+
return `<${bytes.length} bytes>`;
|
|
90
|
+
}
|
|
91
|
+
const text = value === undefined ? 'undefined' : JSON.stringify(value);
|
|
92
|
+
return text.length > MAX_SHOWN_LENGTH ? `${text.slice(0, MAX_SHOWN_LENGTH - 3)}...` : text;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Parse each file with the full parser and the custom build, using the same
|
|
97
|
+
* options on both sides, and compare the results.
|
|
98
|
+
*
|
|
99
|
+
* @param {string[]} paths Absolute file paths.
|
|
100
|
+
* @param {{fs: Object, fullParser: Object, customParser: Object, domParser: (Object|undefined)}} deps
|
|
101
|
+
* @returns {Promise<{results: {path: string, differences: string[]}[], skipped: {path: string, message: string}[]}>}
|
|
102
|
+
* Files that cannot be read, or that the full parser cannot parse, go to
|
|
103
|
+
* skipped.
|
|
104
|
+
*/
|
|
105
|
+
async function verifyImages(paths, deps) {
|
|
106
|
+
const results = [];
|
|
107
|
+
const skipped = [];
|
|
108
|
+
for (const filePath of paths) {
|
|
109
|
+
let buffer;
|
|
110
|
+
let full;
|
|
111
|
+
try {
|
|
112
|
+
buffer = deps.fs.readFileSync(filePath);
|
|
113
|
+
full = await deps.fullParser.load(buffer, parseOptions(deps.domParser));
|
|
114
|
+
} catch (error) {
|
|
115
|
+
skipped.push({path: filePath, message: error.message});
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
results.push({path: filePath, differences: await customDifferences(full, buffer, deps)});
|
|
119
|
+
}
|
|
120
|
+
return {results, skipped};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parseOptions(domParser) {
|
|
124
|
+
return {expanded: true, async: true, domParser};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function customDifferences(full, buffer, deps) {
|
|
128
|
+
let custom;
|
|
129
|
+
try {
|
|
130
|
+
custom = await deps.customParser.load(buffer, parseOptions(deps.domParser));
|
|
131
|
+
} catch (error) {
|
|
132
|
+
return [`the custom build failed: ${error.message}`];
|
|
133
|
+
}
|
|
134
|
+
return diffResults(full, custom);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Load the custom bundle, bypassing the require cache so a bundle rebuilt in
|
|
139
|
+
* this process is read again.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} distPath Absolute path of dist/exif-reader.js.
|
|
142
|
+
* @returns {Object} The ExifReader export of the bundle.
|
|
143
|
+
*/
|
|
144
|
+
function loadCustomParser(distPath) {
|
|
145
|
+
delete require.cache[require.resolve(distPath)];
|
|
146
|
+
return require(distPath);
|
|
147
|
+
}
|