@@ -57,31 +57,6 @@ var STORAGE_BASE_URL = 'https://www.googleapis.com/storage/v1/b';
57
57
*/
58
58
var STORAGE_UPLOAD_BASE_URL = 'https://www.googleapis.com/upload/storage/v1/b' ;
59
59
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
-
85
60
/**
86
61
* Google Cloud Storage allows you to store data on Google infrastructure. See
87
62
* the guide on {@link https://developers.google.com/storage} to create a
@@ -388,6 +363,7 @@ Bucket.prototype.createWriteStream = function(name, metadata) {
388
363
*/
389
364
Bucket . prototype . write = function ( name , options , callback ) {
390
365
callback = callback || util . noop ;
366
+ var bufferStream ;
391
367
var data = typeof options === 'object' ? options . data : options ;
392
368
var metadata = options . metadata || { } ;
393
369
@@ -398,9 +374,12 @@ Bucket.prototype.write = function(name, options, callback) {
398
374
}
399
375
400
376
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 ) )
402
379
. on ( 'error' , callback )
403
380
. on ( 'complete' , callback . bind ( null , null ) ) ;
381
+ bufferStream . push ( data ) ;
382
+ bufferStream . push ( null ) ;
404
383
}
405
384
} ;
406
385
0 commit comments