Skip to content

Commit 1551e19

Browse files
committed
Refactor parseMetaData calls.
1 parent 7461cc7 commit 1551e19

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

js/load-image-meta.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,22 @@
5555
}
5656
}
5757

58-
// Parses image metadata and calls the callback with an object argument
59-
// with the following properties:
60-
// * imageHead: The complete image head as ArrayBuffer (Uint8Array for IE10)
61-
// The options argument accepts an object and supports the following
62-
// properties:
63-
// * maxMetaDataSize: Defines the maximum number of bytes to parse.
64-
// * disableImageHead: Disables creating the imageHead property.
65-
loadImage.parseMetaData = function (file, callback, options, data) {
58+
/**
59+
* Parses image metadata and calls the callback with an object argument
60+
* with the following property:
61+
* - imageHead: The complete image head as ArrayBuffer
62+
* The options argument accepts an object and supports the following
63+
* properties:
64+
* - maxMetaDataSize: Defines the maximum number of bytes to parse.
65+
* - disableImageHead: Disables creating the imageHead property.
66+
*
67+
* @param {Blob} file Blob object
68+
* @param {Function} callback Callback fynction
69+
* @param {object} [options] Parsing options
70+
* @param {object} [data] Result data object
71+
* @returns {Promise|undefined} Returns Promise if no callback is provided.
72+
*/
73+
function parseMetaData(file, callback, options, data) {
6674
var that = this
6775
/**
6876
* Promise executor
@@ -197,11 +205,11 @@
197205
loadImage.replaceHead = function (blob, head, callback) {
198206
var options = { maxMetaDataSize: 256, disableMetaDataParsers: true }
199207
if (!callback && loadImage.global.Promise) {
200-
return loadImage.parseMetaData(blob, options).then(function (data) {
208+
return parseMetaData(blob, options).then(function (data) {
201209
return replaceJPEGHead(blob, data.imageHead, head)
202210
})
203211
}
204-
loadImage.parseMetaData(
212+
parseMetaData(
205213
blob,
206214
function (data) {
207215
callback(replaceJPEGHead(blob, data.imageHead, head))
@@ -214,7 +222,7 @@
214222
loadImage.transform = function (img, options, callback, file, data) {
215223
if (loadImage.requiresMetaData(options)) {
216224
data = data || {} // eslint-disable-line no-param-reassign
217-
loadImage.parseMetaData(
225+
parseMetaData(
218226
file,
219227
function (result) {
220228
if (result !== data) {
@@ -238,4 +246,6 @@
238246
originalTransform.apply(loadImage, arguments)
239247
}
240248
}
249+
250+
loadImage.parseMetaData = parseMetaData
241251
})

0 commit comments

Comments
 (0)