exifreader 4.54.0 → 4.55.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 +398 -27
- package/bin/analyze.js +139 -9
- package/bin/build-pages.js +21 -35
- package/bin/cli.js +81 -13
- package/bin/generate-tag-modules.js +287 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +213 -38
- package/package.json +71 -11
- package/src/composable/brand.js +10 -0
- package/src/composable/composition-tag-filter.js +97 -0
- package/src/composable/composition.js +195 -0
- package/src/composable/core.d.ts +148 -0
- package/src/composable/core.js +526 -0
- package/src/composable/exif-block-reader.js +197 -0
- package/src/composable/formats/avif.js +19 -0
- package/src/composable/formats/gif.js +28 -0
- package/src/composable/formats/heic.js +19 -0
- package/src/composable/formats/iso-bmff-file-reader.js +14 -0
- package/src/composable/formats/jpeg.js +55 -0
- package/src/composable/formats/jxl.js +30 -0
- package/src/composable/formats/png.js +187 -0
- package/src/composable/formats/tiff.js +18 -0
- package/src/composable/formats/webp.js +28 -0
- package/src/composable/formats/xml.js +18 -0
- package/src/composable/formats.d.ts +17 -0
- package/src/composable/formats.js +17 -0
- package/src/composable/group-helpers.js +129 -0
- package/src/composable/groups/canon.js +26 -0
- package/src/composable/groups/composite.js +43 -0
- package/src/composable/groups/exif.js +48 -0
- package/src/composable/groups/gps.js +75 -0
- package/src/composable/groups/icc.js +52 -0
- package/src/composable/groups/iptc.js +86 -0
- package/src/composable/groups/maker-notes.js +21 -0
- package/src/composable/groups/mpf.js +25 -0
- package/src/composable/groups/pentax.js +34 -0
- package/src/composable/groups/photoshop.js +18 -0
- package/src/composable/groups/thumbnail.js +131 -0
- package/src/composable/groups/xmp.js +118 -0
- package/src/composable/groups.d.ts +20 -0
- package/src/composable/groups.js +105 -0
- package/src/composable/iptc-block-reader.js +44 -0
- package/src/composable/read-view.js +165 -0
- package/src/composable/tag-binding-name.js +17 -0
- package/src/composable/tags/exif.d.ts +295 -0
- package/src/composable/tags/exif.js +396 -0
- package/src/composable/tags/iptc.d.ts +84 -0
- package/src/composable/tags/iptc.js +109 -0
- package/src/composable/value-budget.js +24 -0
- package/src/composite.js +2 -2
- package/src/decompression.js +60 -0
- package/src/engine.js +50 -106
- package/src/errors.js +8 -2
- package/src/exif-reader.d.ts +8 -0
- package/src/exif-reader.js +112 -763
- package/src/file-loaders.js +74 -1
- package/src/file-tags.js +9 -9
- package/src/image-header.js +13 -47
- package/src/iptc-tag-names-descriptions.js +334 -0
- package/src/iptc-tag-names.js +50 -306
- package/src/iptc-tags.js +41 -27
- package/src/jfif-tags.js +9 -9
- package/src/load-auto.js +2 -2
- package/src/loadview-pipeline.js +52 -192
- package/src/node-require.js +15 -2
- package/src/png-text-tags.js +5 -3
- package/src/tag-filter-config.js +24 -15
- package/src/tag-filter.js +15 -3
- package/src/tag-names-0th-ifd-descriptions.js +232 -0
- package/src/tag-names-0th-ifd.js +49 -173
- package/src/tag-names-common.js +263 -211
- package/src/tag-names-exif-ifd-descriptions.js +249 -0
- package/src/tag-names-exif-ifd.js +55 -187
- package/src/tag-names-gps-ifd-descriptions.js +156 -0
- package/src/tag-names-gps-ifd.js +39 -146
- package/src/tag-names-utils.js +28 -3
- package/src/tags-helpers.js +6 -2
- package/src/types.js +2 -0
- package/src/unsupported-format-error.js +21 -0
- package/src/utils.js +22 -85
- package/src/xmp-tag-names.js +42 -21
- package/webpack.config.js +1 -1
package/src/utils.js
CHANGED
|
@@ -383,79 +383,6 @@ export function deferInit(object, key, initializer) {
|
|
|
383
383
|
});
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
-
export function dataUriToBuffer(dataUri) {
|
|
387
|
-
const commaIndex = dataUri.indexOf(',');
|
|
388
|
-
const header = dataUri.substring(0, commaIndex);
|
|
389
|
-
const data = dataUri.substring(commaIndex + 1);
|
|
390
|
-
|
|
391
|
-
if (header.indexOf(';base64') !== -1) {
|
|
392
|
-
const base64 = percentDecodeBase64Payload(data);
|
|
393
|
-
if (typeof atob !== 'undefined') {
|
|
394
|
-
return binaryStringToArrayBuffer(atob(base64));
|
|
395
|
-
}
|
|
396
|
-
if (typeof Buffer === 'undefined') {
|
|
397
|
-
return undefined;
|
|
398
|
-
}
|
|
399
|
-
if (typeof Buffer.from !== 'undefined') { // eslint-disable-line no-undef
|
|
400
|
-
return Buffer.from(base64, 'base64'); // eslint-disable-line no-undef
|
|
401
|
-
}
|
|
402
|
-
return new Buffer(base64, 'base64'); // eslint-disable-line no-undef
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
return percentDecodeToBytes(data).buffer;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// WHATWG data: URL processing percent-decodes the body before the forgiving-base64 decode.
|
|
409
|
-
// A non-ASCII payload can never be valid base64, so it goes to the decoder unchanged.
|
|
410
|
-
function percentDecodeBase64Payload(data) {
|
|
411
|
-
if (data.indexOf('%') === -1 || /[\u0080-\uffff]/.test(data)) {
|
|
412
|
-
return data;
|
|
413
|
-
}
|
|
414
|
-
return getByteString(percentDecodeToBytes(data));
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
function binaryStringToArrayBuffer(string) {
|
|
418
|
-
const bytes = new Uint8Array(string.length);
|
|
419
|
-
for (let i = 0; i < string.length; i++) {
|
|
420
|
-
bytes[i] = string.charCodeAt(i);
|
|
421
|
-
}
|
|
422
|
-
return bytes.buffer;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// WHATWG URL "string percent-decode" (used for data: URLs, RFC 2397): UTF-8 encode, then each %XX is one byte.
|
|
426
|
-
function percentDecodeToBytes(string) {
|
|
427
|
-
const byteString = /[\u0080-\uffff]/.test(string) ? unescape(encodeURIComponent(string)) : string;
|
|
428
|
-
const bytes = new Uint8Array(byteString.length - 2 * countPercentEscapes(byteString));
|
|
429
|
-
let byteIndex = 0;
|
|
430
|
-
for (let i = 0; i < byteString.length; i++) {
|
|
431
|
-
if (isPercentEscape(byteString, i)) {
|
|
432
|
-
bytes[byteIndex++] = getHexDigitValue(byteString.charCodeAt(i + 1)) * 16 + getHexDigitValue(byteString.charCodeAt(i + 2));
|
|
433
|
-
i += 2;
|
|
434
|
-
} else {
|
|
435
|
-
bytes[byteIndex++] = byteString.charCodeAt(i);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return bytes;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function countPercentEscapes(byteString) {
|
|
442
|
-
let count = 0;
|
|
443
|
-
for (let i = 0; i < byteString.length; i++) {
|
|
444
|
-
if (isPercentEscape(byteString, i)) {
|
|
445
|
-
count++;
|
|
446
|
-
i += 2;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return count;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function isPercentEscape(byteString, index) {
|
|
453
|
-
return byteString.charCodeAt(index) === 0x25
|
|
454
|
-
&& index + 2 < byteString.length
|
|
455
|
-
&& getHexDigitValue(byteString.charCodeAt(index + 1)) !== -1
|
|
456
|
-
&& getHexDigitValue(byteString.charCodeAt(index + 2)) !== -1;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
386
|
/**
|
|
460
387
|
* @param {number} charCode
|
|
461
388
|
* @returns {number} The value of the hex digit, or -1 for any other character.
|
|
@@ -502,12 +429,14 @@ const MAX_CUSTOM_OUTPUT_LENGTH = (1024 * 1024 * 1024) - 1;
|
|
|
502
429
|
* @returns {Object} {brotli, deflate, maxDecompressedSize, budget: {remaining, warned, failed, pending}}
|
|
503
430
|
*/
|
|
504
431
|
export function withDecompressBudget(decompressConfig) {
|
|
505
|
-
|
|
432
|
+
const config = {
|
|
506
433
|
brotli: decompressConfig ? decompressConfig.brotli : undefined,
|
|
507
434
|
deflate: decompressConfig ? decompressConfig.deflate : undefined,
|
|
508
|
-
maxDecompressedSize: decompressConfig ? decompressConfig.maxDecompressedSize : undefined
|
|
509
|
-
budget: {remaining: getMaxDecompressedSize(decompressConfig), warned: false, failed: false, pending: undefined}
|
|
435
|
+
maxDecompressedSize: decompressConfig ? decompressConfig.maxDecompressedSize : undefined
|
|
510
436
|
};
|
|
437
|
+
// From the copy, so a getter cannot make the enforced limit differ from the one decompress names.
|
|
438
|
+
config.budget = {remaining: getMaxDecompressedSize(config), warned: false, failed: false, pending: undefined};
|
|
439
|
+
return config;
|
|
511
440
|
}
|
|
512
441
|
|
|
513
442
|
/**
|
|
@@ -531,7 +460,7 @@ export function decompress(dataView, compressionMethod, encoding, returnType = '
|
|
|
531
460
|
const maxDecompressedSize = getMaxDecompressedSize(decompressConfig);
|
|
532
461
|
const budget = getDecompressBudget(decompressConfig, maxDecompressedSize);
|
|
533
462
|
|
|
534
|
-
if (compressionMethod !== COMPRESSION_METHOD_NONE && budget
|
|
463
|
+
if (compressionMethod !== COMPRESSION_METHOD_NONE && isBudgetExhausted(budget)) {
|
|
535
464
|
return rejectExceedsMax(budget, maxDecompressedSize);
|
|
536
465
|
}
|
|
537
466
|
|
|
@@ -589,8 +518,9 @@ function getDecompressType(compressionMethod) {
|
|
|
589
518
|
}
|
|
590
519
|
|
|
591
520
|
function getMaxDecompressedSize(decompressConfig) {
|
|
592
|
-
|
|
593
|
-
|
|
521
|
+
const maxDecompressedSize = decompressConfig ? decompressConfig.maxDecompressedSize : undefined;
|
|
522
|
+
if (typeof maxDecompressedSize === 'number' && !isNaN(maxDecompressedSize)) {
|
|
523
|
+
return maxDecompressedSize;
|
|
594
524
|
}
|
|
595
525
|
return DEFAULT_MAX_DECOMPRESSED_SIZE;
|
|
596
526
|
}
|
|
@@ -602,6 +532,11 @@ function getDecompressBudget(decompressConfig, maxDecompressedSize) {
|
|
|
602
532
|
return {remaining: maxDecompressedSize, warned: false, failed: false, pending: undefined};
|
|
603
533
|
}
|
|
604
534
|
|
|
535
|
+
// Also true for a NaN budget, so no bad charge can lift the limit.
|
|
536
|
+
function isBudgetExhausted(budget) {
|
|
537
|
+
return !(budget.remaining >= 0);
|
|
538
|
+
}
|
|
539
|
+
|
|
605
540
|
function decompressWithCustomFunctionInTurn(customFn, dataView, returnType, encoding, budget, maxDecompressedSize) {
|
|
606
541
|
// The executor runs now, so a synchronous result is charged before this returns and a throw becomes a rejection.
|
|
607
542
|
return new Promise((resolve) => {
|
|
@@ -618,7 +553,7 @@ function queueCustomFunctionCall(customFn, dataView, returnType, encoding, budge
|
|
|
618
553
|
// Copy now: the input can view the caller's buffer, which may be reused once load() returns.
|
|
619
554
|
const inputCopy = new DataView(dataView.buffer.slice(dataView.byteOffset, dataView.byteOffset + dataView.byteLength));
|
|
620
555
|
return holdTurn(budget, previousCall.then(() => {
|
|
621
|
-
if (budget
|
|
556
|
+
if (isBudgetExhausted(budget)) {
|
|
622
557
|
return rejectExceedsMax(budget, maxDecompressedSize);
|
|
623
558
|
}
|
|
624
559
|
return decompressWithCustomFunction(customFn, inputCopy, returnType, encoding, budget, maxDecompressedSize);
|
|
@@ -683,7 +618,7 @@ export function isThenable(value) {
|
|
|
683
618
|
|
|
684
619
|
function chargeCustomResult(result, returnType, encoding, budget, maxDecompressedSize) {
|
|
685
620
|
budget.remaining -= getResultByteLength(result);
|
|
686
|
-
if (budget
|
|
621
|
+
if (isBudgetExhausted(budget)) {
|
|
687
622
|
return rejectExceedsMax(budget, maxDecompressedSize);
|
|
688
623
|
}
|
|
689
624
|
return convertCustomResult(result, returnType, encoding);
|
|
@@ -727,7 +662,7 @@ function readBoundedDecompressedStream(dataView, format, budget, maxDecompressed
|
|
|
727
662
|
// Charge before checking and never give bytes back, so an
|
|
728
663
|
// exceeded budget stays exhausted for every later block.
|
|
729
664
|
budget.remaining -= value.byteLength;
|
|
730
|
-
if (budget
|
|
665
|
+
if (isBudgetExhausted(budget)) {
|
|
731
666
|
return reader.cancel().then(() => rejectExceedsMax(budget, maxDecompressedSize));
|
|
732
667
|
}
|
|
733
668
|
chunks.push(value);
|
|
@@ -754,10 +689,12 @@ function decodeBuffer(arrayBuffer, returnType, encoding) {
|
|
|
754
689
|
}
|
|
755
690
|
|
|
756
691
|
function getResultByteLength(result) {
|
|
757
|
-
|
|
758
|
-
|
|
692
|
+
const byteLength = result ? result.byteLength : undefined;
|
|
693
|
+
if (typeof byteLength !== 'number') {
|
|
694
|
+
return 0;
|
|
759
695
|
}
|
|
760
|
-
|
|
696
|
+
// A NaN or negative length would give bytes back, so it uses up the budget instead.
|
|
697
|
+
return byteLength >= 0 ? byteLength : Infinity;
|
|
761
698
|
}
|
|
762
699
|
|
|
763
700
|
function rejectExceedsMax(budget, maxDecompressedSize) {
|
package/src/xmp-tag-names.js
CHANGED
|
@@ -2,7 +2,28 @@
|
|
|
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
|
|
5
|
+
import {
|
|
6
|
+
getApertureValueDescription,
|
|
7
|
+
getColorSpaceDescription,
|
|
8
|
+
getComponentsConfigurationDescription,
|
|
9
|
+
getContrastDescription,
|
|
10
|
+
getCustomRenderedDescription,
|
|
11
|
+
getExposureModeDescription,
|
|
12
|
+
getExposureProgramDescription,
|
|
13
|
+
getExposureTimeDescription,
|
|
14
|
+
getFNumberDescription,
|
|
15
|
+
getFocalLengthDescription,
|
|
16
|
+
getFocalPlaneResolutionUnitDescription,
|
|
17
|
+
getMeteringModeDescription,
|
|
18
|
+
getResolutionUnitDescription,
|
|
19
|
+
getSaturationDescription,
|
|
20
|
+
getSceneCaptureTypeDescription,
|
|
21
|
+
getSharpnessDescription,
|
|
22
|
+
getShutterSpeedValueDescription,
|
|
23
|
+
getWhiteBalanceDescription,
|
|
24
|
+
getXResolutionDescription,
|
|
25
|
+
getYResolutionDescription
|
|
26
|
+
} from './tag-names-common.js';
|
|
6
27
|
|
|
7
28
|
export default {
|
|
8
29
|
'tiff:Orientation'(value) {
|
|
@@ -32,39 +53,39 @@ export default {
|
|
|
32
53
|
}
|
|
33
54
|
return value;
|
|
34
55
|
},
|
|
35
|
-
'tiff:ResolutionUnit': (value) =>
|
|
36
|
-
'tiff:XResolution': (value) => fraction(
|
|
37
|
-
'tiff:YResolution': (value) => fraction(
|
|
38
|
-
'exif:ApertureValue': (value) => fraction(
|
|
56
|
+
'tiff:ResolutionUnit': (value) => getResolutionUnitDescription(parseInt(value, 10)),
|
|
57
|
+
'tiff:XResolution': (value) => fraction(getXResolutionDescription, value),
|
|
58
|
+
'tiff:YResolution': (value) => fraction(getYResolutionDescription, value),
|
|
59
|
+
'exif:ApertureValue': (value) => fraction(getApertureValueDescription, value),
|
|
39
60
|
'exif:GPSLatitude': calculateGPSValue,
|
|
40
61
|
'exif:GPSLongitude': calculateGPSValue,
|
|
41
|
-
'exif:FNumber': (value) => fraction(
|
|
42
|
-
'exif:FocalLength': (value) => fraction(
|
|
43
|
-
'exif:FocalPlaneResolutionUnit': (value) =>
|
|
44
|
-
'exif:ColorSpace': (value) =>
|
|
62
|
+
'exif:FNumber': (value) => fraction(getFNumberDescription, value),
|
|
63
|
+
'exif:FocalLength': (value) => fraction(getFocalLengthDescription, value),
|
|
64
|
+
'exif:FocalPlaneResolutionUnit': (value) => getFocalPlaneResolutionUnitDescription(parseInt(value, 10)),
|
|
65
|
+
'exif:ColorSpace': (value) => getColorSpaceDescription(parseNumber(value)),
|
|
45
66
|
'exif:ComponentsConfiguration'(value, description) {
|
|
46
67
|
if (/^\d, \d, \d, \d$/.test(description)) {
|
|
47
68
|
const numbers = description.split(', ').map((number) => parseInt(number, 10));
|
|
48
|
-
return
|
|
69
|
+
return getComponentsConfigurationDescription(numbers);
|
|
49
70
|
}
|
|
50
71
|
return description;
|
|
51
72
|
},
|
|
52
|
-
'exif:Contrast': (value) =>
|
|
53
|
-
'exif:CustomRendered': (value) =>
|
|
54
|
-
'exif:ExposureMode': (value) =>
|
|
55
|
-
'exif:ExposureProgram': (value) =>
|
|
73
|
+
'exif:Contrast': (value) => getContrastDescription(parseInt(value, 10)),
|
|
74
|
+
'exif:CustomRendered': (value) => getCustomRenderedDescription(parseInt(value, 10)),
|
|
75
|
+
'exif:ExposureMode': (value) => getExposureModeDescription(parseInt(value, 10)),
|
|
76
|
+
'exif:ExposureProgram': (value) => getExposureProgramDescription(parseInt(value, 10)),
|
|
56
77
|
'exif:ExposureTime'(value) {
|
|
57
78
|
if (isFraction(value)) {
|
|
58
|
-
return
|
|
79
|
+
return getExposureTimeDescription(value.split('/').map((number) => parseInt(number, 10)));
|
|
59
80
|
}
|
|
60
81
|
return value;
|
|
61
82
|
},
|
|
62
|
-
'exif:MeteringMode': (value) =>
|
|
63
|
-
'exif:Saturation': (value) =>
|
|
64
|
-
'exif:SceneCaptureType': (value) =>
|
|
65
|
-
'exif:Sharpness': (value) =>
|
|
66
|
-
'exif:ShutterSpeedValue': (value) => fraction(
|
|
67
|
-
'exif:WhiteBalance': (value) =>
|
|
83
|
+
'exif:MeteringMode': (value) => getMeteringModeDescription(parseInt(value, 10)),
|
|
84
|
+
'exif:Saturation': (value) => getSaturationDescription(parseInt(value, 10)),
|
|
85
|
+
'exif:SceneCaptureType': (value) => getSceneCaptureTypeDescription(parseInt(value, 10)),
|
|
86
|
+
'exif:Sharpness': (value) => getSharpnessDescription(parseInt(value, 10)),
|
|
87
|
+
'exif:ShutterSpeedValue': (value) => fraction(getShutterSpeedValueDescription, value),
|
|
88
|
+
'exif:WhiteBalance': (value) => getWhiteBalanceDescription(parseInt(value, 10))
|
|
68
89
|
};
|
|
69
90
|
|
|
70
91
|
function fraction(func, value) {
|
package/webpack.config.js
CHANGED