changes the size function in StoreStream to accommodate block alignement required by encryption

This commit is contained in:
Marcin Czenko 2025-07-04 19:29:56 +02:00
parent d039ab69b3
commit 9e2d3c25a6
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0

View File

@ -55,10 +55,20 @@ proc new*(
result.initStream()
method `size`*(self: StoreStream): int =
## The size of a StoreStream is the size of the original dataset, without
## padding or parity blocks.
## The size of a StoreStream is the size of the original dataset
## padded to the boundary of the block - this is because we have
## encrypted data, and when encrypting we always encrypt the whole block
let m = self.manifest
(if m.protected: m.originalDatasetSize else: m.datasetSize).int
let size = if m.protected: m.originalDatasetSize else: m.datasetSize
(
if size mod m.blockSize == 0.NBytes:
size
else:
# Pad to the next block boundary
size + (m.blockSize - (size mod m.blockSize))
).int # (size div m.blockSize.int + 1) * m.blockSize.int
# (if m.protected: m.originalDatasetSize else: m.datasetSize).int
proc `size=`*(self: StoreStream, size: int) {.error: "Setting the size is forbidden".} =
discard