exifreader 4.8.1 → 4.9.1
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 +26 -1
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +6 -6
- package/package.json +1 -1
- package/src/exif-reader.js +30 -12
package/exif-reader.d.ts
CHANGED
|
@@ -177,14 +177,14 @@ interface MPFImageTags {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer): Tags & XmpTags & IccTags;
|
|
180
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: {expanded: true}): ExpandedTags;
|
|
181
|
-
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: {expanded?: false}): Tags & XmpTags & IccTags;
|
|
180
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: {expanded: true, includeUnknown?: boolean, length?: number}): ExpandedTags;
|
|
181
|
+
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: {expanded?: false, includeUnknown?: boolean, length?: number}): Tags & XmpTags & IccTags;
|
|
182
182
|
export function load(data: string | File): Promise<Tags & XmpTags & IccTags>;
|
|
183
|
-
export function load(data: string | File, options: {expanded: true}): Promise<ExpandedTags>;
|
|
184
|
-
export function load(data: string | File, options: {expanded?: false}): Promise<Tags & XmpTags & IccTags>;
|
|
183
|
+
export function load(data: string | File, options: {expanded: true, includeUnknown?: boolean, length?: number}): Promise<ExpandedTags>;
|
|
184
|
+
export function load(data: string | File, options: {expanded?: false, includeUnknown?: boolean, length?: number}): Promise<Tags & XmpTags & IccTags>;
|
|
185
185
|
export function loadView(data: DataView): Tags & XmpTags & IccTags;
|
|
186
|
-
export function loadView(data: DataView, options: {expanded: true}): ExpandedTags;
|
|
187
|
-
export function loadView(data: DataView, options: {expanded?: false}): Tags & XmpTags & IccTags;
|
|
186
|
+
export function loadView(data: DataView, options: {expanded: true, includeUnknown?: boolean}): ExpandedTags;
|
|
187
|
+
export function loadView(data: DataView, options: {expanded?: false, includeUnknown?: boolean}): Tags & XmpTags & IccTags;
|
|
188
188
|
|
|
189
189
|
export namespace errors {
|
|
190
190
|
export class MetadataMissingError extends Error {}
|
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 {
|