Socket
Socket
Sign inDemoInstall

s3-blob-store

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

s3-blob-store - npm Package Compare versions

Comparing version 4.1.0 to 4.1.1

LICENSE

6

History.md

@@ -0,5 +1,3 @@

# 2.0 / 2017-06-19
2.0 / 2017-06-19
==================
* Changed write stream behaviour, see [#13](https://github.com/jb55/s3-blob-store/pull/13)
- Changed write stream behaviour, see [#13](https://github.com/jb55/s3-blob-store/pull/13)

@@ -0,1 +1,2 @@

'use strict';

@@ -6,9 +7,8 @@ var downloader = require('s3-download-stream');

var uploadStream = require('s3-stream-upload');
var cloneDeep = require('lodash.clonedeep');
function S3BlobStore(opts) {
function S3BlobStore (opts) {
if (!(this instanceof S3BlobStore)) return new S3BlobStore(opts);
opts = opts || {};
if (!opts.client) throw Error("S3BlobStore client option required (aws-sdk AWS.S3 instance)");
if (!opts.bucket) throw Error("S3BlobStore bucket option required");
if (!opts.client) throw Error('S3BlobStore client option required (aws-sdk AWS.S3 instance)');
if (!opts.bucket) throw Error('S3BlobStore bucket option required');
this.accessKey = opts.accessKey;

@@ -20,4 +20,4 @@ this.secretKey = opts.secretKey;

S3BlobStore.prototype.createReadStream = function(opts) {
if (typeof opts === 'string') opts = {key: opts}
S3BlobStore.prototype.createReadStream = function (opts) {
if (typeof opts === 'string') opts = { key: opts };
var config = { client: this.s3, params: this.downloadParams(opts) };

@@ -31,9 +31,9 @@ if (opts.concurrency) config.concurrency = opts.concurrency;

return stream;
}
};
S3BlobStore.prototype.uploadParams = function (opts) {
opts = Object.assign({}, opts, {
params: Object.assign({}, opts.params)
});
S3BlobStore.prototype.uploadParams = function(opts) {
opts = opts ? cloneDeep(opts) : {};
var params = opts.params || {};
var filename = opts.name || opts.filename;

@@ -43,2 +43,3 @@ var key = opts.key || filename;

var params = opts.params;
params.Bucket = params.Bucket || this.bucket;

@@ -48,3 +49,3 @@ params.Key = params.Key || key;

if (!contentType) {
contentType = filename? mime.lookup(filename) : mime.lookup(opts.key)
contentType = filename ? mime.lookup(filename) : mime.lookup(opts.key);
}

@@ -54,44 +55,43 @@ if (contentType) params.ContentType = contentType;

return params;
}
};
S3BlobStore.prototype.downloadParams = function(opts) {
S3BlobStore.prototype.downloadParams = function (opts) {
var params = this.uploadParams(opts);
delete params.ContentType;
return params;
}
};
S3BlobStore.prototype.createWriteStream = function(opts, s3opts, done) {
if (typeof(s3opts) === 'function') {
S3BlobStore.prototype.createWriteStream = function (opts, s3opts, done) {
if (typeof s3opts === 'function') {
done = s3opts;
s3opts = {};
}
if (typeof opts === 'string') opts = {key: opts}
var params = this.uploadParams(opts)
var out = uploadStream(this.s3, params)
if (typeof opts === 'string') opts = { key: opts };
var params = this.uploadParams(opts);
var out = uploadStream(this.s3, params);
out.on('error', function (err) {
debug('got err %j', err);
return done && done(err)
})
done && done(err);
});
out.on('finish', function () {
debug('uploaded');
done && done(null, { key: params.Key })
})
done && done(null, { key: params.Key });
});
return out;
}
};
S3BlobStore.prototype.remove = function(opts, done) {
var key = typeof opts === 'string' ? opts : opts.key
this.s3.deleteObject({ Bucket: this.bucket, Key: key }, done)
S3BlobStore.prototype.remove = function (opts, done) {
var key = typeof opts === 'string' ? opts : opts.key;
this.s3.deleteObject({ Bucket: this.bucket, Key: key }, done);
return this;
}
};
S3BlobStore.prototype.exists = function(opts, done) {
if (typeof opts === 'string') opts = {key: opts}
this.s3.headObject({ Bucket: this.bucket, Key: opts.key }, function(err, res){
S3BlobStore.prototype.exists = function (opts, done) {
if (typeof opts === 'string') opts = { key: opts };
this.s3.headObject({ Bucket: this.bucket, Key: opts.key }, function (err, res) {
if (err && err.statusCode === 404) return done(null, false);
done(err, !err)
done(err, !err);
});
}
};
module.exports = S3BlobStore;
{
"name": "s3-blob-store",
"version": "4.1.1",
"description": "s3 abstract-blob-store",

@@ -10,4 +11,2 @@ "keywords": [

],
"version": "4.1.0",
"license": "MIT",
"repository": {

@@ -17,9 +16,13 @@ "type": "git",

},
"license": "MIT",
"main": "index.js",
"files": [
"index.js"
],
"scripts": {
"test": "node test.js"
"lint": "eslint . --ext .js",
"test": "node test.js | tap-spec"
},
"dependencies": {
"debug": "^3.1.0",
"lodash.clonedeep": "^4.5.0",
"debug": "^4.1.1",
"mime-types": "^2.0.0",

@@ -32,4 +35,14 @@ "s3-download-stream": "1.1.1",

"aws-sdk": "^2.0.15",
"tape": "^4.8.0"
"eslint": "^6.8.0",
"eslint-config-semistandard": "^15.0.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"s3rver": "^3.5.0",
"tap-spec": "^5.0.0",
"tape": "^4.8.0",
"tmp": "^0.1.0"
}
}

@@ -0,13 +1,11 @@

# s3-blob-store [![build status](https://badgen.net/travis/jb55/s3-blob-store/master)](https://travis-ci.com/jb55/s3-blob-store) [![install size](https://badgen.net/packagephobia/install/s3-blob-store)](https://packagephobia.now.sh/result?p=s3-blob-store) [![npm package version](https://badgen.net/npm/v/s3-blob-store)](https://npm.im/s3-blob-store) [![github license](https://badgen.net/github/license/jb55/s3-blob-store)](https://github.com/jb55/s3-blob-store/blob/master/LICENSE) [![js semistandard style](https://badgen.net/badge/code%20style/semistandard/pink)](https://github.com/Flet/semistandard)
# s3-blob-store
Amazon S3 [abstract-blob-store](http://npmrepo.com/abstract-blob-store)
Amazon S3 [abstract-blob-store](http://npmrepo.com/abstract-blob-store)
[![Build Status](https://travis-ci.org/jb55/s3-blob-store.svg)](https://travis-ci.org/jb55/s3-blob-store)
[![blob-store-compatible](https://raw.githubusercontent.com/maxogden/abstract-blob-store/master/badge.png)](https://github.com/maxogden/abstract-blob-store)
[![blob-store-compatible](https://raw.githubusercontent.com/maxogden/abstract-blob-store/master/badge.png)](https://github.com/maxogden/abstract-blob-store)
## Installation
Install with npm
Install with npm

@@ -25,3 +23,3 @@ $ npm install s3-blob-store

secretAccessKey: process.env.S3_SECRET_KEY
})
});

@@ -33,15 +31,14 @@ var store = s3blobs({

// write to s3
fs.createReadStream('/tmp/somefile.txt')
.pipe(store.createWriteStream({ key: 'somefile.txt' }))
.pipe(store.createWriteStream({ key: 'somefile.txt' }));
// read from s3
store.createReadStream({ key: 'somefile.txt' })
.pipe(fs.createWriteStream('/tmp/somefile.txt'))
.pipe(fs.createWriteStream('/tmp/somefile.txt'));
// exists
store.exists({ key: 'somefile.txt' }, function(err, exists){
})
store.exists({ key: 'somefile.txt' }, function (err, exists) {
// ...
});
```

@@ -51,10 +48,10 @@

### var s3 = require('s3-blob-store')(options)
### `var s3 = require('s3-blob-store')(options)`
`options` must be an object that has the following properties:
`client`: an `require('aws-sdk').S3` instance
`bucket`: your bucket
- `client`: an `require('aws-sdk').S3` instance
- `bucket`: your bucket
### s3.createWriteStream(opts, cb)
### `s3.createWriteStream(opts, cb)`

@@ -70,5 +67,5 @@ returns a writable stream that you can pipe data to.

### s3.createReadStream(opts)
### `s3.createReadStream(opts)`
opts should be `{key: string (usually a hash or path + filename}`
`opts` should be `{ key: string (usually a hash or path + filename) }`

@@ -75,0 +72,0 @@ `opts.params` additional [parameters](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getObject-property) to pass to S3

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