Skip to content

Commit

Permalink
fix premature upload closure
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfenton committed Apr 5, 2016
1 parent 6226dec commit 5e90fe7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
### Fixed
* Fixed a case where S3 write streams could be prematurely closed when files are less than 5 MB

## [3.0.0-alpha.20] - 2016-04-04
### Changed
* Added default/configurable endpoint for S3 filesystem
Expand Down
32 changes: 20 additions & 12 deletions src/lib/Files.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,27 @@ const Files = function (options) {
return input
}

/**
* Creates a writeable stream that goes to S3
*
* @param {string} name - the name of file to write to
* @return {object} a writeable stream
* @private
*/
/**
* Creates a writeable stream that goes to S3
*
* @param {string} name - the name of file to write to
* @return {object} a writeable stream
* @private
*/
this._createS3WriteStream = function (name, options) {
let aborted = false
const input = _()
const params = s3Params(this.s3Bucket, name, options)
params.Body = input.pipe(zlib.createGzip())
const upload = this.s3.upload(params, (err, data) => {
var aborted = false
var input = _()
input.on('data', function (chunk) {
through.write(chunk)
})
input.end = function (chunk) {
if (chunk) through.write(chunk)
through.write(_.nil)
}
var through = _()
var params = s3Params(this.s3Bucket, name, options)
params.Body = through.pipe(zlib.createGzip())
var upload = this.s3.upload(params, function (err, data) {
if (err && !aborted) input.emit('error', err)
else if (!err) input.emit('finish')
input.destroy()
Expand Down

0 comments on commit 5e90fe7

Please sign in to comment.