'use strict';
var aws = require('aws-sdk');
var autoAuth = require('aws-auto-auth');
var s3Stream = require('s3-upload-stream');


function UploadStream(bucket, profile){
  if(!bucket) throw new Error('Need to initialize uploadStream with an S3 bucket.');

  if(!(this instanceof UploadStream)) return new UploadStream(bucket, profile);

  this.credentials = autoAuth(aws, profile); 
  this.bucket = bucket;
  this.S3 = new aws.S3({credentials: this.credentials});
  this.s3Stream = s3Stream(this.S3); 
}


function streamToBucket(stream, key, cb){
  var upload = this.s3Stream.upload({Bucket: this.bucket, Key: key});
  var self = this;

  upload.on('error', function(err){
    stream.unpipe(upload);
    cb(new Error('Error loading to ' + self.bucket + '. ' + err))
  });

  upload.on('uploaded', function(details){
    cb(null, details); 
  });

  stream.pipe(upload); 

  return upload;
}


UploadStream.prototype.stream = streamToBucket;


module.exports = UploadStream;

@@ -375,17 +375,16 @@
 rofile);
- 
 %0A  this.
@@ -493,17 +493,16 @@
 his.S3);
- 
 %0A%7D%0A%0A%0Afun
@@ -511,55 +511,32 @@
 ion 
-streamToBucket(s
+getS
 tream
-, 
+(
 key
-, cb
 )%7B%0A  
-var upload =
+return
  thi
@@ -591,280 +591,8 @@
 %7D);%0A
-  var self = this;%0A%0A  upload.on('error', function(err)%7B%0A    stream.unpipe(upload);%0A    cb(new Error('Error loading to ' + self.bucket + '. ' + err))%0A  %7D);%0A%0A  upload.on('uploaded', function(details)%7B%0A    cb(null, details); %0A  %7D);%0A%0A  stream.pipe(upload); %0A%0A  return upload;%0A
 %7D%0A%0A%0A
@@ -627,22 +627,17 @@
 m = 
-s
+getS
 tream
-ToBucket
 ;%0A%0A%0A

Change uploadStream to accomodate pump