diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..b4d9626 --- /dev/null +++ b/.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 +} diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..4f4e2cd --- /dev/null +++ b/.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 + } +} diff --git a/index.js b/index.js index 6b1057f..2fba288 100644 --- a/index.js +++ b/index.js @@ -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") { @@ -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); @@ -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") { @@ -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); } @@ -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; @@ -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) { @@ -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); }; diff --git a/package.json b/package.json index 2db900d..b96433a 100644 --- a/package.json +++ b/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": { @@ -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": {