diff --git a/CHANGELOG.md b/CHANGELOG.md index f7c42b62c..4333168b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/lib/Files.js b/src/lib/Files.js index 71ab37aa6..f7c63ac0a 100644 --- a/src/lib/Files.js +++ b/src/lib/Files.js @@ -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()