Skip to content

Commit

Permalink
Added check for empty prefix to default to forward slash
Browse files Browse the repository at this point in the history
Cleaned up formatting
  • Loading branch information
JoeDoyle23 committed Aug 6, 2014
1 parent 1e37f89 commit e797b70
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 18 deletions.
131 changes: 131 additions & 0 deletions .jscsrc
@@ -0,0 +1,131 @@
{
"requireCurlyBraces": [
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowMultipleVarDecl": true,
"requireBlocksOnNewline": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": "allButReserved",
"requireDotNotation": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": [
"?",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"disallowSpaceBeforeBinaryOperators": [","],
"requireSpaceBeforeBinaryOperators": [
"?",
"+",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"disallowSpaceAfterPrefixUnaryOperators": ["!"],
"requireSpaceAfterBinaryOperators": [
"?",
"+",
"/",
"*",
":",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"disallowKeywords": ["with"],
"disallowMultipleLineStrings": true,
"disallowMultipleLineBreaks": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": "\"",
"validateIndentation": "\t",
"disallowTrailingWhitespace": true,
"disallowKeywordsOnNewLine": ["else", "catch"],
"requireLineFeedAtFileEnd": true,
"safeContextKeyword": ["self","PushDevice"],
"disallowYodaConditions": true
}
15 changes: 15 additions & 0 deletions .jshintrc
@@ -0,0 +1,15 @@
{
"quotmark": "double",
"eqnull": true,
"node": true,
"smarttabs": true,
"globals": {
"describe": false,
"beforeEach": false,
"before": false,
"inject": false,
"after": false,
"afterEach": false,
"it": false
}
}
38 changes: 22 additions & 16 deletions index.js
Expand Up @@ -16,7 +16,7 @@ var Client = module.exports = function (config) {
}
};

Client.prototype.getFile = function(uri, headers, callback) {
Client.prototype.getFile = function (uri, headers, callback) {
var self = this;

if (!callback && typeof(headers) == "function") {
Expand All @@ -30,7 +30,7 @@ Client.prototype.getFile = function(uri, headers, callback) {
}
function bad(e) {
cancelLocalListeners();
if(e.code === "ENOENT") {
if (e.code === "ENOENT") {
stream.statusCode = 404;
stream.headers = {};
return callback(null, stream);
Expand All @@ -46,7 +46,7 @@ Client.prototype.getFile = function(uri, headers, callback) {
stream.on("readable", good);
};

Client.prototype.putFile = function(from, to, headers, callback) {
Client.prototype.putFile = function (from, to, headers, callback) {
var self = this;

if (typeof(callback) == "undefined") {
Expand All @@ -57,27 +57,28 @@ Client.prototype.putFile = function(from, to, headers, callback) {
utils.checkToPath(self.config.bucket + to, cb);
}, function (cb) {
fs.stat(from, cb);
}], function(err) {
}], function (err) {
if (err) {
return callback(err);
}
var r = fs.createReadStream(from),
w = fs.createWriteStream(self.config.bucket + to);
w.on("finish", function() {
var r = fs.createReadStream(from);
var w = fs.createWriteStream(self.config.bucket + to);

w.on("finish", function () {
callback(null, {headers:{}, statusCode:201});
});
w.on("error", function(e) {
w.on("error", function (e) {
callback(null, {headers:{}, statusCode:404});
});
r.pipe(w);
});
};

Client.prototype.putBuffer = function(buffer, to, headers, callback) {
Client.prototype.putBuffer = function (buffer, to, headers, callback) {
var self = this;

utils.checkToPath(self.config.bucket + to, function() {
fs.writeFile(self.config.bucket + to, buffer, function(err) {
utils.checkToPath(self.config.bucket + to, function () {
fs.writeFile(self.config.bucket + to, buffer, function (err) {
if (err) {
return callback(err);
}
Expand All @@ -87,18 +88,18 @@ Client.prototype.putBuffer = function(buffer, to, headers, callback) {
});
};

Client.prototype.deleteFile = function(file, callback) {
Client.prototype.deleteFile = function (file, callback) {
var self = this;

fs.unlink(self.config.bucket + file, function(err) {
fs.unlink(self.config.bucket + file, function (err) {
return callback(null, {headers:{}, statusCode: err ? 404 : 204});
});
};

Client.prototype.copyFile = function(from, to, callback) {
Client.prototype.copyFile = function (from, to, callback) {
var self = this;

utils.checkToPath(self.config.bucket + to, function() {
utils.checkToPath(self.config.bucket + to, function () {
var readStream = fs.createReadStream(self.config.bucket + from);
var writeStream = fs.createWriteStream(self.config.bucket + to);
var isDone = false;
Expand All @@ -124,6 +125,11 @@ Client.prototype.copyFile = function(from, to, callback) {

Client.prototype.list = function (options, cb) {
var self = this;

if (options.prefix === "") {
options.prefix = "/";
}

async.waterfall([
function (cb) {
if (!options.prefix) {
Expand Down Expand Up @@ -154,6 +160,6 @@ Client.prototype.list = function (options, cb) {
], cb);
};

module.exports.createClient = function(config) {
module.exports.createClient = function (config) {
return new Client(config);
};
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "faux-knox",
"version": "0.1.12",
"version": "0.1.13",
"description": "Mock requests to knox module using file system",
"main": "index.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/AppPress/node-faux-knox/issues"
},
"devDependencies": {
"mocha": "~1.21.3",
"mocha": "~1.21.4",
"should": "~4.0.4"
},
"dependencies": {
Expand Down

0 comments on commit e797b70

Please sign in to comment.