addStream method
Adds data from a stream and returns the root CID.
This is memory efficient for large files as it chunks and processes
the stream incrementally, building a UnixFS DAG identical to the one
IPFSNode.addFileStream produces on native platforms.
Implementation
Future<CID> addStream(
Stream<List<int>> stream, {
int cidVersion = 0,
bool rawLeaves = false,
}) async {
final builder = UnixFSBuilder(cidVersion: cidVersion, rawLeaves: rawLeaves);
// UnixFSBuilder.build unconditionally yields a root block (even for an
// empty stream), so the loop always assigns rootCid before it completes.
late CID rootCid;
await for (final block in builder.build(stream)) {
await _blockStore.putBlock(block);
rootCid = block.cid;
}
return rootCid;
}