C# implementation of FrostFS SDK
sdk
Find a file
Vitaliy Potyarkin abd9b5d0d0
All checks were successful
DCO / DCO (pull_request) Successful in 4m12s
lint-build / dotnet8.0 (pull_request) Successful in 5m41s
lint-build / dotnet8.0 (push) Successful in 1m52s
[#39] Add CODEOWNERS
Signed-off-by: Vitaliy Potyarkin <v.potyarkin@yadro.com>
2024-12-10 18:52:18 +03:00
.forgejo/workflows [#13] Execute .NET code analyzers in CI 2024-11-18 07:07:57 +00:00
src [#28] Client: Use external GRPC Channnel 2024-12-06 09:01:33 +03:00
.editorconfig [#28] Client: Apply code optimizations 2024-11-18 17:00:19 +03:00
.gitignore [#11] Add Network Snapshot 2024-06-26 12:29:33 +03:00
CODEOWNERS [#39] Add CODEOWNERS 2024-12-10 18:52:18 +03:00
FrostFS.SDK.sln [#26] All: Remove V2 from naming 2024-11-18 11:33:50 +03:00
LICENSE Initial commit 2024-04-24 09:46:03 +00:00
README.md [#23] Client: Refactoring to optimize memory usage 2024-09-12 11:56:26 +03:00

frostfs-sdk-csharp

C# implementation of FrostFS SDK.

Prerequisites

Get the key for your wallet

  1. Get the address
cat <path_to_your_wallet> | jq .accounts[0].address | tr -d '"'
  1. Get the key
neo-go wallet export -w <path_to_your_wallet> -d <address_from_p1>

Example usage

Container

using FrostFS.SDK;
using FrostFS.SDK.ClientV2;

using Microsoft.Extensions.Options;

var Key = "KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq";
var Host = "http://172.22.33.44:8080";

var options = Options.Create(new SingleOwnerClientSettings
{
    Key = Key,
    Host = Host
});

using var client = Client.GetSingleOwnerInstance(options);

await foreach (var cid in client.ListContainersAsync())
{
    await client.DeleteContainerAsync(new PrmContainerDelete(cid));
}

var placementPolicy = new FrostFsPlacementPolicy(true, new FrostFsReplica(1));

var createContainerParam = new PrmContainerCreate(
    new FrostFsContainerInfo(BasicAcl.PublicRW, new FrostFsPlacementPolicy(true, new FrostFsReplica(1))));

var containerId = await client.CreateContainerAsync(createContainerParam);

using var fileStream = File.OpenRead(@"C:\Users\Paul\Pictures\cat.jpeg");

var param = new PrmObjectPut
{
    Header = new FrostFsObjectHeader(
                containerId: containerId,
                type: FrostFsObjectType.Regular,
                [new FrostFsAttribute("fileName", "test")]),
    Payload = fileStream
};

FrostFsObjectId objectId = await client.PutObjectAsync(param);

var filter = new FilterByAttribute(FrostFsMatchType.Equals, "fileName", "test");

await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId) { Filters = [filter] }))
{
    var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objId));
}

var @object = await client.GetObjectAsync(new PrmObjectGet(containerId, objectId));

var downloadedBytes = new byte[@object.Header.PayloadLength];
MemoryStream ms = new(downloadedBytes);

ReadOnlyMemory<byte>? chunk = null;
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
{
    ms.Write(chunk.Value.Span);
}