@@ -4281,6 +4281,9 @@ describe('File', () => {
42814281 describe ( 'save' , ( ) => {
42824282 const DATA = 'Data!' ;
42834283 const BUFFER_DATA = Buffer . from ( DATA , 'utf8' ) ;
4284+ const UINT8_ARRAY_DATA = Uint8Array . from (
4285+ Array . from ( DATA ) . map ( l => l . charCodeAt ( 0 ) )
4286+ ) ;
42844287
42854288 class DelayedStreamNoError extends Transform {
42864289 _transform ( chunk : string | Buffer , _encoding : string , done : Function ) {
@@ -4318,6 +4321,22 @@ describe('File', () => {
43184321 await file . save ( DATA , options , assert . ifError ) ;
43194322 } ) ;
43204323
4324+ it ( 'should save a buffer with no errors' , async ( ) => {
4325+ const options = { resumable : false } ;
4326+ file . createWriteStream = ( ) => {
4327+ return new DelayedStreamNoError ( ) ;
4328+ } ;
4329+ await file . save ( BUFFER_DATA , options , assert . ifError ) ;
4330+ } ) ;
4331+
4332+ it ( 'should save a Uint8Array with no errors' , async ( ) => {
4333+ const options = { resumable : false } ;
4334+ file . createWriteStream = ( ) => {
4335+ return new DelayedStreamNoError ( ) ;
4336+ } ;
4337+ await file . save ( UINT8_ARRAY_DATA , options , assert . ifError ) ;
4338+ } ) ;
4339+
43214340 it ( 'string upload should retry on first failure' , async ( ) => {
43224341 const options = {
43234342 resumable : false ,
@@ -4363,15 +4382,28 @@ describe('File', () => {
43634382 }
43644383 } ) ;
43654384
4366- it ( 'should save a buffer with no errors' , async ( ) => {
4385+ it ( 'should save a Readable with no errors (String)' , done => {
43674386 const options = { resumable : false } ;
43684387 file . createWriteStream = ( ) => {
4369- return new DelayedStreamNoError ( ) ;
4388+ const writeStream = new PassThrough ( ) ;
4389+ writeStream . on ( 'data' , data => {
4390+ assert . strictEqual ( data . toString ( ) , DATA ) ;
4391+ } ) ;
4392+ writeStream . once ( 'finish' , done ) ;
4393+ return writeStream ;
43704394 } ;
4371- await file . save ( DATA , options , assert . ifError ) ;
4395+
4396+ const readable = new Readable ( {
4397+ read ( ) {
4398+ this . push ( DATA ) ;
4399+ this . push ( null ) ;
4400+ } ,
4401+ } ) ;
4402+
4403+ void file . save ( readable , options ) ;
43724404 } ) ;
43734405
4374- it ( 'should save a Readable with no errors' , done => {
4406+ it ( 'should save a Readable with no errors (Buffer) ' , done => {
43754407 const options = { resumable : false } ;
43764408 file . createWriteStream = ( ) => {
43774409 const writeStream = new PassThrough ( ) ;
@@ -4384,7 +4416,28 @@ describe('File', () => {
43844416
43854417 const readable = new Readable ( {
43864418 read ( ) {
4387- this . push ( DATA ) ;
4419+ this . push ( BUFFER_DATA ) ;
4420+ this . push ( null ) ;
4421+ } ,
4422+ } ) ;
4423+
4424+ void file . save ( readable , options ) ;
4425+ } ) ;
4426+
4427+ it ( 'should save a Readable with no errors (Uint8Array)' , done => {
4428+ const options = { resumable : false } ;
4429+ file . createWriteStream = ( ) => {
4430+ const writeStream = new PassThrough ( ) ;
4431+ writeStream . on ( 'data' , data => {
4432+ assert . strictEqual ( data . toString ( ) , DATA ) ;
4433+ } ) ;
4434+ writeStream . once ( 'finish' , done ) ;
4435+ return writeStream ;
4436+ } ;
4437+
4438+ const readable = new Readable ( {
4439+ read ( ) {
4440+ this . push ( UINT8_ARRAY_DATA ) ;
43884441 this . push ( null ) ;
43894442 } ,
43904443 } ) ;
0 commit comments