@@ -154,7 +154,7 @@ export class S3Bucket {
154
154
etag : JSON . parse ( res . headers . get ( "etag" ) ! ) ,
155
155
lastModified : new Date ( res . headers . get ( "Last-Modified" ) ! ) ,
156
156
missingMeta : parseInt ( res . headers . get ( "x-amz-missing-meta" ) ?? "0" ) ,
157
- storageClass : res . headers . get ( "x-amz-storage-class" ) as StorageClass ??
157
+ storageClass : ( res . headers . get ( "x-amz-storage-class" ) as StorageClass ) ??
158
158
"STANDARD" ,
159
159
taggingCount : parseInt ( res . headers . get ( "x-amz-tagging-count" ) ?? "0" ) ,
160
160
@@ -164,13 +164,13 @@ export class S3Bucket {
164
164
contentLanguage : res . headers . get ( "Content-Language" ) ?? undefined ,
165
165
contentType : res . headers . get ( "Content-Type" ) ?? undefined ,
166
166
expires : expires ? new Date ( expires ) : undefined ,
167
- legalHold : legalHold ? true : ( legalHold === "OFF" ? false : undefined ) ,
168
- lockMode : res . headers . get ( "x-amz-object-lock-mode" ) as LockMode ??
167
+ legalHold : legalHold ? true : legalHold === "OFF" ? false : undefined ,
168
+ lockMode : ( res . headers . get ( "x-amz-object-lock-mode" ) as LockMode ) ??
169
169
undefined ,
170
170
lockRetainUntil : lockRetainUntil ? new Date ( lockRetainUntil ) : undefined ,
171
171
partsCount : partsCount ? parseInt ( partsCount ) : undefined ,
172
172
replicationStatus :
173
- res . headers . get ( "x-amz-replication-status" ) as ReplicationStatus ??
173
+ ( res . headers . get ( "x-amz-replication-status" ) as ReplicationStatus ) ??
174
174
undefined ,
175
175
versionId : res . headers . get ( "x-amz-version-id" ) ?? undefined ,
176
176
websiteRedirectLocation :
@@ -245,14 +245,18 @@ export class S3Bucket {
245
245
}
246
246
}
247
247
248
+ if ( res . body == null ) {
249
+ throw new S3Error ( "S3 did not return a body for a getObject call." , "" ) ;
250
+ }
251
+
248
252
return {
249
- body : new Uint8Array ( await res . arrayBuffer ( ) ) ,
253
+ body : res . body ,
250
254
contentLength : parseInt ( res . headers . get ( "Content-Length" ) ! ) ,
251
255
deleteMarker : res . headers . get ( "x-amz-delete-marker" ) === "true" ,
252
256
etag : JSON . parse ( res . headers . get ( "etag" ) ! ) ,
253
257
lastModified : new Date ( res . headers . get ( "Last-Modified" ) ! ) ,
254
258
missingMeta : parseInt ( res . headers . get ( "x-amz-missing-meta" ) ?? "0" ) ,
255
- storageClass : res . headers . get ( "x-amz-storage-class" ) as StorageClass ??
259
+ storageClass : ( res . headers . get ( "x-amz-storage-class" ) as StorageClass ) ??
256
260
"STANDARD" ,
257
261
taggingCount : parseInt ( res . headers . get ( "x-amz-tagging-count" ) ?? "0" ) ,
258
262
@@ -262,13 +266,13 @@ export class S3Bucket {
262
266
contentLanguage : res . headers . get ( "Content-Language" ) ?? undefined ,
263
267
contentType : res . headers . get ( "Content-Type" ) ?? undefined ,
264
268
expires : expires ? new Date ( expires ) : undefined ,
265
- legalHold : legalHold ? true : ( legalHold === "OFF" ? false : undefined ) ,
266
- lockMode : res . headers . get ( "x-amz-object-lock-mode" ) as LockMode ??
269
+ legalHold : legalHold ? true : legalHold === "OFF" ? false : undefined ,
270
+ lockMode : ( res . headers . get ( "x-amz-object-lock-mode" ) as LockMode ) ??
267
271
undefined ,
268
272
lockRetainUntil : lockRetainUntil ? new Date ( lockRetainUntil ) : undefined ,
269
273
partsCount : partsCount ? parseInt ( partsCount ) : undefined ,
270
274
replicationStatus :
271
- res . headers . get ( "x-amz-replication-status" ) as ReplicationStatus ??
275
+ ( res . headers . get ( "x-amz-replication-status" ) as ReplicationStatus ) ??
272
276
undefined ,
273
277
versionId : res . headers . get ( "x-amz-version-id" ) ?? undefined ,
274
278
websiteRedirectLocation :
@@ -295,12 +299,7 @@ export class S3Bucket {
295
299
params [ "continuation-token" ] = options . continuationToken ;
296
300
}
297
301
298
- const res = await this . _doRequest (
299
- `/` ,
300
- params ,
301
- "GET" ,
302
- headers ,
303
- ) ;
302
+ const res = await this . _doRequest ( `/` , params , "GET" , headers ) ;
304
303
if ( res . status === 404 ) {
305
304
// clean up http body
306
305
await res . arrayBuffer ( ) ;
@@ -345,37 +344,38 @@ export class S3Bucket {
345
344
isTruncated : extractContent ( root , "IsTruncated" ) === "true"
346
345
? true
347
346
: false ,
348
- contents : root . children . filter ( ( node ) => node . name === "Contents" ) . map <
349
- S3Object
350
- > ( ( s3obj ) => {
351
- let lastmod : Date | undefined ;
352
- let content = extractContent ( s3obj , "LastModified" ) ;
353
- if ( content ) {
354
- lastmod = new Date ( content ) ;
355
- }
347
+ contents : root . children
348
+ . filter ( ( node ) => node . name === "Contents" )
349
+ . map < S3Object > ( ( s3obj ) => {
350
+ let lastmod : Date | undefined ;
351
+ let content = extractContent ( s3obj , "LastModified" ) ;
352
+ if ( content ) {
353
+ lastmod = new Date ( content ) ;
354
+ }
356
355
357
- let size : number | undefined ;
358
- content = extractContent ( s3obj , "Size" ) ;
359
- if ( content ) {
360
- size = parseInt ( content ) ;
361
- }
356
+ let size : number | undefined ;
357
+ content = extractContent ( s3obj , "Size" ) ;
358
+ if ( content ) {
359
+ size = parseInt ( content ) ;
360
+ }
362
361
363
- return {
364
- key : extractContent ( s3obj , "Key" ) ,
365
- lastModified : lastmod ,
366
- eTag : extractContent ( s3obj , "ETag" ) ,
367
- size : size ,
368
- storageClass : extractContent ( s3obj , "StorageClass" ) ,
369
- owner : extractContent ( s3obj , "Owner" ) ,
370
- } ;
371
- } ) ,
362
+ return {
363
+ key : extractContent ( s3obj , "Key" ) ,
364
+ lastModified : lastmod ,
365
+ eTag : extractContent ( s3obj , "ETag" ) ,
366
+ size : size ,
367
+ storageClass : extractContent ( s3obj , "StorageClass" ) ,
368
+ owner : extractContent ( s3obj , "Owner" ) ,
369
+ } ;
370
+ } ) ,
372
371
name : extractContent ( root , "Name" ) ,
373
372
prefix : extractContent ( root , "Prefix" ) ,
374
373
delimiter : extractContent ( root , "Delimiter" ) ,
375
374
maxKeys : maxkeys ,
376
- commonPrefixes : extractField ( root , "CommonPrefixes" ) ?. children . map <
377
- CommonPrefix
378
- > ( ( prefix ) => {
375
+ commonPrefixes : extractField (
376
+ root ,
377
+ "CommonPrefixes" ,
378
+ ) ?. children . map < CommonPrefix > ( ( prefix ) => {
379
379
return {
380
380
prefix : extractContent ( prefix , "Prefix" ) ,
381
381
} ;
@@ -449,8 +449,9 @@ export class S3Bucket {
449
449
}
450
450
if ( options ?. lockMode ) headers [ "x-amz-object-lock-mode" ] = options . lockMode ;
451
451
if ( options ?. lockRetainUntil ) {
452
- headers [ "x-amz-object-lock-retain-until-date" ] = options . lockRetainUntil
453
- . toString ( ) ;
452
+ headers [
453
+ "x-amz-object-lock-retain-until-date"
454
+ ] = options . lockRetainUntil . toString ( ) ;
454
455
}
455
456
if ( options ?. legalHold ) {
456
457
headers [ "x-amz-object-lock-legal-hold" ] = options . legalHold
@@ -463,13 +464,7 @@ export class S3Bucket {
463
464
}
464
465
}
465
466
466
- const resp = await this . _doRequest (
467
- key ,
468
- { } ,
469
- "PUT" ,
470
- headers ,
471
- body ,
472
- ) ;
467
+ const resp = await this . _doRequest ( key , { } , "PUT" , headers , body ) ;
473
468
if ( resp . status !== 200 ) {
474
469
throw new S3Error (
475
470
`Failed to put object: ${ resp . status } ${ resp . statusText } ` ,
@@ -490,8 +485,10 @@ export class S3Bucket {
490
485
options ?: CopyObjectOptions ,
491
486
) : Promise < PutObjectResponse > {
492
487
const headers : Params = { } ;
493
- headers [ "x-amz-copy-source" ] = new URL ( encodeURIS3 ( source ) , this . #host)
494
- . toString ( ) ;
488
+ headers [ "x-amz-copy-source" ] = new URL (
489
+ encodeURIS3 ( source ) ,
490
+ this . #host,
491
+ ) . toString ( ) ;
495
492
if ( options ?. acl ) headers [ "x-amz-acl" ] = options . acl ;
496
493
if ( options ?. cacheControl ) headers [ "Cache-Control" ] = options . cacheControl ;
497
494
if ( options ?. contentDisposition ) {
@@ -511,14 +508,14 @@ export class S3Bucket {
511
508
headers [ "x-amz-copy-source-if-none-match" ] = options . copyOnlyIfNoneMatch ;
512
509
}
513
510
if ( options ?. copyOnlyIfModifiedSince ) {
514
- headers [ "x-amz-copy-source-if-modified-since" ] = options
515
- . copyOnlyIfModifiedSince
516
- . toISOString ( ) ;
511
+ headers [
512
+ "x-amz-copy-source-if-modified-since"
513
+ ] = options . copyOnlyIfModifiedSince . toISOString ( ) ;
517
514
}
518
515
if ( options ?. copyOnlyIfUnmodifiedSince ) {
519
- headers [ "x-amz-copy-source-if-unmodified-since" ] = options
520
- . copyOnlyIfUnmodifiedSince
521
- . toISOString ( ) ;
516
+ headers [
517
+ "x-amz-copy-source-if-unmodified-since"
518
+ ] = options . copyOnlyIfUnmodifiedSince . toISOString ( ) ;
522
519
}
523
520
if ( options ?. grantFullControl ) {
524
521
headers [ "x-amz-grant-full-control" ] = options . grantFullControl ;
@@ -544,8 +541,9 @@ export class S3Bucket {
544
541
}
545
542
if ( options ?. lockMode ) headers [ "x-amz-object-lock-mode" ] = options . lockMode ;
546
543
if ( options ?. lockRetainUntil ) {
547
- headers [ "x-amz-object-lock-retain-until-date" ] = options . lockRetainUntil
548
- . toString ( ) ;
544
+ headers [
545
+ "x-amz-object-lock-retain-until-date"
546
+ ] = options . lockRetainUntil . toString ( ) ;
549
547
}
550
548
if ( options ?. legalHold ) {
551
549
headers [ "x-amz-object-lock-legal-hold" ] = options . legalHold
@@ -559,12 +557,7 @@ export class S3Bucket {
559
557
headers [ "x-amz-tagging-directive" ] = options . taggingDirective ;
560
558
}
561
559
562
- const resp = await this . _doRequest (
563
- destination ,
564
- { } ,
565
- "PUT" ,
566
- headers ,
567
- ) ;
560
+ const resp = await this . _doRequest ( destination , { } , "PUT" , headers ) ;
568
561
if ( resp . status !== 200 ) {
569
562
throw new S3Error (
570
563
`Failed to copy object: ${ resp . status } ${ resp . statusText } ` ,
@@ -629,8 +622,12 @@ function encodeURIS3(input: string): string {
629
622
let result = "" ;
630
623
for ( const ch of input ) {
631
624
if (
632
- ( ch >= "A" && ch <= "Z" ) || ( ch >= "a" && ch <= "z" ) ||
633
- ( ch >= "0" && ch <= "9" ) || ch == "_" || ch == "-" || ch == "~" ||
625
+ ( ch >= "A" && ch <= "Z" ) ||
626
+ ( ch >= "a" && ch <= "z" ) ||
627
+ ( ch >= "0" && ch <= "9" ) ||
628
+ ch == "_" ||
629
+ ch == "-" ||
630
+ ch == "~" ||
634
631
ch == "."
635
632
) {
636
633
result += ch ;
@@ -646,7 +643,9 @@ function encodeURIS3(input: string): string {
646
643
const encoder = new TextEncoder ( ) ;
647
644
648
645
function stringToHex ( input : string ) {
649
- return [ ...encoder . encode ( input ) ] . map ( ( s ) => "%" + s . toString ( 16 ) ) . join ( "" )
646
+ return [ ...encoder . encode ( input ) ]
647
+ . map ( ( s ) => "%" + s . toString ( 16 ) )
648
+ . join ( "" )
650
649
. toUpperCase ( ) ;
651
650
}
652
651
@@ -674,17 +673,11 @@ function extractRoot(doc: Document, name: string): Xml {
674
673
return doc . root ;
675
674
}
676
675
677
- function extractField (
678
- node : Xml ,
679
- name : string ,
680
- ) : Xml | undefined {
676
+ function extractField ( node : Xml , name : string ) : Xml | undefined {
681
677
return node . children . find ( ( node ) => node . name === name ) ;
682
678
}
683
679
684
- function extractContent (
685
- node : Xml ,
686
- name : string ,
687
- ) : string | undefined {
680
+ function extractContent ( node : Xml , name : string ) : string | undefined {
688
681
const field = extractField ( node , name ) ;
689
682
const content = field ?. content ;
690
683
if ( content === undefined ) {
0 commit comments