@@ -4281,6 +4281,9 @@ describe('File', () => {
4281
4281
describe ( 'save' , ( ) => {
4282
4282
const DATA = 'Data!' ;
4283
4283
const BUFFER_DATA = Buffer . from ( DATA , 'utf8' ) ;
4284
+ const UINT8_ARRAY_DATA = Uint8Array . from (
4285
+ Array . from ( DATA ) . map ( l => l . charCodeAt ( 0 ) )
4286
+ ) ;
4284
4287
4285
4288
class DelayedStreamNoError extends Transform {
4286
4289
_transform ( chunk : string | Buffer , _encoding : string , done : Function ) {
@@ -4318,6 +4321,22 @@ describe('File', () => {
4318
4321
await file . save ( DATA , options , assert . ifError ) ;
4319
4322
} ) ;
4320
4323
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
+
4321
4340
it ( 'string upload should retry on first failure' , async ( ) => {
4322
4341
const options = {
4323
4342
resumable : false ,
@@ -4363,15 +4382,28 @@ describe('File', () => {
4363
4382
}
4364
4383
} ) ;
4365
4384
4366
- it ( 'should save a buffer with no errors' , async ( ) => {
4385
+ it ( 'should save a Readable with no errors (String)' , done => {
4367
4386
const options = { resumable : false } ;
4368
4387
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 ;
4370
4394
} ;
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 ) ;
4372
4404
} ) ;
4373
4405
4374
- it ( 'should save a Readable with no errors' , done => {
4406
+ it ( 'should save a Readable with no errors (Buffer) ' , done => {
4375
4407
const options = { resumable : false } ;
4376
4408
file . createWriteStream = ( ) => {
4377
4409
const writeStream = new PassThrough ( ) ;
@@ -4384,7 +4416,28 @@ describe('File', () => {
4384
4416
4385
4417
const readable = new Readable ( {
4386
4418
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 ) ;
4388
4441
this . push ( null ) ;
4389
4442
} ,
4390
4443
} ) ;
0 commit comments