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

s3-streamer

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

s3-streamer - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

99

dist/S3Stream.js

@@ -21,6 +21,2 @@ 'use strict';

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _stream = require('stream');

@@ -32,2 +28,6 @@

var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -52,27 +52,2 @@

_createClass(S3Stream, [{
key: 'uploadStream',
value: function uploadStream(s3params) {
return this.s3UploadStream.upload(s3params);
}
}, {
key: 'downloadStream',
value: function downloadStream(s3params) {
return (0, _s3DownloadStream2.default)({
client: this.s3,
params: s3params
});
}
}, {
key: '_streamToS3',
value: function _streamToS3(inputStream, s3params) {
var _this = this;
return new _bluebird2.default(function (resolve, reject) {
var upload = _this.uploadStream(s3params);
upload.on('error', reject);
upload.on('uploaded', resolve);
inputStream.pipe(upload);
});
}
}, {
key: 'urlToS3',

@@ -90,9 +65,15 @@ value: function urlToS3(url, s3params) {

}, {
key: 'localFileToS3',
value: function localFileToS3(filename, s3params) {
var stream = _fs2.default.createReadStream(filename);
return this._streamToS3(stream, s3params);
}
}, {
key: 'stringFromS3',
value: function stringFromS3(s3params) {
var _this2 = this;
var _this = this;
return new _bluebird2.default(function (resolve, reject) {
var stringSink = new StringSink();
var download = _this2.downloadStream(s3params).pipe(stringSink);
var download = _this.downloadStream(s3params).pipe(stringSink);
download.on('error', reject);

@@ -105,5 +86,38 @@ download.on('finish', function () {

}, {
key: 'localFileFromS3',
value: function localFileFromS3(filename, s3params) {
var _this2 = this;
return new _bluebird2.default(function (resolve, reject) {
var fileSink = _fs2.default.createWriteStream(filename);
var download = _this2.downloadStream(s3params).pipe(fileSink);
download.on('error', reject);
download.on('finish', function () {
resolve(filename);
});
});
}
// lower level methods
}, {
key: 'uploadStream',
value: function uploadStream(s3params) {
return this.s3UploadStream.upload(s3params);
}
}, {
key: 'downloadStream',
value: function downloadStream(s3params) {
return (0, _s3DownloadStream2.default)({
client: this.s3,
params: s3params
});
}
// helper methods
}, {
key: '_string2stream',
value: function _string2stream(string) {
if (!_lodash2.default.isString(string)) {
if (typeof string !== 'string') {
throw new Error('Can only convert string to stream');

@@ -117,2 +131,14 @@ }

}
}, {
key: '_streamToS3',
value: function _streamToS3(inputStream, s3params) {
var _this3 = this;
return new _bluebird2.default(function (resolve, reject) {
var upload = _this3.uploadStream(s3params);
upload.on('error', reject);
upload.on('uploaded', resolve);
inputStream.pipe(upload);
});
}
}]);

@@ -123,2 +149,5 @@

// Writable that saves information to string
var StringSink = function (_Writable) {

@@ -136,6 +165,6 @@ _inherits(StringSink, _Writable);

var _this3 = _possibleConstructorReturn(this, (_ref = StringSink.__proto__ || Object.getPrototypeOf(StringSink)).call.apply(_ref, [this].concat(args)));
var _this4 = _possibleConstructorReturn(this, (_ref = StringSink.__proto__ || Object.getPrototypeOf(StringSink)).call.apply(_ref, [this].concat(args)));
_this3.chunks = [];
return _this3;
_this4.chunks = [];
return _this4;
}

@@ -142,0 +171,0 @@

{
"name": "s3-streamer",
"version": "1.0.1",
"description": "Thin wrapper to stream uploads and downloads from Amazon S3, from local filesystem or URLs",
"version": "1.0.2",
"description": "Thin wrapper over existing libraries to standardize the interface for streaming uploads and downloads from Amazon S3. Supports streaming to/from variables or URLs without using the local filesystem.",
"main": "./dist/index.js",

@@ -33,3 +33,2 @@ "scripts": {

"bluebird": "^3.5.0",
"lodash": "^4.17.4",
"request": "^2.81.0",

@@ -36,0 +35,0 @@ "s3-download-stream": "0.0.5",

# s3stream
Thin wrapper over existing libraries to standardize the interface for streaming uploads and downloads from Amazon S3, from local filesystem or URLs.
Thin wrapper over existing libraries to standardize the interface for streaming uploads and downloads from Amazon S3. Supports streaming to/from variables or URLs without using the local filesystem.
## Example usage
```js
import AWS from "aws-sdk";
import S3Stream from 's3-streamer';
var AWS = require('aws-sdk');
var S3Stream = require('s3-streamer');
let s3 = new AWS.S3();
let s3stream = new S3Stream(s3);
var s3 = new AWS.S3();
var s3stream = new S3Stream(s3);
let s3params = { Bucket: "BUCKET", Key: "KEY" };
var s3params = { Bucket: "BUCKET", Key: "KEY" };

@@ -19,2 +19,3 @@ // upload a string to s3

// download the string from s3
s3stream.stringFromS3(s3params).then(function(string) {

@@ -25,5 +26,9 @@ console.log('Downloaded: %s', string);

});
}).catch(function(err) {
console.log('Error');
// error handling
});
```
## Methods
## Upload Methods

@@ -41,2 +46,9 @@ ```js

```js
s3stream.localFileToS3(filename, s3params)
```
Streams a local file to an S3 object. Returns a bluebird promise.
## Upload Methods
```js
s3stream.stringFromS3(s3params)

@@ -46,2 +58,6 @@ ```

```js
s3stream.localFileFromS3(filename, s3params)
```
Streams an S3 object to a local file. Returns a bluebird promise that resolves with the given filename.

@@ -48,0 +64,0 @@ ## Lower level methods

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