[#13] Change GetObject result to stream
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
c988ff3c76
commit
f5d1899dd2
5 changed files with 75 additions and 34 deletions
|
@ -80,7 +80,7 @@ internal class ObjectServiceProvider : ContextAccessor
|
|||
|
||||
var obj = await GetObject(request, ctx);
|
||||
|
||||
return obj.ToModel();
|
||||
return obj;
|
||||
}
|
||||
|
||||
internal Task<ObjectId> PutObjectAsync(PutObjectParameters parameters, Context ctx)
|
||||
|
@ -311,27 +311,38 @@ internal class ObjectServiceProvider : ContextAccessor
|
|||
}
|
||||
|
||||
// TODO: add implementation with stream writer!
|
||||
private async Task<Object.Object> GetObject(GetRequest request, Context ctx)
|
||||
private async Task<ModelsV2.Object> GetObject(GetRequest request, Context ctx)
|
||||
{
|
||||
using var stream = GetObjectInit(request, ctx);
|
||||
var reader = GetObjectInit(request, ctx);
|
||||
|
||||
var obj = await stream.ReadHeader();
|
||||
var payload = new byte[obj.Header.PayloadLength];
|
||||
var offset = 0L;
|
||||
var chunk = await stream.ReadChunk();
|
||||
var obj = await reader.ReadHeader();
|
||||
|
||||
while (chunk is not null && (ulong)offset < obj.Header.PayloadLength)
|
||||
{
|
||||
var length = Math.Min((long)obj.Header.PayloadLength - offset, chunk.Length);
|
||||
var @object = obj.ToModel();
|
||||
|
||||
Array.Copy(chunk, 0, payload, offset, length);
|
||||
offset += chunk.Length;
|
||||
chunk = await stream.ReadChunk();
|
||||
}
|
||||
@object.ObjectReader = reader;
|
||||
|
||||
obj.Payload = ByteString.CopyFrom(payload);
|
||||
return @object;
|
||||
|
||||
// obj.
|
||||
|
||||
return obj;
|
||||
// return obj.ToModel();
|
||||
|
||||
// var payload = new byte[obj.Header.PayloadLength];
|
||||
// var offset = 0L;
|
||||
// var chunk = await stream.ReadChunk();
|
||||
|
||||
// while (chunk is not null && (ulong)offset < obj.Header.PayloadLength)
|
||||
// {
|
||||
// var length = Math.Min((long)obj.Header.PayloadLength - offset, chunk.Length);
|
||||
|
||||
// Array.Copy(chunk, 0, payload, offset, length);
|
||||
// offset += chunk.Length;
|
||||
// chunk = await stream.ReadChunk();
|
||||
// }
|
||||
|
||||
// obj.Payload = ByteString.CopyFrom(payload);
|
||||
|
||||
// return obj;
|
||||
}
|
||||
|
||||
private ObjectReader GetObjectInit(GetRequest initRequest, Context ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue