Skip to contents

Reads a plan, preview, approval or ledger file and rebuilds the corresponding object. A preview is rebuilt through zotPreview(), so its digest is recalculated from the rows on disk and compared with the stored one: a file edited after it was written is refused.

Usage

zotReadBatch(path, digest = NULL)

Arguments

path

A file written by zotWriteBatch() or zotExecute().

digest

Optional expected SHA-256 digest; a mismatch is refused.

Value

A plan data.table, a zotPreview, a zotApproval or a zotLedger.

Details

A ledger has no kind; it is recognized by its digest and items and returned as the zotLedger list that zotExecute() produces. A plan has no stored digest; when digest is supplied for a plan it is compared with the digest the plan would have under zotPreview().

Examples

Plan <- data.table::data.table(
  action = "patch", library = "user", itemKey = "ABCD1234",
  payload = list(list(title = "A reviewed title"))
)
Preview <- zotPreview(Plan, describe = "Correct one title")
Path <- tempfile(fileext = ".json")
zotWriteBatch(Preview, Path)
identical(zotReadBatch(Path)$digest, Preview$digest)
#> [1] TRUE
unlink(Path)