bloody-simple-s3
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -0,1 +1,6 @@ | ||
## 0.6.1 - 2015-11-12 | ||
* Use commonjs to import/export modules to avoid babel "default" decorator - see https://github.com/babel/babel/issues/2724 for further info | ||
* Replace gulpfile.js with gulpfile.babel.js | ||
## 0.6.0 - 2015-11-10 | ||
@@ -2,0 +7,0 @@ |
@@ -5,52 +5,17 @@ 'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _os = require('os'); | ||
var os = require('os'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var crypto = require('crypto'); | ||
var stream = require('stream'); | ||
var Promise = require('bluebird'); | ||
var CustomError = require('customerror'); | ||
var AWS = require('aws-sdk'); | ||
var _ = require('lodash'); | ||
var type = require('type-of'); | ||
var _os2 = _interopRequireDefault(_os); | ||
Promise.promisifyAll(fs); | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _path = require('path'); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _crypto = require('crypto'); | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
var _stream = require('stream'); | ||
var _stream2 = _interopRequireDefault(_stream); | ||
var _bluebird = require('bluebird'); | ||
var _bluebird2 = _interopRequireDefault(_bluebird); | ||
var _customerror = require('customerror'); | ||
var _customerror2 = _interopRequireDefault(_customerror); | ||
var _awsSdk = require('aws-sdk'); | ||
var _awsSdk2 = _interopRequireDefault(_awsSdk); | ||
var _lodash = require('lodash'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _typeOf = require('type-of'); | ||
var _typeOf2 = _interopRequireDefault(_typeOf); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
_bluebird2.default.promisifyAll(_fs2.default); | ||
var BloodySimpleS3 = (function () { | ||
@@ -60,7 +25,7 @@ function BloodySimpleS3(options) { | ||
if (!_lodash2.default.isPlainObject(options)) { | ||
throw new _customerror2.default('Invalid options param; expected object, received ' + (0, _typeOf2.default)(options), 'InvalidArgument'); | ||
if (!_.isPlainObject(options)) { | ||
throw new CustomError('Invalid options param; expected object, received ' + type(options), 'InvalidArgument'); | ||
} | ||
options = _lodash2.default.defaults(options, { | ||
options = _.defaults(options, { | ||
region: 'us-east-1', | ||
@@ -70,20 +35,20 @@ sslEnabled: true | ||
if (!_lodash2.default.isString(options.bucket)) { | ||
throw new _customerror2.default('Invalid bucket option; expected string, received ' + (0, _typeOf2.default)(options.bucket), 'InvalidArgument'); | ||
if (!_.isString(options.bucket)) { | ||
throw new CustomError('Invalid bucket option; expected string, received ' + type(options.bucket), 'InvalidArgument'); | ||
} | ||
if (!_lodash2.default.isString(options.accessKeyId)) { | ||
throw new _customerror2.default('Invalid accessKeyId option; expected string, received ' + (0, _typeOf2.default)(options.accessKeyId), 'InvalidArgument'); | ||
if (!_.isString(options.accessKeyId)) { | ||
throw new CustomError('Invalid accessKeyId option; expected string, received ' + type(options.accessKeyId), 'InvalidArgument'); | ||
} | ||
if (!_lodash2.default.isString(options.secretAccessKey)) { | ||
throw new _customerror2.default('Invalid secretAccessKey option; expected string, received ' + (0, _typeOf2.default)(options.secretAccessKey), 'InvalidArgument'); | ||
if (!_.isString(options.secretAccessKey)) { | ||
throw new CustomError('Invalid secretAccessKey option; expected string, received ' + type(options.secretAccessKey), 'InvalidArgument'); | ||
} | ||
if (!_lodash2.default.isString(options.region)) { | ||
throw new _customerror2.default('Invalid region option; expected string, received ' + (0, _typeOf2.default)(options.region), 'InvalidArgument'); | ||
if (!_.isString(options.region)) { | ||
throw new CustomError('Invalid region option; expected string, received ' + type(options.region), 'InvalidArgument'); | ||
} | ||
if (!_lodash2.default.isBoolean(options.sslEnabled)) { | ||
throw new _customerror2.default('Invalid sslEnabled option; expected boolean, received ' + (0, _typeOf2.default)(options.sslEnabled), 'InvalidArgument'); | ||
if (!_.isBoolean(options.sslEnabled)) { | ||
throw new CustomError('Invalid sslEnabled option; expected boolean, received ' + type(options.sslEnabled), 'InvalidArgument'); | ||
} | ||
@@ -93,3 +58,3 @@ | ||
this.s3 = new _awsSdk2.default.S3({ | ||
this.s3 = new AWS.S3({ | ||
accessKeyId: options.accessKeyId, | ||
@@ -106,4 +71,4 @@ secretAccessKey: options.secretAccessKey, | ||
value: function createReadStream(filename) { | ||
if (!_lodash2.default.isString(filename)) { | ||
throw new _customerror2.default('Invalid filename param; expected string, received ' + (0, _typeOf2.default)(filename), 'InvalidArgument'); | ||
if (!_.isString(filename)) { | ||
throw new CustomError('Invalid filename param; expected string, received ' + type(filename), 'InvalidArgument'); | ||
} | ||
@@ -123,26 +88,26 @@ | ||
if (!_lodash2.default.isString(source)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid source param; expected string, received ' + (0, _typeOf2.default)(source), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(source)) { | ||
return Promise.reject(new CustomError('Invalid source param; expected string, received ' + type(source), 'InvalidArgument')).nodeify(callback); | ||
} | ||
if (_lodash2.default.isFunction(target)) { | ||
if (_.isFunction(target)) { | ||
callback = target; | ||
target = _os2.default.tmpdir(); | ||
} else if (_lodash2.default.isUndefined(target)) { | ||
target = _os2.default.tmpdir(); | ||
target = os.tmpdir(); | ||
} else if (_.isUndefined(target)) { | ||
target = os.tmpdir(); | ||
} | ||
if (!_lodash2.default.isString(target)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid target param; expected string, received ' + (0, _typeOf2.default)(target), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(target)) { | ||
return Promise.reject(new CustomError('Invalid target param; expected string, received ' + type(target), 'InvalidArgument')).nodeify(callback); | ||
} | ||
return _fs2.default.statAsync(target).then(function (stat) { | ||
if (stat.isDirectory()) return _path2.default.join(target, _path2.default.basename(source)); | ||
return fs.statAsync(target).then(function (stat) { | ||
if (stat.isDirectory()) return path.join(target, path.basename(source)); | ||
if (stat.isFile()) return target; | ||
throw new _customerror2.default('Invalid target path; expected directory or file', 'InvalidDownloadTarget'); | ||
throw new CustomError('Invalid target path; expected directory or file', 'InvalidDownloadTarget'); | ||
}).then(function (file) { | ||
var resolver = function resolver(resolve, reject) { | ||
var readable = _this.createReadStream(source); | ||
var writable = _fs2.default.createWriteStream(file); | ||
var writable = fs.createWriteStream(file); | ||
readable.pipe(writable); | ||
@@ -157,3 +122,3 @@ | ||
return new _bluebird2.default(resolver); | ||
return new Promise(resolver); | ||
}).nodeify(callback); | ||
@@ -164,10 +129,10 @@ } | ||
value: function download(source, target, callback) { | ||
return _bluebird2.default.props({ | ||
return Promise.props({ | ||
file: this.downloadWithoutCheck(source, target), | ||
meta: this.getFileMeta(source) | ||
}).then(function (props) { | ||
return _fs2.default.readFileAsync(props.file.name).then(function (buf) { | ||
if (props.meta.ETag !== '"' + _crypto2.default.createHash('md5').update(buf).digest().toString('hex') + '"') { | ||
return _fs2.default.unlinkAsync(props.file.name) // remove downloaded file from disk | ||
.throw(new _customerror2.default('Invalid checksum of file ' + source, 'BadMD5Digest')); | ||
return fs.readFileAsync(props.file.name).then(function (buf) { | ||
if (props.meta.ETag !== '"' + crypto.createHash('md5').update(buf).digest().toString('hex') + '"') { | ||
return fs.unlinkAsync(props.file.name) // remove downloaded file from disk | ||
.throw(new CustomError('Invalid checksum of file ' + source, 'BadMD5Digest')); | ||
} | ||
@@ -198,3 +163,3 @@ | ||
return new _bluebird2.default(resolver).nodeify(callback); | ||
return new Promise(resolver).nodeify(callback); | ||
} | ||
@@ -206,8 +171,8 @@ }, { | ||
if (!_lodash2.default.isString(filename)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid filename param; expected string, received ' + (0, _typeOf2.default)(filename), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(filename)) { | ||
return Promise.reject(new CustomError('Invalid filename param; expected string, received ' + type(filename), 'InvalidArgument')).nodeify(callback); | ||
} | ||
if (!(contents instanceof _stream2.default.Readable) && !Buffer.isBuffer(contents) && !_lodash2.default.isString(contents)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid contents param; expected readable stream, buffer or string, received ' + (0, _typeOf2.default)(contents), 'InvalidArgument')).nodeify(callback); | ||
if (!(contents instanceof stream.Readable) && !Buffer.isBuffer(contents) && !_.isString(contents)) { | ||
return Promise.reject(new CustomError('Invalid contents param; expected readable stream, buffer or string, received ' + type(contents), 'InvalidArgument')).nodeify(callback); | ||
} | ||
@@ -222,3 +187,3 @@ | ||
if (Buffer.isBuffer(contents)) { | ||
params.ContentMD5 = _crypto2.default.createHash('md5').update(contents).digest().toString('base64'); // force integrity check | ||
params.ContentMD5 = crypto.createHash('md5').update(contents).digest().toString('base64'); // force integrity check | ||
} | ||
@@ -233,3 +198,3 @@ | ||
return new _bluebird2.default(resolver).nodeify(callback); | ||
return new Promise(resolver).nodeify(callback); | ||
} | ||
@@ -241,29 +206,29 @@ }, { | ||
if (!_lodash2.default.isString(source)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid source param; expected string, received ' + (0, _typeOf2.default)(source), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(source)) { | ||
return Promise.reject(new CustomError('Invalid source param; expected string, received ' + type(source), 'InvalidArgument')).nodeify(callback); | ||
} | ||
source = _path2.default.resolve(__dirname, source); | ||
source = path.resolve(__dirname, source); | ||
if (_lodash2.default.isFunction(target)) { | ||
if (_.isFunction(target)) { | ||
callback = target; | ||
target = _path2.default.basename(source); | ||
} else if (_lodash2.default.isUndefined(target)) { | ||
target = _path2.default.basename(source); | ||
target = path.basename(source); | ||
} else if (_.isUndefined(target)) { | ||
target = path.basename(source); | ||
} | ||
if (!_lodash2.default.isString(target)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid target param; expected string, received ' + (0, _typeOf2.default)(target), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(target)) { | ||
return Promise.reject(new CustomError('Invalid target param; expected string, received ' + type(target), 'InvalidArgument')).nodeify(callback); | ||
} | ||
return _fs2.default.statAsync(source).then(function (stat) { | ||
return fs.statAsync(source).then(function (stat) { | ||
if (!stat.isFile()) { | ||
throw new _customerror2.default('Source is invalid; you must reference a file', 'InvalidUploadSource'); | ||
throw new CustomError('Source is invalid; you must reference a file', 'InvalidUploadSource'); | ||
} | ||
if (stat.size < _os2.default.freemem()) { | ||
return _fs2.default.readFileAsync(source); // memory is suffient - use buffer | ||
if (stat.size < os.freemem()) { | ||
return fs.readFileAsync(source); // memory is suffient - use buffer | ||
} | ||
return _fs2.default.createReadStream(source); | ||
return fs.createReadStream(source); | ||
}).then(function (contents) { | ||
@@ -278,15 +243,15 @@ return _this4.writeFile(target, contents); | ||
if (!_lodash2.default.isString(dir)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid dir param; expected string, received ' + (0, _typeOf2.default)(dir), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(dir)) { | ||
return Promise.reject(new CustomError('Invalid dir param; expected string, received ' + type(dir), 'InvalidArgument')).nodeify(callback); | ||
} | ||
if (_lodash2.default.isFunction(options)) { | ||
if (_.isFunction(options)) { | ||
callback = options; | ||
options = {}; | ||
} else if (_lodash2.default.isUndefined(options)) { | ||
} else if (_.isUndefined(options)) { | ||
options = {}; | ||
} | ||
if (!_lodash2.default.isPlainObject(options)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid options param; expected object, received ' + (0, _typeOf2.default)(options), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isPlainObject(options)) { | ||
return Promise.reject(new CustomError('Invalid options param; expected object, received ' + type(options), 'InvalidArgument')).nodeify(callback); | ||
} | ||
@@ -296,4 +261,4 @@ | ||
Bucket: this.bucket, | ||
Prefix: _path2.default.normalize(dir), | ||
Marker: options.cursor || _path2.default.normalize(dir), | ||
Prefix: path.normalize(dir), | ||
Marker: options.cursor || path.normalize(dir), | ||
MaxKeys: options.limit | ||
@@ -306,3 +271,3 @@ }; | ||
var arr = _lodash2.default.map(data.Contents, function (obj) { | ||
var arr = _.map(data.Contents, function (obj) { | ||
return { | ||
@@ -319,3 +284,3 @@ name: obj.Key, | ||
return new _bluebird2.default(resolver).nodeify(callback); | ||
return new Promise(resolver).nodeify(callback); | ||
} | ||
@@ -327,24 +292,24 @@ }, { | ||
if (!_lodash2.default.isString(source)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid source param; expected string, received ' + (0, _typeOf2.default)(source), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(source)) { | ||
return Promise.reject(new CustomError('Invalid source param; expected string, received ' + type(source), 'InvalidArgument')).nodeify(callback); | ||
} | ||
if (!_lodash2.default.isString(target)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid target param; expected string, received ' + (0, _typeOf2.default)(target), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(target)) { | ||
return Promise.reject(new CustomError('Invalid target param; expected string, received ' + type(target), 'InvalidArgument')).nodeify(callback); | ||
} | ||
if (_lodash2.default.isFunction(options)) { | ||
if (_.isFunction(options)) { | ||
callback = options; | ||
options = {}; | ||
} else if (_lodash2.default.isUndefined(options)) { | ||
} else if (_.isUndefined(options)) { | ||
options = {}; | ||
} | ||
if (!_lodash2.default.isPlainObject(options)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid options param; expected object, received ' + (0, _typeOf2.default)(options), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isPlainObject(options)) { | ||
return Promise.reject(new CustomError('Invalid options param; expected object, received ' + type(options), 'InvalidArgument')).nodeify(callback); | ||
} | ||
var params = _lodash2.default.assign(options, { | ||
var params = _.assign(options, { | ||
Bucket: this.bucket, | ||
CopySource: encodeURIComponent(_path2.default.join(this.bucket, source)), | ||
CopySource: encodeURIComponent(path.join(this.bucket, source)), | ||
Key: target, | ||
@@ -361,3 +326,3 @@ MetadataDirective: 'COPY' | ||
return new _bluebird2.default(resolver).nodeify(callback); | ||
return new Promise(resolver).nodeify(callback); | ||
} | ||
@@ -369,4 +334,4 @@ }, { | ||
if (!_lodash2.default.isString(filename)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid filename param; expected string, received ' + (0, _typeOf2.default)(filename), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(filename)) { | ||
return Promise.reject(new CustomError('Invalid filename param; expected string, received ' + type(filename), 'InvalidArgument')).nodeify(callback); | ||
} | ||
@@ -386,3 +351,3 @@ | ||
return new _bluebird2.default(resolver).nodeify(callback); | ||
return new Promise(resolver).nodeify(callback); | ||
} | ||
@@ -394,3 +359,3 @@ }, { | ||
if (_lodash2.default.isFunction(options)) { | ||
if (_.isFunction(options)) { | ||
callback = options; | ||
@@ -418,4 +383,4 @@ options = {}; | ||
if (!_lodash2.default.isString(filename)) { | ||
return _bluebird2.default.reject(new _customerror2.default('Invalid filename param; expected string, received ' + (0, _typeOf2.default)(filename), 'InvalidArgument')).nodeify(callback); | ||
if (!_.isString(filename)) { | ||
return Promise.reject(new CustomError('Invalid filename param; expected string, received ' + type(filename), 'InvalidArgument')).nodeify(callback); | ||
} | ||
@@ -435,3 +400,3 @@ | ||
return new _bluebird2.default(resolver).nodeify(callback); | ||
return new Promise(resolver).nodeify(callback); | ||
} | ||
@@ -443,2 +408,2 @@ }]); | ||
exports.default = BloodySimpleS3; | ||
module.exports = BloodySimpleS3; |
{ | ||
"name": "bloody-simple-s3", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "A bloody simple interface to S3, based on the official AWS sdk", | ||
@@ -46,7 +46,7 @@ "repository": { | ||
"gulp-rimraf": "^0.2.0", | ||
"babel": "^6.0.15", | ||
"babel-core": "^6.1.2", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.3", | ||
"babel": "^6.1.5", | ||
"babel-core": "^6.1.4", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.4", | ||
"babel-preset-es2015": "^6.1.2" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # Bloody simple S3 | ||
[ ![Build Status for visionmobile/bloody-simple-sqs](https://codeship.com/projects/ce3c9d80-bb71-0132-8afa-3ee0b98d9f7e/status?branch=master)](https://codeship.com/projects/72166) | ||
[ ![Build Status for visionmobile/bloody-simple-s3](https://codeship.com/projects/e66d6350-aebb-0132-cc2e-72504bd694d9/status?branch=master)](https://codeship.com/projects/68954) | ||
@@ -8,0 +8,0 @@ #### Features |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7
332
0
0
19365