getFiles method
Get WalrusFile instances for a list of blob IDs or quilt patch IDs.
Each ID can be either:
- A 32-byte blob ID (URL-safe base64) → returned as a plain file
- A 37-byte quilt patch ID → returned as the specific file within the quilt
Blob readers are shared for the same blob ID to avoid redundant network calls.
Mirrors the TS SDK's getFiles().
Implementation
Future<List<WalrusFile>> getFiles({required List<String> ids}) async {
final state = await _stateReader.systemState();
final numShards = state.nShards;
// Dedup blob readers.
final readersByBlobId = <String, BlobReader>{};
final quiltReadersByBlobId = <String, QuiltReader>{};
final parsedIds = ids.map(parseWalrusId).toList();
for (final id in parsedIds) {
final blobId = id.kind == 'blob' ? id.blobId! : id.patchId!.quiltId;
readersByBlobId.putIfAbsent(
blobId,
() => BlobReader(
blobId: blobId,
numShards: numShards,
readBlob: (id) => readBlob(blobId: id),
readSecondarySliver: (id, index) =>
getSecondarySliver(blobId: id, sliverIndex: index),
),
);
if (id.kind == 'quiltPatch') {
quiltReadersByBlobId.putIfAbsent(
blobId,
() => QuiltReader(blob: readersByBlobId[blobId]!),
);
}
}
return parsedIds.map((id) {
if (id.kind == 'blob') {
return WalrusFile(reader: readersByBlobId[id.blobId!]!);
}
final patchId = id.patchId!;
return WalrusFile(
reader: QuiltFileReader(
quilt: quiltReadersByBlobId[patchId.quiltId]!,
sliverIndex: patchId.startIndex,
),
);
}).toList();
}