diff --git a/lib/storage/index.js b/lib/storage/index.js index 49e272e75c9..b25736cfff9 100644 --- a/lib/storage/index.js +++ b/lib/storage/index.js @@ -22,7 +22,6 @@ var crypto = require('crypto'); var duplexify = require('duplexify'); -var nodeutil = require('util'); var stream = require('stream'); var uuid = require('node-uuid'); @@ -57,31 +56,6 @@ var STORAGE_BASE_URL = 'https://www.googleapis.com/storage/v1/b'; */ var STORAGE_UPLOAD_BASE_URL = 'https://www.googleapis.com/upload/storage/v1/b'; -/** - * Readable stream implementation to stream the given buffer. - * - * @constructor - * - * @param {buffer} buffer - The buffer to stream. - * - * @private - */ -function BufferStream(buffer) { - stream.Readable.call(this); - this.data = buffer; -} - -nodeutil.inherits(BufferStream, stream.Readable); - -/** - * Push the provided buffer to the stream. - * @private - */ -BufferStream.prototype._read = function() { - this.push(this.data); - this.push(null); -}; - /** * Google Cloud Storage allows you to store data on Google infrastructure. See * the guide on {@link https://developers.google.com/storage} to create a @@ -388,6 +362,7 @@ Bucket.prototype.createWriteStream = function(name, metadata) { */ Bucket.prototype.write = function(name, options, callback) { callback = callback || util.noop; + var bufferStream; var data = typeof options === 'object' ? options.data : options; var metadata = options.metadata || {}; @@ -398,9 +373,12 @@ Bucket.prototype.write = function(name, options, callback) { } if (typeof data === 'string' || data instanceof Buffer) { - new BufferStream(data).pipe(this.createWriteStream(name, metadata)) + bufferStream = new stream.PassThrough(); + bufferStream.pipe(this.createWriteStream(name, metadata)) .on('error', callback) .on('complete', callback.bind(null, null)); + bufferStream.push(data); + bufferStream.push(null); } };