faux-knox-2
Advanced tools
Comparing version 0.1.6 to 0.1.7
26
index.js
@@ -89,3 +89,29 @@ var fs = require("fs"); | ||
}; | ||
Client.prototype.copyFile = function(from, to, callback) { | ||
var self = this; | ||
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; | ||
var done = function (err) { | ||
if (isDone) return; | ||
isDone = true; | ||
if (err) { | ||
return callback(err); | ||
} | ||
return callback(null, {headers:{}, statusCode:201}); | ||
}; | ||
readStream.on("error", done); | ||
writeStream.on("error", done); | ||
writeStream.on("close", function () { | ||
done(); | ||
}); | ||
readStream.pipe(writeStream); | ||
}); | ||
}; | ||
module.exports.createClient = function(config) { | ||
@@ -92,0 +118,0 @@ return new Client(config); |
{ | ||
"name": "faux-knox-2", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Mock requests to knox module using file system", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
20
test.js
@@ -109,2 +109,22 @@ var should = require("should"); | ||
}); | ||
describe("copyFile", function () { | ||
before(function(done) { | ||
client.putFile("./test_files/put/fort_knox_tank.jpg", "to/a/new/path/here/tank.jpg", done); | ||
}); | ||
it("should copy a file", function (done) { | ||
function fileExists(value, callback) { | ||
fs.exists("./test_files/to/a/new/path/here/tankCopy.jpg", function(exists) { | ||
should.strictEqual(exists, value); | ||
callback(); | ||
}); | ||
} | ||
fileExists(false, function() { | ||
client.copyFile("to/a/new/path/here/tank.jpg", "to/a/new/path/here/tankCopy.jpg", function(err, res) { | ||
res.should.have.property("headers").be.a("object"); | ||
res.should.have.property("statusCode", 201); | ||
fileExists(true, done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
after(function(done) { | ||
@@ -111,0 +131,0 @@ async.each(["./test_files/from", "./test_files/to"], rimraf, done); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10646
9
244