AnkiIO 1.0.2
Build, validate, import, and export Anki-compatible decks from .NET
Loading...
Searching...
No Matches
AnkiIO.AnkiPackage Class Referencesealed

Contains the supported deck graphs, media, and diagnostics read from one Anki package. More...

Properties

IReadOnlyList< AnkiDeckDecks [get]
 Gets a fixed collection of the package's top-level deck hierarchies.
AnkiMediaCollection Media [get]
 Gets the media payloads eagerly extracted from the archive.
IReadOnlyList< AnkiDiagnosticDiagnostics [get]
 Gets the ordered compatibility and preservation findings produced while reading.
IEnumerable< AnkiNoteNotes [get]
 Enumerates all notes reachable from every top-level hierarchy.
IEnumerable< AnkiCardCards [get]
 Enumerates all cards reachable through Notes.

Detailed Description

Contains the supported deck graphs, media, and diagnostics read from one Anki package.

An AnkiPackage is an in-memory result, not an open archive. The reader closes or releases all temporary database resources before returning it, so the package does not implement IDisposable and remains usable after the source file or stream is closed.

Use the package writer overloads when modifying a package that was read from disk. They write every top-level deck and retain Media. Writing only package.Decks[0] intentionally writes one hierarchy and omits media held only by the package. The deck graphs and media collection remain mutable and are not safe for concurrent mutation.

Media extraction is eager: payloads are copied into memory while reading. Peak and retained memory can therefore grow with the allowed archive size. Apply appropriately small AnkiPackageLimits when inputs are untrusted.

Read, modify, and write a package without dropping its package-level media:

var package = await AnkiPackageReader.ReadAsync("input.apkg");
package.Decks[0].AddBasicNote("bonjour", "hello");
await AnkiPackageWriter.WriteAsync(package, "output.apkg");
Writes validated deck data as a legacy-compatible .apkg archive accepted by Anki 26....
static async Task WriteAsync(AnkiDeck deck, string path, CancellationToken cancellationToken=default)
Writes one deck hierarchy to a package file without opening or modifying an Anki profile.

Definition at line 28 of file AnkiPackage.cs.

Property Documentation

◆ Cards

IEnumerable<AnkiCard> AnkiIO.AnkiPackage.Cards
get

Enumerates all cards reachable through Notes.

A lazy enumeration that reflects later note and card mutations.

Do not mutate notes or card collections while this enumeration is in progress.

Definition at line 70 of file AnkiPackage.cs.

◆ Decks

IReadOnlyList<AnkiDeck> AnkiIO.AnkiPackage.Decks
get

Gets a fixed collection of the package's top-level deck hierarchies.

A read-only snapshot of root references in package order. The collection cannot be resized or replaced, but each referenced AnkiDeck remains mutable.

A package may contain more than one root. Traverse each root to reach nested decks. The writer overloads accepting this package preserve all roots; deck overloads write only the supplied root.

Definition at line 46 of file AnkiPackage.cs.

◆ Diagnostics

IReadOnlyList<AnkiDiagnostic> AnkiIO.AnkiPackage.Diagnostics
get

Gets the ordered compatibility and preservation findings produced while reading.

A read-only snapshot. Diagnostics describe non-fatal adapter choices and data that could not be preserved.

Branch on AnkiDiagnostic.Code or severity; human-readable messages may evolve.

Definition at line 60 of file AnkiPackage.cs.

◆ Media

AnkiMediaCollection AnkiIO.AnkiPackage.Media
get

Gets the media payloads eagerly extracted from the archive.

A mutable collection backed by caller-independent in-memory copies of the extracted payloads.

This collection is separate from every AnkiDeck.Media collection. Package writer overloads combine both locations, coalesce identical filenames and hashes, and reject conflicting same-name content. Removing an item here before writing intentionally omits it unless a deck registers the same filename.

Definition at line 55 of file AnkiPackage.cs.

◆ Notes

IEnumerable<AnkiNote> AnkiIO.AnkiPackage.Notes
get

Enumerates all notes reachable from every top-level hierarchy.

A lazy depth-first enumeration that reflects later mutations to the deck graphs.

Do not mutate a deck or its note collection while this enumeration is in progress.

Definition at line 65 of file AnkiPackage.cs.


The documentation for this class was generated from the following file: