Manifest: renamed operations to addProtection/removeProtection

This commit is contained in:
Bulat-Ziganshin 2022-08-27 18:41:38 +03:00
parent 105d02993b
commit 546ec70589
3 changed files with 9 additions and 11 deletions

View File

@ -82,7 +82,7 @@ proc encode*(
parity = parity
trace "Erasure coding manifest", blocks, parity
without var encoded =? Manifest.new(manifest, blocks, parity), error:
without var encoded =? manifest.addProtection(blocks, parity), error:
trace "Unable to create manifest", msg = error.msg
return error.failure
@ -253,7 +253,7 @@ proc decode*(
finally:
decoder.release()
without decoded =? encoded.unprotect(blocks = encoded.blocks[0..<encoded.originalLen]), error:
without decoded =? encoded.removeProtection(), error:
return failure error
return success decoded

View File

@ -204,11 +204,10 @@ proc new*(
originalBytes: blocks.len * blockSize,
protected: protected).success
proc new*(
T: type Manifest,
proc addProtection*(
manifest: Manifest,
K, M: int): ?!Manifest =
## Create an erasure protected dataset from an unprotected one
## Create an erasure protected dataset manifest from an unprotected one
##
? manifest.verify()
@ -238,11 +237,10 @@ proc new*(
? self.verify()
self.success
proc unprotect*(
manifest: Manifest,
blocks: openArray[Cid] = []
proc removeProtection*(
manifest: Manifest
): ?!Manifest =
## Create an unprotected dataset from an erasure protected one
## Create an unprotected dataset manifest from an erasure protected one
##
? manifest.verify()
@ -250,7 +248,7 @@ proc unprotect*(
return failure newException(CodexError, "Trying to unprotect already non-protected manifest")
var self = copyAllScalarFields(manifest, protected = false)
self.blocks = @blocks
self.blocks = manifest.blocks[0..<manifest.originalLen]
? self.verify()
self.success

View File

@ -63,7 +63,7 @@ suite "Manifest":
Block.new(("Block " & $it).toBytes).tryGet().cid
)
manifest = Manifest.new(blocks).tryGet()
protected = Manifest.new(manifest, 2, 2).tryGet()
protected = manifest.addProtection(2, 2).tryGet()
check:
protected.originalCid == manifest.cid.tryGet()