mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Simplify 'this' in IO pipeline using arrow functions
This commit is contained in:
@@ -650,6 +650,7 @@ function _setBooleanOption (key, val) {
|
||||
* @private
|
||||
*/
|
||||
function _read () {
|
||||
/* istanbul ignore else */
|
||||
if (!this.options.streamOut) {
|
||||
this.options.streamOut = true;
|
||||
this._pipeline();
|
||||
@@ -662,14 +663,13 @@ function _read () {
|
||||
* @private
|
||||
*/
|
||||
function _pipeline (callback) {
|
||||
const that = this;
|
||||
if (typeof callback === 'function') {
|
||||
// output=file/buffer
|
||||
if (this._isStreamInput()) {
|
||||
// output=file/buffer, input=stream
|
||||
this.on('finish', function () {
|
||||
that._flattenBufferIn();
|
||||
sharp.pipeline(that.options, callback);
|
||||
this.on('finish', () => {
|
||||
this._flattenBufferIn();
|
||||
sharp.pipeline(this.options, callback);
|
||||
});
|
||||
} else {
|
||||
// output=file/buffer, input=file/buffer
|
||||
@@ -680,41 +680,31 @@ function _pipeline (callback) {
|
||||
// output=stream
|
||||
if (this._isStreamInput()) {
|
||||
// output=stream, input=stream
|
||||
if (this.streamInFinished) {
|
||||
this.once('finish', () => {
|
||||
this._flattenBufferIn();
|
||||
sharp.pipeline(this.options, function (err, data, info) {
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
that.emit('error', err);
|
||||
this.emit('error', err);
|
||||
} else {
|
||||
that.emit('info', info);
|
||||
that.push(data);
|
||||
this.emit('info', info);
|
||||
this.push(data);
|
||||
}
|
||||
that.push(null);
|
||||
});
|
||||
} else {
|
||||
this.on('finish', function () {
|
||||
that._flattenBufferIn();
|
||||
sharp.pipeline(that.options, function (err, data, info) {
|
||||
if (err) {
|
||||
that.emit('error', err);
|
||||
} else {
|
||||
that.emit('info', info);
|
||||
that.push(data);
|
||||
}
|
||||
that.push(null);
|
||||
});
|
||||
this.push(null);
|
||||
});
|
||||
});
|
||||
if (this.streamInFinished) {
|
||||
this.emit('finish');
|
||||
}
|
||||
} else {
|
||||
// output=stream, input=file/buffer
|
||||
sharp.pipeline(this.options, function (err, data, info) {
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
that.emit('error', err);
|
||||
this.emit('error', err);
|
||||
} else {
|
||||
that.emit('info', info);
|
||||
that.push(data);
|
||||
this.emit('info', info);
|
||||
this.push(data);
|
||||
}
|
||||
that.push(null);
|
||||
this.push(null);
|
||||
});
|
||||
}
|
||||
return this;
|
||||
@@ -722,15 +712,15 @@ function _pipeline (callback) {
|
||||
// output=promise
|
||||
if (this._isStreamInput()) {
|
||||
// output=promise, input=stream
|
||||
return new Promise(function (resolve, reject) {
|
||||
that.on('finish', function () {
|
||||
that._flattenBufferIn();
|
||||
sharp.pipeline(that.options, function (err, data, info) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.once('finish', () => {
|
||||
this._flattenBufferIn();
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
if (that.options.resolveWithObject) {
|
||||
resolve({ data: data, info: info });
|
||||
if (this.options.resolveWithObject) {
|
||||
resolve({ data, info });
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
@@ -740,12 +730,12 @@ function _pipeline (callback) {
|
||||
});
|
||||
} else {
|
||||
// output=promise, input=file/buffer
|
||||
return new Promise(function (resolve, reject) {
|
||||
sharp.pipeline(that.options, function (err, data, info) {
|
||||
return new Promise((resolve, reject) => {
|
||||
sharp.pipeline(this.options, (err, data, info) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
if (that.options.resolveWithObject) {
|
||||
if (this.options.resolveWithObject) {
|
||||
resolve({ data: data, info: info });
|
||||
} else {
|
||||
resolve(data);
|
||||
|
||||
Reference in New Issue
Block a user