fromContent static method
Creates a CID from raw content.
Specify codec, hashType, and version if they differ from defaults.
Implementation
static Future<CID> fromContent(
Uint8List content, {
String codec = 'raw',
String hashType = 'sha2-256',
int version = 1,
}) async {
Digest digest;
if (hashType == 'sha2-256') {
digest = sha256.convert(content);
} else {
throw UnsupportedError('Hash type $hashType not supported');
}
final mhInfo = Multihash.encode(hashType, Uint8List.fromList(digest.bytes));
if (version == 0) {
return CID.v0(Uint8List.fromList(digest.bytes));
} else {
return CID.v1(codec, mhInfo);
}
}