[#13] Change GetObject result to stream
All checks were successful
DCO / DCO (pull_request) Successful in 42s
All checks were successful
DCO / DCO (pull_request) Successful in 42s
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
|
@ -1,3 +1,4 @@
|
|||
using System.Security.Cryptography;
|
||||
using FrostFS.SDK.ClientV2;
|
||||
using FrostFS.SDK.ClientV2.Interfaces;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
|
@ -82,13 +83,17 @@ public class ClientTestLive
|
|||
|
||||
Assert.NotNull(container);
|
||||
|
||||
Random rnd = new();
|
||||
var bytes = new byte[6*1024*1024 + 100];
|
||||
rnd.NextBytes(bytes);
|
||||
|
||||
var param = new PutObjectParameters
|
||||
{
|
||||
Header = new ObjectHeader(
|
||||
containerId: containerId,
|
||||
type: ObjectType.Regular,
|
||||
new ObjectAttribute("fileName", "test")),
|
||||
Payload = new MemoryStream([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]),
|
||||
Payload = new MemoryStream(bytes),
|
||||
ClientCut = false
|
||||
};
|
||||
|
||||
|
@ -102,7 +107,7 @@ public class ClientTestLive
|
|||
hasObject = true;
|
||||
|
||||
var objHeader = await fsClient.GetObjectHeadAsync(containerId, objectId);
|
||||
Assert.Equal(10u, objHeader.PayloadLength);
|
||||
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||
Assert.Single(objHeader.Attributes);
|
||||
Assert.Equal("fileName", objHeader.Attributes.First().Key);
|
||||
Assert.Equal("test", objHeader.Attributes.First().Value);
|
||||
|
@ -112,7 +117,16 @@ public class ClientTestLive
|
|||
|
||||
var @object = await fsClient.GetObjectAsync(containerId, objectId!);
|
||||
|
||||
Assert.Equal([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], @object.Payload);
|
||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||
MemoryStream ms = new(downloadedBytes);
|
||||
|
||||
byte[]? chunk = null;
|
||||
while ((chunk = await @object.ObjectReader.ReadChunk()) != null)
|
||||
{
|
||||
ms.Write(chunk);
|
||||
}
|
||||
|
||||
Assert.Equal(MD5.HashData(bytes), MD5.HashData(downloadedBytes));
|
||||
|
||||
await Cleanup(fsClient);
|
||||
|
||||
|
@ -145,13 +159,17 @@ public class ClientTestLive
|
|||
|
||||
Assert.NotNull(container);
|
||||
|
||||
Random rnd = new();
|
||||
var bytes = new byte[6*1024*1024 + 100];
|
||||
rnd.NextBytes(bytes);
|
||||
|
||||
var param = new PutObjectParameters
|
||||
{
|
||||
Header = new ObjectHeader(
|
||||
containerId: containerId,
|
||||
type: ObjectType.Regular,
|
||||
new ObjectAttribute("fileName", "test")),
|
||||
Payload = new MemoryStream([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]),
|
||||
Payload = new MemoryStream(bytes),
|
||||
ClientCut = true
|
||||
};
|
||||
|
||||
|
@ -165,7 +183,7 @@ public class ClientTestLive
|
|||
hasObject = true;
|
||||
|
||||
var objHeader = await fsClient.GetObjectHeadAsync(containerId, objectId);
|
||||
Assert.Equal(10u, objHeader.PayloadLength);
|
||||
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||
Assert.Single(objHeader.Attributes);
|
||||
Assert.Equal("fileName", objHeader.Attributes.First().Key);
|
||||
Assert.Equal("test", objHeader.Attributes.First().Value);
|
||||
|
@ -175,7 +193,14 @@ public class ClientTestLive
|
|||
|
||||
var @object = await fsClient.GetObjectAsync(containerId, objectId!);
|
||||
|
||||
Assert.Equal([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], @object.Payload);
|
||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||
MemoryStream ms = new(downloadedBytes);
|
||||
|
||||
byte[]? chunk = null;
|
||||
while ((chunk = await @object.ObjectReader.ReadChunk()) != null)
|
||||
{
|
||||
ms.Write(chunk);
|
||||
}
|
||||
|
||||
await Cleanup(fsClient);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue