[manifest] Extract logic for decoding a manifest given a cid
This commit is contained in:
parent
e06211f827
commit
d4025f4a5f
|
@ -173,3 +173,9 @@ func decode*(
|
||||||
##
|
##
|
||||||
|
|
||||||
decoder.decode(data)
|
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)
|
||||||
|
|
|
@ -69,16 +69,7 @@ proc retrieve*(
|
||||||
return failure(
|
return failure(
|
||||||
newException(CodexError, "Couldn't retrieve block for Cid!"))
|
newException(CodexError, "Couldn't retrieve block for Cid!"))
|
||||||
|
|
||||||
without mc =? blk.cid.contentType():
|
if manifest =? Manifest.decode(blk.data, blk.cid):
|
||||||
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.protected:
|
if manifest.protected:
|
||||||
proc erasureJob(): Future[void] {.async.} =
|
proc erasureJob(): Future[void] {.async.} =
|
||||||
|
|
Loading…
Reference in New Issue