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