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

s3fs

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

s3fs - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

42

lib/s3fs.js

@@ -66,3 +66,3 @@ /*

Bucket: this.bucket,
Key: this.path + s3Utils.toKey(name)
Key: s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(name)))
}).createReadStream();

@@ -72,3 +72,3 @@ };

S3fs.prototype.createWriteStream = function (name) {
return new S3WriteStream(this.s3, this.bucket, this.path + s3Utils.toKey(name));
return new S3WriteStream(this.s3, this.bucket, s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(name))));
};

@@ -79,3 +79,3 @@

var promise = new Promise(function (resolve) {
var key = self.path + s3Utils.toKey(name);
var key = s3Utils.toKey(s3Utils.joinPaths(self.path + s3Utils.toKey(name)));

@@ -121,3 +121,3 @@ if (directoryRegExp.test(key)) {

//TODO: Add support for Mode, which by some form of magic would translate to S3 permissions. Not sure how we would maintain the same FS interface and convert it to S3 for permissions.
var promise = putObject(this.s3, this.bucket, this.path + s3Utils.toKey(path) + '/');
var promise = putObject(this.s3, this.bucket, s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(path))) + '/');

@@ -155,3 +155,3 @@ if (!callback) {

S3fs.prototype.readdir = function (name, callback) {
var prefix = this.path + s3Utils.toKey(name);
var prefix = s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(name, this.bucket, this.path)));
// Make sure directories have a trailing slash.

@@ -183,7 +183,9 @@ if (prefix[prefix.length - 1] !== '/') {

if (options.encoding) {
options.ResponseContentEncoding = options.encoding;
options = extend(true, {
ResponseContentEncoding: options.encoding
}, options);
delete options.encoding;
}
var promise = getObject(this.s3, this.bucket, this.path + s3Utils.toKey(name, this.bucket, this.path), options);
var promise = getObject(this.s3, this.bucket, s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(name, this.bucket, this.path))), options);

@@ -202,3 +204,3 @@ if (!callback) {

S3fs.prototype.rmdir = function (path, callback) {
var promise = deleteObject(this.s3, this.bucket, this.path + s3Utils.toKey(path) + '/');
var promise = deleteObject(this.s3, this.bucket, s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(path))) + '/');

@@ -217,3 +219,3 @@ if (!callback) {

S3fs.prototype.unlink = function (name, callback) {
var promise = deleteObject(this.s3, this.bucket, this.path + s3Utils.toKey(name));
var promise = deleteObject(this.s3, this.bucket, s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(name, this.bucket, this.path))));

@@ -240,7 +242,9 @@ if (!callback) {

if (options.encoding) {
options.ContentEncoding = options.encoding;
options = extend(true, {
ContentEncoding: options.encoding
}, options);
delete options.encoding;
}
var promise = putObject(this.s3, this.bucket, this.path + s3Utils.toKey(name), data, options);
var promise = putObject(this.s3, this.bucket, s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(name, this.bucket, this.path))), data, options);

@@ -331,4 +335,4 @@ if (!callback) {

Bucket: self.bucket,
Key: self.path + s3Utils.toKey(destinationFile),
CopySource: [self.bucket, self.path + s3Utils.toKey(sourceFile)].join('/')
Key: s3Utils.toKey(s3Utils.joinPaths(self.path + s3Utils.toKey(destinationFile))),
CopySource: [self.bucket, s3Utils.toKey(s3Utils.joinPaths(self.path + s3Utils.toKey(sourceFile)))].join('/')
}, function (err) {

@@ -460,3 +464,3 @@ if (err) {

Bucket: self.bucket,
Key: self.path + s3Utils.toKey(path)
Key: s3Utils.toKey(s3Utils.joinPaths(self.path + s3Utils.toKey(path)))
}, function (err, data) {

@@ -506,3 +510,3 @@ if (err) {

var promise = listAllObjects(this.s3, this.bucket, this.path + s3Utils.toKey(path) + '/', '/', marker);
var promise = listAllObjects(this.s3, this.bucket, s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(path))) + '/', '/', marker);

@@ -544,3 +548,3 @@ if (!callback) {

var self = this;
var promise = listAllObjectsFiles(this.s3, this.bucket, this.path + s3Utils.toKey(sourcePath) + '/').then(function (files) {
var promise = listAllObjectsFiles(this.s3, this.bucket, s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(sourcePath))) + '/').then(function (files) {
var promises = [];

@@ -666,3 +670,3 @@ files.forEach(function (file) {

S3fs.prototype.readdirp = function (path, callback) {
var prefix = this.path + s3Utils.toKey(path);
var prefix = s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(path, this.bucket, this.path)));
if (prefix[prefix.length - 1] !== '/') {

@@ -703,3 +707,3 @@ prefix += '/'; // Make sure we have a trailing slash for the directory

var self = this,
promise = listAllObjectsFiles(this.s3, this.bucket, path ? this.path + s3Utils.toKey(path) + '/' : undefined).then(function (objects) {
promise = listAllObjectsFiles(this.s3, this.bucket, path ? s3Utils.toKey(s3Utils.joinPaths(this.path + s3Utils.toKey(path))) + '/' : undefined).then(function (objects) {
return Promise.all(objects.filter(function (object) {

@@ -770,3 +774,3 @@ //filter items

Bucket: s3fs.bucket,
Key: s3fs.path + s3Utils.toKey(path, s3fs.bucket, s3fs.path)
Key: s3Utils.toKey(s3Utils.joinPaths(s3fs.path + s3Utils.toKey(path, s3fs.bucket, s3fs.path)))
}, function (err, data) {

@@ -773,0 +777,0 @@ if (err) {

@@ -79,3 +79,3 @@ /*

return !!p;
}), false).join('/');
}), !isAbsolute).join('/');

@@ -82,0 +82,0 @@ if (tail && trailingSlash) {

{
"name": "s3fs",
"version": "2.1.1",
"version": "2.2.0",
"description": "Implementation of Node.JS FS interface using Amazon Simple Storage Service (S3).",

@@ -5,0 +5,0 @@ "keywords": [

@@ -74,5 +74,9 @@ /*

it('should be able to create a directory when going up a directory', function () {
return expect(bucketS3fsImpl.clone('testDir').mkdir('../testDir/../testDir/testDir2/')).to.eventually.be.fulfilled();
});
it('should be able to create a directory with a callback', function () {
return expect(new Promise(function (resolve, reject) {
s3fsImpl.mkdir('testDir', function (err) {
bucketS3fsImpl.mkdir('testDir', function (err) {
if (err) {

@@ -90,5 +94,9 @@ return reject(err);

it('should be able to recursively create directories when going up a directory', function () {
return expect(bucketS3fsImpl.clone('testDir').mkdirp('../testDir/../testDir/testDir2/')).to.eventually.be.fulfilled();
});
it('should be able to recursively create directories with a callback', function () {
return expect(new Promise(function (resolve, reject) {
s3fsImpl.mkdirp('testDirDos/testSubDir/anotherDir', function (err) {
bucketS3fsImpl.mkdirp('testDirDos/testSubDir/anotherDir', function (err) {
if (err) {

@@ -103,5 +111,13 @@ return reject(err);

it('should be able to tell that a directory exists', function () {
return expect(bucketS3fsImpl.exists('/')).to.eventually.be.fulfilled();
return expect(bucketS3fsImpl.exists('/')).to.eventually.equal(true);
});
it.skip('should be able to tell that a directory exists when going up a directory', function () {
//TODO: Fix this so that it actually works on sub-directories.
return expect(bucketS3fsImpl.mkdir('/testDir').then(function() {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.exists('../testDir/../testDir/');
})).to.eventually.equal(true);
});
it('should be able to tell that a directory exists with a callback', function () {

@@ -141,5 +157,20 @@ return expect(new Promise(function (resolve) {

})
).to.eventually.be.fulfilled();
.then(function() {
return bucketS3fsImpl.readdir('/');
})
).to.eventually.have.lengthOf(0);
});
it('should be able to remove an empty directory by going up a directory', function () {
return expect(bucketS3fsImpl.mkdir('testDir')
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.rmdir('../testDir/../testDir/');
})
.then(function() {
return bucketS3fsImpl.readdir('/');
})
).to.eventually.have.lengthOf(0);
});
it('should be able to remove an empty directory with a callback', function () {

@@ -208,2 +239,22 @@ return expect(bucketS3fsImpl.mkdir('testDir')

it('should be able to copy a directory recursively when going up a directory', function () {
return expect(bucketS3fsImpl.writeFile('testDir/test.json', '{}')
.then(function () {
return bucketS3fsImpl.writeFile('testDir/test/test.json', '{}');
})
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.copyDir('../testDir', '../testCopyDirDestPromise');
})
.then(function () {
return bucketS3fsImpl.readdir('testCopyDirDestPromise');
})
).to.eventually.satisfy(function (files) {
expect(files).to.have.lengthOf(2);
expect(files[0]).to.equal('test.json');
expect(files[1]).to.equal('test/');
return true;
});
});
it('should be able to copy a directory recursively with a promise', function () {

@@ -256,2 +307,23 @@ return expect(bucketS3fsImpl.writeFile('testDir/test.json', '{}')

it('should be able to delete a directory recursively when going up a directory', function () {
return expect(bucketS3fsImpl.writeFile('testDir/test1.json', '{}')
.then(function () {
return bucketS3fsImpl.writeFile('testDir/test1/test2.json', '{}')
.then(function () {
return bucketS3fsImpl.writeFile('testDir/test1/test2/test3.json', '{}');
});
})
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.rmdirp('../testDir/../testDir/test1').then(function () {
return bucketS3fsImpl.readdir('testDir');
});
})
).to.eventually.satisfy(function (files) {
expect(files).to.have.lengthOf(1);
expect(files[0]).to.equal('test1.json');
return true;
});
});
it('should be able to delete a directory recursively with a callback', function () {

@@ -301,2 +373,19 @@ return expect(bucketS3fsImpl.writeFile('testDir/test.json', '{}')

it('should list all the files in a directory recursively when going up a directory', function () {
return expect(bucketS3fsImpl.writeFile('testDir/test.json', '{}')
.then(function () {
return bucketS3fsImpl.writeFile('testDir/test/test.json', '{}');
})
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.readdirp('../testDir/../testDir/');
})
).to.eventually.satisfy(function (files) {
expect(files).to.have.lengthOf(2);
expect(files[0]).to.equal('test.json');
expect(files[1]).to.equal('test/test.json');
return true;
});
});
it('should list all the files in a directory recursively with a callback', function () {

@@ -336,2 +425,14 @@ return expect(bucketS3fsImpl.writeFile('testDir/test.json', '{}')

it('should retrieve the stats of a directory when going up a directory - stat(2)', function () {
return expect(bucketS3fsImpl.mkdir('testDir/')
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.stat('../testDir/../testDir/');
})
).to.eventually.satisfy(function (stats) {
expect(stats.isDirectory()).to.be.true();
return true;
});
});
it('should retrieve the stats of a directory with a callback - stat(2)', function () {

@@ -366,2 +467,14 @@ return expect(bucketS3fsImpl.mkdir('testDir/')

it('should retrieve the stats of a directory when going up a directory - lstat(2)', function () {
return expect(bucketS3fsImpl.mkdir('testDir/')
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.lstat('../testDir/../testDir/');
})
).to.eventually.satisfy(function (stats) {
expect(stats.isDirectory()).to.be.true();
return true;
});
});
it('should retrieve the stats of a directory with a callback - lstat(2)', function () {

@@ -404,2 +517,22 @@ return expect(bucketS3fsImpl.mkdir('testDir/')

it('should list all the files in a directory when going up a directory', function () {
return expect(bucketS3fsImpl.mkdir('testDir/')
.then(function () {
return bucketS3fsImpl.writeFile('testDir/test.json', '{}')
.then(function () {
return bucketS3fsImpl.writeFile('testDir/test/test.json', '{}');
});
})
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.readdir('../testDir/../testDir');
})
).to.eventually.satisfy(function (files) {
expect(files).to.have.lengthOf(2);
expect(files[0]).to.equal('test.json');
expect(files[1]).to.equal('test/');
return true;
});
});
it('should list all the files in a directory with a callback', function () {

@@ -449,2 +582,21 @@ return expect(bucketS3fsImpl.mkdir('testDir/')

it('should be able to list all objects in a directory when going up a directory', function () {
return expect(bucketS3fsImpl.mkdir('testDir/')
.then(function () {
return bucketS3fsImpl.writeFile('testDir/test.json', '{}')
.then(function () {
return bucketS3fsImpl.writeFile('testDir/test/test.json', '{}');
});
})
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.listContents('../testDir/../testDir/');
})
).to.eventually.satisfy(function (files) {
expect(files).to.have.lengthOf(1);
expect(files[0].Key).to.be.equal('test.json');
return true;
});
});
it('should be able to list all objects in a directory with a callback', function () {

@@ -451,0 +603,0 @@ return expect(bucketS3fsImpl.mkdir('testDir/')

@@ -90,2 +90,17 @@ /*

it('should be able to read and write a file by going out of the bucket path when using clone', function () {
var invalidFileText = '{ "test": "invalid" }';
var fileText = '{ "test": "test" }';
return Promise.all([
bucketS3fsImpl.writeFile('one/test-file.json', invalidFileText),
bucketS3fsImpl.writeFile('two/test-file.json', fileText)
]).then(function () {
var oneS3fsImpl = bucketS3fsImpl.clone('one');
return expect(oneS3fsImpl.readFile('../two/test-file.json')).to.eventually.satisfy(function (data) {
expect(data.Body.toString()).to.equal(fileText);
return true;
});
});
});
it('should be able to read and write a file by going up a directory', function () {

@@ -117,4 +132,4 @@ var fileText = '{ "test": "test" }';

it('should be able to write a large file', function () {
var promise = new Promise(function(resolve, reject) {
fs.readFile('./test/mock/large-file.txt', function(err, largeFile) {
var promise = new Promise(function (resolve, reject) {
fs.readFile('./test/mock/large-file.txt', function (err, largeFile) {
if (err) {

@@ -130,6 +145,17 @@ return reject(err);

it('should be able to write a file with encoding', function () {
it('should be able to write a file with utf8 encoding', function () {
var fileText = '{ "test": "test" }';
var options = {encoding: 'utf8'};
return bucketS3fsImpl.writeFile('test-file.json', fileText, options).then(function () {
return expect(bucketS3fsImpl.readFile('test-file.json', options)).to.eventually.satisfy(function (data) {
expect(data.Body.toString()).to.equal(fileText);
return true;
});
});
});
it('should be able to write a file with utf16 encoding', function () {
var fileText = '{ "test": "test" }';
var options = {encoding: 'utf16'};
return bucketS3fsImpl.writeFile('test-file.json', fileText, {encoding: 'utf16'}).then(function () {
return bucketS3fsImpl.writeFile('test-file.json', fileText, options).then(function () {
return expect(bucketS3fsImpl.readFile('test-file.json', options)).to.eventually.satisfy(function (data) {

@@ -143,4 +169,4 @@ expect(data.Body.toString()).to.equal(fileText);

it('should be able to write a large file with a callback', function () {
var promise = new Promise(function(resolve, reject) {
fs.readFile('./test/mock/large-file.txt', function(err, largeFile) {
var promise = new Promise(function (resolve, reject) {
fs.readFile('./test/mock/large-file.txt', function (err, largeFile) {
if (err) {

@@ -188,5 +214,20 @@ return reject(err);

})
).to.eventually.be.fulfilled();
.then(function() {
return bucketS3fsImpl.exists('test-copy.json');
})
).to.eventually.equal(true);
});
it('should be able to copy an object when going up a directory', function () {
return expect(bucketS3fsImpl.writeFile('testDir/test-copy.json', '{}')
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.copyFile('../testDir/../testDir/test-copy.json', '../testDir/../testDir/test-copy-dos.json');
})
.then(function() {
return bucketS3fsImpl.exists('testDir/test-copy-dos.json');
})
).to.eventually.equal(true);
});
it('should be able to copy an object with a callback', function () {

@@ -215,2 +256,11 @@ return expect(bucketS3fsImpl.writeFile('test-copy-callback.json', '{}')

it('should be able to get the head of an object when going up a directory', function () {
return expect(bucketS3fsImpl.writeFile('testDir/test-head.json', '{}')
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.headObject('../testDir/test-head.json');
})
).to.eventually.be.fulfilled();
});
it('should be able to get the head of an object with a callback', function () {

@@ -236,5 +286,20 @@ return expect(bucketS3fsImpl.writeFile('test-head-callback.json', '{}')

})
).to.eventually.be.fulfilled();
.then(function() {
return bucketS3fsImpl.readdirp('/');
})
).to.eventually.have.lengthOf(0);
});
it('should be able to delete a file when going up a directory', function () {
return expect(bucketS3fsImpl.writeFile('testDir/test-delete.json', '{ "test": "test" }')
.then(function () {
var testDirS3fsImpl = bucketS3fsImpl.clone('testDir');
return testDirS3fsImpl.unlink('../testDir/test-delete.json');
})
.then(function() {
return bucketS3fsImpl.readdirp('/');
})
).to.eventually.have.lengthOf(0);
});
it('should be able to delete a file with a callback', function () {

@@ -271,4 +336,4 @@ return expect(bucketS3fsImpl.writeFile('test-delete-callback.json', '{ "test": "test" }')

it('should be able to write a file from a buffer', function () {
var promise = new Promise(function(resolve, reject) {
fs.readFile('./test/mock/example-file.json', function(err, exampleFile) {
var promise = new Promise(function (resolve, reject) {
fs.readFile('./test/mock/example-file.json', function (err, exampleFile) {
if (err) {

@@ -285,4 +350,4 @@ return reject(err);

it('should be able to write a file from a buffer with a callback', function () {
var promise = new Promise(function(resolve, reject) {
fs.readFile('./test/mock/example-file.json', function(err, exampleFile) {
var promise = new Promise(function (resolve, reject) {
fs.readFile('./test/mock/example-file.json', function (err, exampleFile) {
if (err) {

@@ -289,0 +354,0 @@ return reject(err);

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