From e1185d39a6e5b4d205a014db4fdb0fa709bc8e63 Mon Sep 17 00:00:00 2001 From: Sadiq Ramzan Date: Thu, 21 Jun 2018 17:57:42 +0400 Subject: [PATCH] Default callback function --- lib/client.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index f73981d..20c737a 100644 --- a/lib/client.js +++ b/lib/client.js @@ -119,10 +119,11 @@ Client.prototype.mkdir = function(dir, attrs, callback) { if (attrs) { attrs.mode = getFolderAttr(process.platform, attrs); } - + var self = this; var dirs = []; var exists = false; + callback = getCallback(self, callback); this.sftp(function(err, sftp) { if (err) { @@ -163,6 +164,7 @@ Client.prototype.mkdir = function(dir, attrs, callback) { Client.prototype.write = function(options, callback) { var destination = options.destination; destination = unixy(destination); + callback = getCallback(self, callback); var attrs = options.attrs; var content = options.content; @@ -256,6 +258,8 @@ Client.prototype.upload = function(src, dest, callback) { dest = unixy(dest); var self = this; + + callback = getCallback(self, callback); async.waterfall([ function(callback) { @@ -291,6 +295,8 @@ Client.prototype.upload = function(src, dest, callback) { Client.prototype.download = function(src, dest, callback) { var self = this; + + callback = getCallback(self, callback); self.sftp(function(err,sftp){ if (err) { @@ -332,3 +338,12 @@ function getFolderAttr(platform, attrs) { return attrs.mode || DEFAULT_MODE; } } + +function getCallback(self, callback) { + if (_.isFunction(callback)) { + return callback; + } + return function defaultCallback(error) { + self.emit('error', error); + } +}