getBlobStream method
downloads a blob as a stream, useful for large files like videos
if serverUrls
is null, the userServerList is fetched from nostr.
if the pukey has no UserServerList (kind: 10063), throws an error
Implementation
Future<Stream<BlobResponse>> getBlobStream({
required String sha256,
bool useAuth = false,
List<String>? serverUrls,
String? pubkeyToFetchUserServerList,
int chunkSize = 1024 * 1024, // 1MB chunks,
}) async {
Nip01Event? myAuthorization;
if (useAuth) {
_checkSigner();
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
myAuthorization = Nip01Event(
content: "get",
pubKey: _signer.getPublicKey(),
kind: kBlossom,
createdAt: now,
tags: [
["t", "get"],
["x", sha256],
["expiration", "${now + BLOSSOM_AUTH_EXPIRATION.inMilliseconds}"],
],
);
await _signer.sign(myAuthorization);
}
if (serverUrls == null) {
if (pubkeyToFetchUserServerList == null) {
throw "pubkeyToFetchUserServerList is null and serverUrls is null";
}
serverUrls ??= await _userServerList
.getUserServerList(pubkeys: [pubkeyToFetchUserServerList]);
}
if (serverUrls == null) {
throw Exception("User has no server list");
}
return _blossomImpl.getBlobStream(
sha256: sha256,
authorization: myAuthorization,
serverUrls: serverUrls,
chunkSize: chunkSize,
);
}