exifreader 4.22.1 → 4.23.2
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/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +4 -4
- package/src/exif-reader.js +2 -0
- package/src/icc-tags.js +1 -1
- package/src/image-header.js +5 -0
- package/src/png-text-tags.js +8 -1
- package/src/utils.js +3 -2
- package/src/xml.js +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.23.2",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"@babel/preset-env": "^7.23.2",
|
|
30
30
|
"@babel/register": "^7.22.15",
|
|
31
31
|
"@types/node": "^18.11.9",
|
|
32
|
-
"babel-loader": "^
|
|
32
|
+
"babel-loader": "^9.1.3",
|
|
33
33
|
"babel-plugin-rewire": "^1.2.0",
|
|
34
34
|
"chai": "^4.3.10",
|
|
35
35
|
"cross-env": "^7.0.3",
|
|
36
36
|
"cypress": "^13.3.2",
|
|
37
37
|
"eslint": "^8.52.0",
|
|
38
|
-
"eslint-plugin-cypress": "^
|
|
38
|
+
"eslint-plugin-cypress": "^3.0.2",
|
|
39
39
|
"husky": "^9.0.11",
|
|
40
40
|
"mocha": "^10.2.0",
|
|
41
41
|
"npm-run-all": "^4.1.5",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"typescript": "^5.2.2",
|
|
47
47
|
"webpack": "^5.89.0",
|
|
48
48
|
"webpack-cli": "^5.1.4",
|
|
49
|
-
"webpack-dev-server": "^
|
|
49
|
+
"webpack-dev-server": "^5.0.4"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "node bin/build.js",
|
package/src/exif-reader.js
CHANGED
package/src/icc-tags.js
CHANGED
|
@@ -35,7 +35,7 @@ function readCompressedIcc(dataView, iccData) {
|
|
|
35
35
|
return {};
|
|
36
36
|
}
|
|
37
37
|
const compressedDataView = new DataView(dataView.buffer.slice(iccData[0].offset, iccData[0].offset + iccData[0].length));
|
|
38
|
-
return decompress(compressedDataView, iccData[0].compressionMethod, 'dataview')
|
|
38
|
+
return decompress(compressedDataView, iccData[0].compressionMethod, 'utf-8', 'dataview')
|
|
39
39
|
.then(parseTags)
|
|
40
40
|
.catch(() => ({}));
|
|
41
41
|
}
|
package/src/image-header.js
CHANGED
|
@@ -10,6 +10,7 @@ import Heic from './image-header-heic.js';
|
|
|
10
10
|
import Avif from './image-header-avif.js';
|
|
11
11
|
import Webp from './image-header-webp.js';
|
|
12
12
|
import Gif from './image-header-gif.js';
|
|
13
|
+
import Xml from './xml.js';
|
|
13
14
|
import {objectAssign} from './utils.js';
|
|
14
15
|
|
|
15
16
|
export default {
|
|
@@ -45,6 +46,10 @@ function parseAppMarkers(dataView, async) {
|
|
|
45
46
|
return addFileType(Gif.findOffsets(dataView), 'gif', 'GIF');
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
if (Constants.USE_XMP && Xml.isXMLFile(dataView)) {
|
|
50
|
+
return addFileType(Xml.findOffsets(dataView), 'xml', 'XML');
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
throw new Error('Invalid image format');
|
|
49
54
|
}
|
|
50
55
|
|
package/src/png-text-tags.js
CHANGED
|
@@ -106,7 +106,7 @@ function getNameAndValue(dataView, offset, length, type, async) {
|
|
|
106
106
|
if (compressionMethod !== COMPRESSION_METHOD_NONE && !async) {
|
|
107
107
|
return {};
|
|
108
108
|
}
|
|
109
|
-
const decompressedValueChars = decompress(valueChars, compressionMethod);
|
|
109
|
+
const decompressedValueChars = decompress(valueChars, compressionMethod, getEncodingFromType(type));
|
|
110
110
|
if (decompressedValueChars instanceof Promise) {
|
|
111
111
|
return decompressedValueChars
|
|
112
112
|
.then((_decompressedValueChars) => constructTag(_decompressedValueChars, type, langChars, keywordChars))
|
|
@@ -142,6 +142,13 @@ function moveToNextState(type, parsingState) {
|
|
|
142
142
|
return STATE_TEXT;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
function getEncodingFromType(type) {
|
|
146
|
+
if (type === TYPE_TEXT || type === TYPE_ZTXT) {
|
|
147
|
+
return 'latin1';
|
|
148
|
+
}
|
|
149
|
+
return 'utf-8';
|
|
150
|
+
}
|
|
151
|
+
|
|
145
152
|
function constructTag(valueChars, type, langChars, keywordChars) {
|
|
146
153
|
const value = getValue(valueChars);
|
|
147
154
|
return {
|
package/src/utils.js
CHANGED
|
@@ -150,7 +150,7 @@ export function strRepeat(string, num) {
|
|
|
150
150
|
export const COMPRESSION_METHOD_NONE = undefined;
|
|
151
151
|
export const COMPRESSION_METHOD_DEFLATE = 0;
|
|
152
152
|
|
|
153
|
-
export function decompress(dataView, compressionMethod, returnType = 'string') {
|
|
153
|
+
export function decompress(dataView, compressionMethod, encoding, returnType = 'string') {
|
|
154
154
|
if (compressionMethod === COMPRESSION_METHOD_DEFLATE) {
|
|
155
155
|
if (typeof DecompressionStream === 'function') {
|
|
156
156
|
const decompressionStream = new DecompressionStream('deflate');
|
|
@@ -158,7 +158,8 @@ export function decompress(dataView, compressionMethod, returnType = 'string') {
|
|
|
158
158
|
if (returnType === 'dataview') {
|
|
159
159
|
return new Response(decompressedStream).arrayBuffer().then((arrayBuffer) => new DataView(arrayBuffer));
|
|
160
160
|
}
|
|
161
|
-
return new Response(decompressedStream).
|
|
161
|
+
return new Response(decompressedStream).arrayBuffer()
|
|
162
|
+
.then((buffer) => new TextDecoder(encoding).decode(buffer));
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
if (compressionMethod !== undefined) {
|
package/src/xml.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import {getStringFromDataView} from './utils.js';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
isXMLFile,
|
|
9
|
+
findOffsets
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const XML_MARKER_OFFSET = 0;
|
|
13
|
+
const XML_MARKER = '<?xpacket begin';
|
|
14
|
+
|
|
15
|
+
function isXMLFile(dataView) {
|
|
16
|
+
return !!dataView && getStringFromDataView(dataView, XML_MARKER_OFFSET, XML_MARKER.length) === XML_MARKER;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function findOffsets(dataView) {
|
|
20
|
+
const xmpChunks = [];
|
|
21
|
+
xmpChunks.push({dataOffset: XML_MARKER_OFFSET, length: dataView.byteLength});
|
|
22
|
+
return {
|
|
23
|
+
xmpChunks,
|
|
24
|
+
};
|
|
25
|
+
}
|