AnkiIO 1.0.2
Build, validate, import, and export Anki-compatible decks from .NET
Loading...
Searching...
No Matches
AnkiPackageLimits.cs
1namespace AnkiIO;
2
35public sealed record AnkiPackageLimits
36{
37 private int maximumEntries = 10_000;
38 private long maximumEntryBytes = 256L * 1024 * 1024;
39 private long maximumTotalBytes = 2L * 1024 * 1024 * 1024;
40 private double maximumCompressionRatio = 200;
41 private long maximumCollectionBytes = 512L * 1024 * 1024;
42
45 {
46 }
47
51 public static AnkiPackageLimits Default { get; } = new();
52
56 public int MaximumEntries
57 {
58 get => maximumEntries;
59 init => maximumEntries = RequirePositive(value, nameof(MaximumEntries));
60 }
61
66 {
67 get => maximumEntryBytes;
68 init => maximumEntryBytes = RequirePositive(value, nameof(MaximumEntryBytes));
69 }
70
76 {
77 get => maximumTotalBytes;
78 init => maximumTotalBytes = RequirePositive(value, nameof(MaximumTotalBytes));
79 }
80
89 {
90 get => maximumCompressionRatio;
91 init
92 {
93 if (!double.IsFinite(value) || value <= 0)
94 {
95 throw new ArgumentOutOfRangeException(nameof(MaximumCompressionRatio), value, "The maximum compression ratio must be finite and positive.");
96 }
97
98 maximumCompressionRatio = value;
99 }
100 }
101
107 {
108 get => maximumCollectionBytes;
109 init => maximumCollectionBytes = RequirePositive(value, nameof(MaximumCollectionBytes));
110 }
111
112 internal void Validate()
113 {
114 _ = RequirePositive(MaximumEntries, nameof(MaximumEntries));
115 _ = RequirePositive(MaximumEntryBytes, nameof(MaximumEntryBytes));
116 _ = RequirePositive(MaximumTotalBytes, nameof(MaximumTotalBytes));
117 _ = RequirePositive(MaximumCollectionBytes, nameof(MaximumCollectionBytes));
118 if (!double.IsFinite(MaximumCompressionRatio) || MaximumCompressionRatio <= 0)
119 {
120 throw new ArgumentOutOfRangeException(nameof(MaximumCompressionRatio), MaximumCompressionRatio, "The maximum compression ratio must be finite and positive.");
121 }
122 }
123
124 private static int RequirePositive(int value, string parameterName)
125 {
126 if (value <= 0)
127 {
128 throw new ArgumentOutOfRangeException(parameterName, value, "The limit must be positive.");
129 }
130
131 return value;
132 }
133
134 private static long RequirePositive(long value, string parameterName)
135 {
136 if (value <= 0)
137 {
138 throw new ArgumentOutOfRangeException(parameterName, value, "The limit must be positive.");
139 }
140
141 return value;
142 }
143}
double MaximumCompressionRatio
Gets the largest permitted uncompressed-to-compressed ratio for a non-empty ZIP entry.
int MaximumEntries
Gets the largest permitted number of ZIP entries.
AnkiPackageLimits()
Initializes the documented default archive limits.
long MaximumTotalBytes
Gets the largest permitted sum of all declared uncompressed ZIP entry lengths.
static AnkiPackageLimits Default
Gets the shared default limits.
long MaximumEntryBytes
Gets the largest permitted declared uncompressed length of one ZIP entry.
long MaximumCollectionBytes
Gets the largest permitted declared uncompressed length of collection.anki2.