Skip to content

Commit f5ec83c

Browse files
committed
read_object_stream method
1 parent 9704f13 commit f5ec83c

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/sdk/namespace_s3.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class NamespaceS3 {
3535
this.access_key = s3_params.accessKeyId;
3636
this.endpoint = s3_params.endpoint;
3737
this.s3 = noobaa_s3_client.get_s3_client_v3_params(s3_params);
38+
if (!bucket) {
39+
throw new Error('NamespaceS3: bucket is required');
40+
}
3841
this.bucket = String(bucket);
3942
this.access_mode = s3_params.access_mode;
4043
this.stats = stats;
@@ -207,8 +210,10 @@ class NamespaceS3 {
207210
await this.s3.getObject(request) :
208211
await this.s3.headObject(request);
209212
} catch (err) {
210-
// catch invalid range error for objects of size 0 and trying head object instead
211-
if (err.code !== 'InvalidRange') {
213+
// catch invalid range error for objects of size 0 and try head object instead
214+
const httpCode = err?.$metadata?.httpStatusCode;
215+
const isInvalidRange = err?.name === 'InvalidRange' || httpCode === 416;
216+
if (!isInvalidRange) {
212217
throw err;
213218
}
214219
res = await this.s3.headObject({ ...request, Range: undefined });
@@ -256,7 +261,8 @@ class NamespaceS3 {
256261
this.bucket,
257262
inspect(_.omit(params, 'object_md.ns')),
258263
);
259-
if (obj_out.$metadata.httpStatusCode >= 300) return; // will be handled by error event
264+
// In v3, non-2xx typically throws; keep this guard harmless.
265+
if (obj_out.$metadata.httpStatusCode >= 300) throw new Error(`S3 getObject failed with status ${obj_out.$metadata.httpStatusCode}`);
260266
let count = 1;
261267
// on s3 read_object_md might not return x-amz-tagging-count header, so we get it here
262268
//params.tag_count = headers['x-amz-tagging-count'];
@@ -270,12 +276,13 @@ class NamespaceS3 {
270276
// clear count for next updates
271277
count = 0;
272278
});
273-
const read_stream = /** @type {import('stream').Readable} **/ obj_out.Body.transformToWebStream();
274-
await stream_utils.pipeline([read_stream, count_stream], true);
275-
return count_stream;
279+
const read_stream = /** @type {import('stream').Readable} */ (obj_out.Body);
280+
// Return a live stream to be piped by the caller (endpoint)
281+
return read_stream.pipe(count_stream);
276282
} catch (err) {
277283
this._translate_error_code(params, err);
278284
dbg.warn('NamespaceS3.read_object_stream:', inspect(err));
285+
throw err;
279286
}
280287
}
281288

@@ -350,16 +357,15 @@ class NamespaceS3 {
350357
}
351358
}
352359
dbg.log0('NamespaceS3.upload_object:', this.bucket, inspect(params), 'res', inspect(res));
353-
const etag = s3_utils.parse_etag(res.ETag);
354-
/** @type {import("@aws-sdk/client-s3").GetObjectAttributesRequest} */
360+
const etag = s3_utils.parse_etag(res.ETag || res.CopyObjectResult?.ETag);
361+
/** @type {import("@aws-sdk/client-s3").HeadObjectRequest} */
355362
const request = {
356363
Bucket: this.bucket,
357364
Key: params.key,
358365
VersionId: params.version_id,
359-
ObjectAttributes: params.attributes,
360366
};
361367
const res_head = await this.s3.headObject(request);
362-
const last_modified_time = await s3_utils.get_http_response_date(res_head, this.s3, this.bucket, params.key);
368+
const last_modified_time = await s3_utils.get_http_response_date(res_head);
363369
return { etag, version_id: res.VersionId, last_modified_time };
364370
}
365371

@@ -477,7 +483,7 @@ class NamespaceS3 {
477483
Key: params.key,
478484
UploadId: params.obj_id,
479485
MaxParts: params.max,
480-
PartNumberMarker: params.num_marker.toString(),
486+
PartNumberMarker: params.num_marker?.toString(),
481487
};
482488
const res = await this.s3.listParts(req);
483489
dbg.log0('NamespaceS3.list_multiparts:', this.bucket, inspect(params), 'res', inspect(res));

src/sdk/object_sdk.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,7 @@ class ObjectSDK {
470470
region: config.DEFAULT_REGION, // SDKv3 needs region
471471
forcePathStyle: true,
472472
requestHandler: noobaa_s3_client.get_requestHandler_with_suitable_agent(r.endpoint),
473-
requestStreamBufferSize: config.IO_STREAM_SPLIT_SIZE,
474-
computeChecksums: false, // disabled by default for performance
475473
access_mode: r.access_mode,
476-
//signatureVersion: cloud_utils.get_s3_endpoint_signature_ver(r.endpoint, r.auth_method)
477474
},
478475
bucket: r.target_bucket,
479476
stats: this.stats,

0 commit comments

Comments
 (0)