Skip to content

Commit 5ae29fb

Browse files
storage: use passthrough stream for buffers.
1 parent b2721e0 commit 5ae29fb

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

lib/storage/index.js

+5-26
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,6 @@ var STORAGE_BASE_URL = 'https://www.googleapis.com/storage/v1/b';
5757
*/
5858
var STORAGE_UPLOAD_BASE_URL = 'https://www.googleapis.com/upload/storage/v1/b';
5959

60-
/**
61-
* Readable stream implementation to stream the given buffer.
62-
*
63-
* @constructor
64-
*
65-
* @param {buffer} buffer - The buffer to stream.
66-
*
67-
* @private
68-
*/
69-
function BufferStream(buffer) {
70-
stream.Readable.call(this);
71-
this.data = buffer;
72-
}
73-
74-
nodeutil.inherits(BufferStream, stream.Readable);
75-
76-
/**
77-
* Push the provided buffer to the stream.
78-
* @private
79-
*/
80-
BufferStream.prototype._read = function() {
81-
this.push(this.data);
82-
this.push(null);
83-
};
84-
8560
/**
8661
* Google Cloud Storage allows you to store data on Google infrastructure. See
8762
* the guide on {@link https://developers.google.com/storage} to create a
@@ -388,6 +363,7 @@ Bucket.prototype.createWriteStream = function(name, metadata) {
388363
*/
389364
Bucket.prototype.write = function(name, options, callback) {
390365
callback = callback || util.noop;
366+
var bufferStream;
391367
var data = typeof options === 'object' ? options.data : options;
392368
var metadata = options.metadata || {};
393369

@@ -398,9 +374,12 @@ Bucket.prototype.write = function(name, options, callback) {
398374
}
399375

400376
if (typeof data === 'string' || data instanceof Buffer) {
401-
new BufferStream(data).pipe(this.createWriteStream(name, metadata))
377+
bufferStream = new stream.PassThrough();
378+
bufferStream.pipe(this.createWriteStream(name, metadata))
402379
.on('error', callback)
403380
.on('complete', callback.bind(null, null));
381+
bufferStream.push(data);
382+
bufferStream.push(null);
404383
}
405384
};
406385

0 commit comments

Comments
 (0)