Skip to content

CookBookArchive

Namespace Nfty.Core.Formats in assembly Nfty.Core.

public static class CookBookArchive

Reads and writes .cbk archives — a manifest plus one nested .rcp per recipe.

Methods

HashOf(string)

public static string HashOf(string path);

What a Set records for this archive: the SHA-256 of its bytes, lowercase hex.

Parameters

  • path (string) - Archive path.

Returns. The hash, lowercase hex.

Remarks

The same value LoadedCookBook.SourceSha256 carries and set.json stores as cookbookSha256 - without decoding the book. Answering "is this the book that Set was cooked from?" by reading it would pull every variant PNG in the collection into memory to compare one string, which is the argument ArchivePeek already makes about manifests.

HashOfAsync(string, CancellationToken)

public static Task<string> HashOfAsync(string path, CancellationToken ct = default);

The awaiting twin of CookBookArchive.HashOf().

Parameters

  • path (string) - Archive path.
  • ct (CancellationToken) - Cancels the hash.

Returns. The hash, lowercase hex.

Read(string, Parallelism?)

public static LoadedCookBook Read(string path, Parallelism? parallelism = null);

Reads a CookBook, eagerly decoding every variant image inside it.

Parameters

  • path (string) - Archive path.
  • parallelism (Parallelism?) - How wide decoding may run; null means Parallelism.Default.

Returns. The loaded book. The caller owns it and must dispose it — that frees every decoded image in the tree. Its manifest's PartialAlpha is recomputed from its loaded recipes rather than trusting the stored value.

Exceptions

ReadAsync(string, CancellationToken, Parallelism?)

public static Task<LoadedCookBook> ReadAsync(string path, CancellationToken ct = default, Parallelism? parallelism = null);

Reads a CookBook, eagerly decoding every variant image inside it.

Parameters

  • path (string) - Archive path.
  • ct (CancellationToken) - Cancels the read. Anything already decoded is disposed before the cancellation propagates.
  • parallelism (Parallelism?) - How wide decoding may run; null means Parallelism.Default.

Returns. The loaded book; the caller owns it. Its manifest's PartialAlpha is recomputed from its loaded recipes rather than trusting the stored value.

Exceptions

Write(string, CookBookManifest, IReadOnlyList<LoadedRecipe>, Parallelism?)

public static void Write(string path, CookBookManifest manifest, IReadOnlyList<LoadedRecipe> recipes, Parallelism? parallelism = null);

Writes a CookBook.

Parameters

  • path (string) - Destination path.
  • manifest (CookBookManifest) - The book's manifest. Its PartialAlpha is ignored — the written value is recomputed from recipes' images.
  • recipes (IReadOnlyList<LoadedRecipe>) - Recipes to nest inside it.
  • parallelism (Parallelism?) - How wide image encoding or decoding may run; null means Parallelism.Default. Never changes the bytes.

WriteAsync(string, CookBookManifest, IReadOnlyList<LoadedRecipe>, CancellationToken, Parallelism?)

public static Task WriteAsync(string path, CookBookManifest manifest, IReadOnlyList<LoadedRecipe> recipes, CancellationToken ct = default, Parallelism? parallelism = null);

Writes a CookBook.

Parameters

  • path (string) - Destination path.
  • manifest (CookBookManifest) - The book's manifest. Its PartialAlpha is ignored — the written value is recomputed from recipes' images.
  • recipes (IReadOnlyList<LoadedRecipe>) - Recipes to nest inside it.
  • ct (CancellationToken) - Cancels the write.
  • parallelism (Parallelism?) - How wide image encoding or decoding may run; null means Parallelism.Default. Never changes the bytes.

Returns. A task that completes when the archive is written.