mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Ensure consistent, correct detection of input opts #2118
This commit is contained in:
18
lib/input.js
18
lib/input.js
@@ -4,6 +4,17 @@ const color = require('color');
|
||||
const is = require('./is');
|
||||
const sharp = require('../build/Release/sharp.node');
|
||||
|
||||
/**
|
||||
* Extract input options, if any, from an object.
|
||||
* @private
|
||||
*/
|
||||
function _inputOptionsFromObject (obj) {
|
||||
const { raw, density, limitInputPixels, sequentialRead, failOnError } = obj;
|
||||
return [raw, density, limitInputPixels, sequentialRead, failOnError].some(is.defined)
|
||||
? { raw, density, limitInputPixels, sequentialRead, failOnError }
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Object containing input and input-related options.
|
||||
* @private
|
||||
@@ -23,12 +34,12 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
|
||||
// Plain Object descriptor, e.g. create
|
||||
inputOptions = input;
|
||||
if (is.plainObject(inputOptions.raw) || is.bool(inputOptions.failOnError)) {
|
||||
// Raw Stream
|
||||
if (_inputOptionsFromObject(inputOptions)) {
|
||||
// Stream with options
|
||||
inputDescriptor.buffer = [];
|
||||
}
|
||||
} else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) {
|
||||
// Stream
|
||||
// Stream without options
|
||||
inputDescriptor.buffer = [];
|
||||
} else {
|
||||
throw new Error(`Unsupported input '${input}' of type ${typeof input}${
|
||||
@@ -337,6 +348,7 @@ function stats (callback) {
|
||||
module.exports = function (Sharp) {
|
||||
Object.assign(Sharp.prototype, {
|
||||
// Private
|
||||
_inputOptionsFromObject,
|
||||
_createInputDescriptor,
|
||||
_write,
|
||||
_flattenBufferIn,
|
||||
|
||||
Reference in New Issue
Block a user