Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

faux-knox-2

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faux-knox-2 - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

36

index.js

@@ -47,5 +47,9 @@ var fs = require("fs");

Client.prototype.putFile = function(from, to, callback) {
Client.prototype.putFile = function(from, to, headers, callback) {
var self = this;
if (typeof(callback) == "undefined") {
callback = headers;
}
async.series([function (cb) {

@@ -116,3 +120,33 @@ utils.checkToPath(self.config.bucket + to, cb);

};
Client.prototype.list = function (options, cb) {
var self = this;
async.waterfall([
function (cb) {
if (!options.prefix) {
return cb(new Error("A path prefix must be specified!"));
}
cb();
},
function (cb) {
utils.checkToPath(self.config.bucket + options.prefix, function () {
cb();
});
},
function (cb) {
var walk = require("walk");
var walker = walk.walk(self.config.bucket + options.prefix);
var files = [];
walker.on("file", function (root, stat, next) {
files.push({Key: root + stat.name});
next();
});
walker.on("end", function () {
cb(null, {Contents: files});
});
}
], cb);
};
module.exports.createClient = function(config) {

@@ -119,0 +153,0 @@ return new Client(config);

5

package.json
{
"name": "faux-knox-2",
"version": "0.1.7",
"version": "0.1.8",
"description": "Mock requests to knox module using file system",

@@ -31,4 +31,5 @@ "main": "index.js",

"mkdirp": "~0.3.5",
"rimraf": "~2.2.1"
"rimraf": "~2.2.1",
"walk": "^2.3.1"
}
}

@@ -46,2 +46,24 @@ var should = require("should");

});
it("should pipe a file", function(done) {
client.getFile("path/to/test.json", null, function(err, cres) {
cres.should.have.property("headers").be.a("object");
cres.should.have.property("statusCode", 200);
function getFile(callback) {
fs.mkdirSync("./test_files/from");
var stream = fs.createWriteStream("./test_files/from/test.json");
cres.on("end", callback);
cres.on("error", callback);
cres.pipe(stream);
}
function getFSFile(callback) {
fs.readFile("./test_files/path/to/test.json", callback);
}
async.parallel([getFile, getFSFile], function(err, results) {
results[0] = fs.readFileSync("./test_files/from/test.json");
should.strictEqual(results[0].toString(), results[1].toString());
done();
});
});
});
it("should not get a file", function(done) {

@@ -65,2 +87,12 @@ client.getFile("path/to/nofile.txt", null, function(err, cres) {

});
it("should put a file into bucket with headers", function(done) {
client.putFile("./test_files/put/fort_knox_tank.jpg", "from/fort/knox/super_tank_headers.jpg", {header: "value"}, function(err, res) {
res.should.have.property("headers").be.a("object");
res.should.have.property("statusCode", 201);
fs.exists("./test_files/from/fort/knox/super_tank_headers.jpg", function(existy) {
should.strictEqual(existy, true);
done();
});
});
});
it("should not put a file into bucket", function(done) {

@@ -67,0 +99,0 @@ client.putFile("./i/dont/exists.txt", "/dev/null", function(err, res) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc