Skip to content

Commit

Permalink
refactor: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Aug 30, 2020
1 parent e4efc95 commit 0f96bba
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,30 @@ const processImg = (img, cb) =>
})

const jimpWrapper = cb => {
return through.obj(async (img, _, callback) => {
try {
if (img.isNull()) {
return callback(null, img)
}

if (img.isStream()) {
return callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'))
}
return through.obj((img, _, callback) => {
if (img.isNull()) {
return callback(null, img)
}

if (typeof cb !== 'function') {
return callback(
new PluginError(PLUGIN_NAME, `Argument '${cb}' is not a function`)
)
}
if (img.isStream()) {
return callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'))
}

const data = await processImg(img, cb)
img.contents = Buffer.from(data)
callback(null, img)
} catch (err) {
callback(new PluginError(PLUGIN_NAME, err))
if (typeof cb !== 'function') {
return callback(
new PluginError(PLUGIN_NAME, `Argument '${cb}' is not a function`)
)
}

;(async () => {
try {
const data = await processImg(img, cb)
img.contents = Buffer.from(data)
callback(null, img)
} catch (err) {
callback(new PluginError(PLUGIN_NAME, err))
}
})()
})
}

Expand Down

0 comments on commit 0f96bba

Please sign in to comment.