exifreader 4.8.0 → 4.9.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 +24 -1
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +1 -1
- package/src/exif-reader.js +30 -12
- package/src/image-header-jpeg.js +11 -0
package/package.json
CHANGED
package/src/exif-reader.js
CHANGED
|
@@ -34,7 +34,7 @@ export const errors = exifErrors;
|
|
|
34
34
|
|
|
35
35
|
export function load(data, options) {
|
|
36
36
|
if (isFilePathOrURL(data)) {
|
|
37
|
-
return loadFile(data).then((fileContents) => loadFromData(fileContents, options));
|
|
37
|
+
return loadFile(data, options).then((fileContents) => loadFromData(fileContents, options));
|
|
38
38
|
}
|
|
39
39
|
if (isBrowserFileObject(data)) {
|
|
40
40
|
return loadFileObject(data).then((fileContents) => loadFromData(fileContents, options));
|
|
@@ -46,26 +46,39 @@ function isFilePathOrURL(data) {
|
|
|
46
46
|
return typeof data === 'string';
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
function loadFile(filename) {
|
|
49
|
+
function loadFile(filename, options) {
|
|
50
50
|
if (/^https?:\/\//.test(filename)) {
|
|
51
51
|
if (typeof fetch !== 'undefined') {
|
|
52
|
-
return browserFetchRemoteFile(filename);
|
|
52
|
+
return browserFetchRemoteFile(filename, options);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
return nodeFetchRemoteFile(filename);
|
|
55
|
+
return nodeFetchRemoteFile(filename, options);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
return loadLocalFile(filename);
|
|
58
|
+
return loadLocalFile(filename, options);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function browserFetchRemoteFile(url) {
|
|
62
|
-
|
|
61
|
+
function browserFetchRemoteFile(url, {length} = {}) {
|
|
62
|
+
const options = {method: 'GET'};
|
|
63
|
+
if (Number.isInteger(length) && length >= 0) {
|
|
64
|
+
options.headers = {
|
|
65
|
+
range: `bytes=0-${length - 1}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return fetch(url, options).then((response) => response.arrayBuffer());
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
function nodeFetchRemoteFile(url) {
|
|
71
|
+
function nodeFetchRemoteFile(url, {length} = {}) {
|
|
66
72
|
return new Promise((resolve, reject) => {
|
|
73
|
+
const options = {};
|
|
74
|
+
if (Number.isInteger(length) && length >= 0) {
|
|
75
|
+
options.headers = {
|
|
76
|
+
range: `bytes=0-${length - 1}`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
67
80
|
const get = requireNodeGet(url);
|
|
68
|
-
get(url, (response) => {
|
|
81
|
+
get(url, options, (response) => {
|
|
69
82
|
if ((response.statusCode >= 200) && (response.statusCode <= 299)) {
|
|
70
83
|
const data = [];
|
|
71
84
|
response.on('data', (chunk) => data.push(Buffer.from(chunk)));
|
|
@@ -86,7 +99,7 @@ function requireNodeGet(url) {
|
|
|
86
99
|
return __non_webpack_require__('http').get;
|
|
87
100
|
}
|
|
88
101
|
|
|
89
|
-
function loadLocalFile(filename) {
|
|
102
|
+
function loadLocalFile(filename, {length} = {}) {
|
|
90
103
|
return new Promise((resolve, reject) => {
|
|
91
104
|
const fs = requireNodeFs();
|
|
92
105
|
fs.open(filename, (error, fd) => {
|
|
@@ -97,8 +110,13 @@ function loadLocalFile(filename) {
|
|
|
97
110
|
if (error) {
|
|
98
111
|
reject(error);
|
|
99
112
|
} else {
|
|
100
|
-
const
|
|
101
|
-
|
|
113
|
+
const size = Math.min(stat.size, length !== undefined ? length : stat.size);
|
|
114
|
+
const buffer = Buffer.alloc(size);
|
|
115
|
+
const options = {
|
|
116
|
+
buffer,
|
|
117
|
+
length: size
|
|
118
|
+
};
|
|
119
|
+
fs.read(fd, options, (error) => {
|
|
102
120
|
if (error) {
|
|
103
121
|
reject(error);
|
|
104
122
|
} else {
|
package/src/image-header-jpeg.js
CHANGED
|
@@ -43,6 +43,10 @@ const APP13_MARKER = 0xffed;
|
|
|
43
43
|
const APP15_MARKER = 0xffef;
|
|
44
44
|
const COMMENT_MARKER = 0xfffe;
|
|
45
45
|
|
|
46
|
+
// Any number of fill bytes can be placed before an app marker. It's actually the first 0xff that is the
|
|
47
|
+
// fill byte and the next 0xff is either another fill byte or the first half of the next app marker.
|
|
48
|
+
const FILL_BYTE = 0xffff;
|
|
49
|
+
|
|
46
50
|
const APP0_JFIF_IDENTIFIER = 'JFIF';
|
|
47
51
|
const APP1_EXIF_IDENTIFIER = 'Exif';
|
|
48
52
|
const APP1_XMP_IDENTIFIER = 'http://ns.adobe.com/xap/1.0/\x00';
|
|
@@ -107,6 +111,9 @@ function findJpegOffsets(dataView) {
|
|
|
107
111
|
mpfDataOffset = appMarkerPosition + MPF_DATA_OFFSET;
|
|
108
112
|
} else if (isAppMarker(dataView, appMarkerPosition)) {
|
|
109
113
|
fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
|
|
114
|
+
} else if (isFillByte(dataView, appMarkerPosition)) {
|
|
115
|
+
appMarkerPosition++;
|
|
116
|
+
continue;
|
|
110
117
|
} else {
|
|
111
118
|
break;
|
|
112
119
|
}
|
|
@@ -216,3 +223,7 @@ function isAppMarker(dataView, appMarkerPosition) {
|
|
|
216
223
|
|| (appMarker === DRI_MARKER)
|
|
217
224
|
|| (appMarker === SOS_MARKER);
|
|
218
225
|
}
|
|
226
|
+
|
|
227
|
+
function isFillByte(dataView, appMarkerPosition) {
|
|
228
|
+
return dataView.getUint16(appMarkerPosition) === FILL_BYTE;
|
|
229
|
+
}
|