addStream method

Future<CID> addStream(
  1. Stream<List<int>> stream
)

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.

Implementation

Future<CID> addStream(Stream<List<int>> stream) async {
  final builder = UnixFSBuilder();
  CID? rootCid;

  await for (final block in builder.build(stream)) {
    await _blockStore.putBlock(block);
    rootCid = block.cid;
  }

  if (rootCid == null) {
    throw StateError('Stream was empty');
  }

  return rootCid;
}