@@ -122,8 +122,8 @@ async function test_put_chunked_object(upload_config) {
122
122
dbg . log0 ( 'PutObject response:' , put_object_response ) ;
123
123
assert . ok ( put_object_response . ETag ) ;
124
124
125
- const get_object_res = await get_object ( s3 , bucket , key ) ;
126
- assert . equal ( get_object_res . body , random_data_buffer . toString ( ) ) ;
125
+ const get_object_res = await get_object_buffer ( s3 , bucket , key ) ;
126
+ assert . ok ( random_data_buffer . equals ( get_object_res . body ) , 'Uploaded and downloaded data differ' ) ;
127
127
assert . equal ( get_object_res . ETag , put_object_response . ETag ) ;
128
128
129
129
await delete_object ( s3 , bucket , key ) ;
@@ -155,7 +155,7 @@ async function test_chunked_mpu(mpu_config) {
155
155
assert . ok ( create_mpu_response . UploadId ) ;
156
156
157
157
const parts = [ ] ;
158
- let original_string = '' ;
158
+ let original_buffer = Buffer . alloc ( 0 ) ;
159
159
for ( let i = 1 ; i <= parts_num ; i ++ ) {
160
160
const random_data_buffer = crypto . randomBytes ( size ) ;
161
161
const random_data_stream = buffer_utils . buffer_to_read_stream ( random_data_buffer ) ;
@@ -171,7 +171,7 @@ async function test_chunked_mpu(mpu_config) {
171
171
dbg . log0 ( 'MPU upload_part_response:' , upload_part_response ) ;
172
172
assert . ok ( upload_part_response . ETag ) ;
173
173
parts . push ( { PartNumber : i , ETag : upload_part_response . ETag } ) ;
174
- original_string += random_data_buffer . toString ( ) ;
174
+ original_buffer = Buffer . concat ( [ original_buffer , random_data_buffer ] ) ;
175
175
}
176
176
177
177
const complete_mpu_input = { Bucket : bucket , Key : key , UploadId : create_mpu_response . UploadId , MultipartUpload : { Parts : parts } } ;
@@ -180,19 +180,18 @@ async function test_chunked_mpu(mpu_config) {
180
180
dbg . log0 ( 'MPU complete_mpu_response:' , complete_mpu_response ) ;
181
181
assert . ok ( complete_mpu_response . ETag ) ;
182
182
183
- const get_object_res = await get_object ( s3 , bucket , key ) ;
184
- assert . equal ( get_object_res . body , original_string ) ;
183
+ const get_object_res = await get_object_buffer ( s3 , bucket , key ) ;
184
+ assert . ok ( original_buffer . equals ( get_object_res . body ) , 'Uploaded and downloaded data differ' ) ;
185
185
186
186
await delete_object ( s3 , bucket , key ) ;
187
187
}
188
188
189
189
/**
190
190
* validate_request_headers - Middleware to log and validate request headers
191
191
* @param {S3Client } s3
192
- * @returns {Promise<Object > } - Returns the request headers after the middleware is executed
192
+ * @returns {Promise<void > } - Returns the S3 client with the middleware added
193
193
*/
194
194
async function validate_request_headers ( s3 ) {
195
- let request_headers ;
196
195
s3 . middlewareStack . add (
197
196
( next , context ) => async args => {
198
197
const command = context . commandName ;
@@ -217,22 +216,21 @@ async function validate_request_headers(s3) {
217
216
priority : 'high' ,
218
217
}
219
218
) ;
220
- return request_headers ;
221
219
}
222
220
223
221
/**
224
- * get_object - Get an object from S3 bucket
222
+ * get_object_buffer - Retrieve an object from S3 bucket and return its content as a Buffer along with its ETag
225
223
* @param {S3Client } s3
226
224
* @param {String } bucket
227
225
* @param {String } key
228
- * @returns {Promise<{body: String , ETag: String}> } - The content of the object as a string
226
+ * @returns {Promise<{body: Buffer , ETag: String}> } - The content of the object as a Buffer and its ETag
229
227
*/
230
- async function get_object ( s3 , bucket , key ) {
228
+ async function get_object_buffer ( s3 , bucket , key ) {
231
229
const get_object_command = new GetObjectCommand ( { Bucket : bucket , Key : key } ) ;
232
230
const get_object_response = await s3 . send ( get_object_command ) ;
233
231
dbg . log0 ( 'GetObject response:' , _ . omit ( get_object_response , [ 'Body' ] ) ) ;
234
- const body = await get_object_response . Body . transformToString ( ) ;
235
- return { body, ETag : get_object_response . ETag } ;
232
+ const body = await get_object_response . Body . transformToByteArray ( ) ;
233
+ return { body : Buffer . from ( body ) , ETag : get_object_response . ETag } ;
236
234
}
237
235
238
236
/**
0 commit comments