2222
2323var crypto = require ( 'crypto' ) ;
2424var duplexify = require ( 'duplexify' ) ;
25- var nodeutil = require ( 'util' ) ;
2625var stream = require ( 'stream' ) ;
2726var uuid = require ( 'node-uuid' ) ;
2827
@@ -57,31 +56,6 @@ var STORAGE_BASE_URL = 'https://www.googleapis.com/storage/v1/b';
5756 */
5857var STORAGE_UPLOAD_BASE_URL = 'https://www.googleapis.com/upload/storage/v1/b' ;
5958
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-
8559/**
8660 * Google Cloud Storage allows you to store data on Google infrastructure. See
8761 * the guide on {@link https://developers.google.com/storage} to create a
@@ -388,6 +362,7 @@ Bucket.prototype.createWriteStream = function(name, metadata) {
388362 */
389363Bucket . prototype . write = function ( name , options , callback ) {
390364 callback = callback || util . noop ;
365+ var bufferStream ;
391366 var data = typeof options === 'object' ? options . data : options ;
392367 var metadata = options . metadata || { } ;
393368
@@ -398,9 +373,12 @@ Bucket.prototype.write = function(name, options, callback) {
398373 }
399374
400375 if ( typeof data === 'string' || data instanceof Buffer ) {
401- new BufferStream ( data ) . pipe ( this . createWriteStream ( name , metadata ) )
376+ bufferStream = new stream . PassThrough ( ) ;
377+ bufferStream . pipe ( this . createWriteStream ( name , metadata ) )
402378 . on ( 'error' , callback )
403379 . on ( 'complete' , callback . bind ( null , null ) ) ;
380+ bufferStream . push ( data ) ;
381+ bufferStream . push ( null ) ;
404382 }
405383} ;
406384
0 commit comments