@@ -904,7 +904,7 @@ export class TypedClient {
904
904
* Creates the bucket `bucketName`.
905
905
*
906
906
*/
907
- async makeBucket ( bucketName : string , region : Region = '' , makeOpts : MakeBucketOpt = { } ) : Promise < void > {
907
+ async makeBucket ( bucketName : string , region : Region = '' , makeOpts ? : MakeBucketOpt ) : Promise < void > {
908
908
if ( ! isValidBucketName ( bucketName ) ) {
909
909
throw new errors . InvalidBucketNameError ( 'Invalid bucket name: ' + bucketName )
910
910
}
@@ -917,7 +917,7 @@ export class TypedClient {
917
917
if ( ! isString ( region ) ) {
918
918
throw new TypeError ( 'region should be of type "string"' )
919
919
}
920
- if ( ! isObject ( makeOpts ) ) {
920
+ if ( makeOpts && ! isObject ( makeOpts ) ) {
921
921
throw new TypeError ( 'makeOpts should be of type "object"' )
922
922
}
923
923
@@ -943,7 +943,7 @@ export class TypedClient {
943
943
const method = 'PUT'
944
944
const headers : RequestHeaders = { }
945
945
946
- if ( makeOpts . ObjectLocking ) {
946
+ if ( makeOpts && makeOpts . ObjectLocking ) {
947
947
headers [ 'x-amz-bucket-object-lock-enabled' ] = true
948
948
}
949
949
@@ -1009,7 +1009,7 @@ export class TypedClient {
1009
1009
/**
1010
1010
* Callback is called with readable stream of the object content.
1011
1011
*/
1012
- async getObject ( bucketName : string , objectName : string , getOpts : GetObjectOpts = { } ) : Promise < stream . Readable > {
1012
+ async getObject ( bucketName : string , objectName : string , getOpts ? : GetObjectOpts ) : Promise < stream . Readable > {
1013
1013
if ( ! isValidBucketName ( bucketName ) ) {
1014
1014
throw new errors . InvalidBucketNameError ( 'Invalid bucket name: ' + bucketName )
1015
1015
}
@@ -1032,7 +1032,7 @@ export class TypedClient {
1032
1032
objectName : string ,
1033
1033
offset : number ,
1034
1034
length = 0 ,
1035
- getOpts : GetObjectOpts = { } ,
1035
+ getOpts ? : GetObjectOpts ,
1036
1036
) : Promise < stream . Readable > {
1037
1037
if ( ! isValidBucketName ( bucketName ) ) {
1038
1038
throw new errors . InvalidBucketNameError ( 'Invalid bucket name: ' + bucketName )
@@ -1060,17 +1060,26 @@ export class TypedClient {
1060
1060
}
1061
1061
}
1062
1062
1063
- const sseHeaders : Record < string , string > = {
1064
- ...( getOpts . SSECustomerAlgorithm && {
1065
- 'X-Amz-Server-Side-Encryption-Customer-Algorithm' : getOpts . SSECustomerAlgorithm ,
1066
- } ) ,
1067
- ...( getOpts . SSECustomerKey && { 'X-Amz-Server-Side-Encryption-Customer-Key' : getOpts . SSECustomerKey } ) ,
1068
- ...( getOpts . SSECustomerKeyMD5 && { 'X-Amz-Server-Side-Encryption-Customer-Key-MD5' : getOpts . SSECustomerKeyMD5 } ) ,
1063
+ let query = ''
1064
+ let headers : RequestHeaders = {
1065
+ ...( range !== '' && { range } ) ,
1069
1066
}
1070
1067
1071
- const headers : RequestHeaders = {
1072
- ...prependXAMZMeta ( sseHeaders ) ,
1073
- ...( range !== '' && { range } ) ,
1068
+ if ( getOpts ) {
1069
+ const sseHeaders : Record < string , string > = {
1070
+ ...( getOpts . SSECustomerAlgorithm && {
1071
+ 'X-Amz-Server-Side-Encryption-Customer-Algorithm' : getOpts . SSECustomerAlgorithm ,
1072
+ } ) ,
1073
+ ...( getOpts . SSECustomerKey && { 'X-Amz-Server-Side-Encryption-Customer-Key' : getOpts . SSECustomerKey } ) ,
1074
+ ...( getOpts . SSECustomerKeyMD5 && {
1075
+ 'X-Amz-Server-Side-Encryption-Customer-Key-MD5' : getOpts . SSECustomerKeyMD5 ,
1076
+ } ) ,
1077
+ }
1078
+ query = qs . stringify ( getOpts )
1079
+ headers = {
1080
+ ...prependXAMZMeta ( sseHeaders ) ,
1081
+ ...headers ,
1082
+ }
1074
1083
}
1075
1084
1076
1085
const expectedStatusCodes = [ 200 ]
@@ -1079,7 +1088,6 @@ export class TypedClient {
1079
1088
}
1080
1089
const method = 'GET'
1081
1090
1082
- const query = qs . stringify ( getOpts )
1083
1091
return await this . makeRequestAsync ( { method, bucketName, objectName, headers, query } , '' , expectedStatusCodes )
1084
1092
}
1085
1093
@@ -1092,12 +1100,7 @@ export class TypedClient {
1092
1100
* @param filePath - path to which the object data will be written to
1093
1101
* @param getOpts - Optional object get option
1094
1102
*/
1095
- async fGetObject (
1096
- bucketName : string ,
1097
- objectName : string ,
1098
- filePath : string ,
1099
- getOpts : GetObjectOpts = { } ,
1100
- ) : Promise < void > {
1103
+ async fGetObject ( bucketName : string , objectName : string , filePath : string , getOpts ?: GetObjectOpts ) : Promise < void > {
1101
1104
// Input validation.
1102
1105
if ( ! isValidBucketName ( bucketName ) ) {
1103
1106
throw new errors . InvalidBucketNameError ( 'Invalid bucket name: ' + bucketName )
@@ -1153,19 +1156,20 @@ export class TypedClient {
1153
1156
/**
1154
1157
* Stat information of the object.
1155
1158
*/
1156
- async statObject ( bucketName : string , objectName : string , statOpts : StatObjectOpts = { } ) : Promise < BucketItemStat > {
1159
+ async statObject ( bucketName : string , objectName : string , statOpts ?: StatObjectOpts ) : Promise < BucketItemStat > {
1160
+ const statOptDef = statOpts || { }
1157
1161
if ( ! isValidBucketName ( bucketName ) ) {
1158
1162
throw new errors . InvalidBucketNameError ( 'Invalid bucket name: ' + bucketName )
1159
1163
}
1160
1164
if ( ! isValidObjectName ( objectName ) ) {
1161
1165
throw new errors . InvalidObjectNameError ( `Invalid object name: ${ objectName } ` )
1162
1166
}
1163
1167
1164
- if ( ! isObject ( statOpts ) ) {
1168
+ if ( ! isObject ( statOptDef ) ) {
1165
1169
throw new errors . InvalidArgumentError ( 'statOpts should be of type "object"' )
1166
1170
}
1167
1171
1168
- const query = qs . stringify ( statOpts )
1172
+ const query = qs . stringify ( statOptDef )
1169
1173
const method = 'HEAD'
1170
1174
const res = await this . makeRequestAsyncOmit ( { method, bucketName, objectName, query } )
1171
1175
@@ -1574,7 +1578,7 @@ export class TypedClient {
1574
1578
/**
1575
1579
* Uploads the object using contents from a file
1576
1580
*/
1577
- async fPutObject ( bucketName : string , objectName : string , filePath : string , metaData : ObjectMetaData = { } ) {
1581
+ async fPutObject ( bucketName : string , objectName : string , filePath : string , metaData ? : ObjectMetaData ) {
1578
1582
if ( ! isValidBucketName ( bucketName ) ) {
1579
1583
throw new errors . InvalidBucketNameError ( 'Invalid bucket name: ' + bucketName )
1580
1584
}
@@ -1585,12 +1589,12 @@ export class TypedClient {
1585
1589
if ( ! isString ( filePath ) ) {
1586
1590
throw new TypeError ( 'filePath should be of type "string"' )
1587
1591
}
1588
- if ( ! isObject ( metaData ) ) {
1592
+ if ( metaData && ! isObject ( metaData ) ) {
1589
1593
throw new TypeError ( 'metaData should be of type "object"' )
1590
1594
}
1591
1595
1592
1596
// Inserts correct `content-type` attribute based on metaData and filePath
1593
- metaData = insertContentType ( metaData , filePath )
1597
+ metaData = insertContentType ( metaData || { } , filePath )
1594
1598
const stat = await fsp . lstat ( filePath )
1595
1599
return await this . putObject ( bucketName , objectName , fs . createReadStream ( filePath ) , stat . size , metaData )
1596
1600
}
@@ -1945,7 +1949,7 @@ export class TypedClient {
1945
1949
/**
1946
1950
* Get the tags associated with a bucket OR an object
1947
1951
*/
1948
- async getObjectTagging ( bucketName : string , objectName : string , getOpts : GetObjectOpts = { } ) : Promise < Tag [ ] > {
1952
+ async getObjectTagging ( bucketName : string , objectName : string , getOpts ? : GetObjectOpts ) : Promise < Tag [ ] > {
1949
1953
const method = 'GET'
1950
1954
let query = 'tagging'
1951
1955
@@ -1955,7 +1959,7 @@ export class TypedClient {
1955
1959
if ( ! isValidObjectName ( objectName ) ) {
1956
1960
throw new errors . InvalidBucketNameError ( 'Invalid object name: ' + objectName )
1957
1961
}
1958
- if ( ! isObject ( getOpts ) ) {
1962
+ if ( getOpts && ! isObject ( getOpts ) ) {
1959
1963
throw new errors . InvalidArgumentError ( 'getOpts should be of type "object"' )
1960
1964
}
1961
1965
0 commit comments