[manifest] Extract logic for decoding a manifest given a cid

This commit is contained in:
Mark Spanbroek 2022-07-07 15:00:08 +02:00 committed by markspanbroek
parent e06211f827
commit d4025f4a5f
2 changed files with 7 additions and 10 deletions

View File

@ -173,3 +173,9 @@ func decode*(
##
decoder.decode(data)
func decode*(_: type Manifest, data: openArray[byte], cid: Cid): ?!Manifest =
without contentType =? cid.contentType() and
containerType =? ManifestContainers.?[$contentType]:
return failure "CID has invalid content type for manifest"
Manifest.decode(data, containerType)

View File

@ -69,16 +69,7 @@ proc retrieve*(
return failure(
newException(CodexError, "Couldn't retrieve block for Cid!"))
without mc =? blk.cid.contentType():
return failure(
newException(CodexError, "Couldn't identify Cid!"))
# if we got a manifest, stream the blocks
if $mc in ManifestContainers:
trace "Retrieving data set", cid, mc = $mc
without manifest =? Manifest.decode(blk.data, ManifestContainers[$mc]):
return failure("Unable to construct manifest!")
if manifest =? Manifest.decode(blk.data, blk.cid):
if manifest.protected:
proc erasureJob(): Future[void] {.async.} =