Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Default callback function #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}