Skip to content

Getting a list of containers via stream

Getting a list of container IDs in a stream. This method allows you to retrieve the IDs of all containers by making consecutive requests to extract blocks.

Arguments:

  1. Execution context
  2. Method arguments, which includes:
  3. Additional headers (optional)

Result:

  • A stream for subtracting container IDs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
func ListContainersStream(p pool.Pool,  owner user.ID) pool.ResListStream {
    prmDelete := pool.PrmListStream{
        OwnerID: owner,
    }

    ctx := context.Background()

    stream, err := p.ListContainersStream(ctx, prmL)
    die(err)

    return stream
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
public static List<ContainerId> getContainersStream(FrostFSClient frostFSClient, CallContext callContext) {
    var reader = frostFSClient.listContainersStream(new PrmContainerGetAll(), callContext);

    List<ContainerId> result = new ArrayList<>();
    while (true) {
        var ids = reader.read();
        if (isNull(ids)) {
            break;
        }

        result.addAll(ids);
    }

    return result;
}

For C#, block retrieval is transparent to the user; the output is an asynchronous enumerator.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
async IEnumerable<FrostFsContainerId> ListContainersAsync(FrostFSClient client)
{
    var args = new PrmContainerGetAll();
    CallContext ctx = default;

    var streamReader = await client.ListContainersStreamAsync(args, ctx);

    await foreach (var cid in result)
    {
        yield return cid;
    }
}