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

Describes one registered Anki media payload and provides repeatable streaming access to it. More...

Public Member Functions

ValueTask< Stream > OpenReadAsync (CancellationToken cancellationToken=default)
 Opens a new readable stream positioned at the beginning of the registered payload.

Properties

string FileName [get]
 Gets the safe collection-relative filename referenced by note HTML or sound markup.
long Length [get]
 Gets the payload size observed during registration.
string Sha256 [get]
 Gets the registration-time SHA-256 digest.

Detailed Description

Describes one registered Anki media payload and provides repeatable streaming access to it.

A descriptor is immutable and does not itself own an open stream, so it does not require disposal. Each OpenReadAsync call creates an independent stream positioned at the beginning; the caller owns and must dispose that returned stream. Cancellation applies while opening, not to later reads from the returned stream.

A descriptor created by AnkiMediaCollection.AddBytes owns an eager defensive copy of the bytes and can be reopened after the caller changes or releases its input buffer. A descriptor created by AnkiMediaCollection.AddFileAsync retains the source path instead. The caller must keep that file readable and unchanged until all package writes are complete.

Length and Sha256 describe registration-time content. Opening a path-backed descriptor does not revalidate those values, but package writing hashes the emitted bytes and rejects a changed source rather than silently producing a package inconsistent with the descriptor.

Definition at line 22 of file AnkiMediaFile.cs.

Member Function Documentation

◆ OpenReadAsync()

ValueTask< Stream > AnkiIO.AnkiMediaFile.OpenReadAsync ( CancellationToken cancellationToken = default)
inline

Opens a new readable stream positioned at the beginning of the registered payload.

Parameters
cancellationTokenCancels the operation before the stream is opened.
Returns
A task-like operation whose result is a new readable stream owned by the caller.

The caller must dispose the returned stream. Multiple streams from the same descriptor have independent positions and may be consumed concurrently. For path-backed media, this accesses the retained source path at call time and therefore may fail if the caller moved, removed, or made the file unreadable after registration.

Exceptions
OperationCanceledExceptioncancellationToken is canceled before opening.
FileNotFoundExceptionThe path-backed source no longer exists.
DirectoryNotFoundExceptionA path-backed source directory no longer exists.
PathTooLongExceptionThe retained source path exceeds a platform path-length limit.
UnauthorizedAccessExceptionThe caller cannot read a path-backed source.
IOExceptionThe underlying source cannot be opened for reading.

Definition at line 60 of file AnkiMediaFile.cs.

Property Documentation

◆ FileName

string AnkiIO.AnkiMediaFile.FileName
get

Gets the safe collection-relative filename referenced by note HTML or sound markup.

A portable simple filename without a directory component or path separator.

Definition at line 36 of file AnkiMediaFile.cs.

◆ Length

long AnkiIO.AnkiMediaFile.Length
get

Gets the payload size observed during registration.

The byte length of the registered content, including zero for an empty payload.

Definition at line 40 of file AnkiMediaFile.cs.

◆ Sha256

string AnkiIO.AnkiMediaFile.Sha256
get

Gets the registration-time SHA-256 digest.

The 64-character lowercase hexadecimal digest of the registered content.

Definition at line 44 of file AnkiMediaFile.cs.


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