ByteValidation class
Input validation utilities for byte values.
Provides helpers for validating file sizes, quota checks, and assertion helpers.
Example:
// Validate file size before upload
if (!ByteValidation.isValidFileSize(fileSize, maxSize: ByteConverter.fromMB(100))) {
throw ArgumentError('File too large');
}
// Check quota
if (!ByteValidation.isWithinQuota(currentUsage, quota: ByteConverter.fromGB(5))) {
print('Quota exceeded!');
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
assertInRange(
ByteConverter size, {required ByteConverter min, required ByteConverter max, String? name}) → void -
Asserts that
sizeis within the specified range. -
assertMaxSize(
ByteConverter size, {required ByteConverter maxSize, String? name}) → void -
Asserts that
sizedoes not exceedmaxSize. -
assertMinSize(
ByteConverter size, {required ByteConverter minSize, String? name}) → void -
Asserts that
sizeis at leastminSize. -
assertNonNegative(
ByteConverter size, [String? name]) → void -
Asserts that
sizeis non-negative, throwing ArgumentError if not. -
assertPositive(
ByteConverter size, [String? name]) → void -
Asserts that
sizeis positive, throwing ArgumentError if not. -
isApproachingQuota(
ByteConverter currentUsage, {required ByteConverter quota, double warningThreshold = 0.8}) → bool -
Checks if
currentUsageexceedswarningThresholdofquota. -
isInRange(
ByteConverter size, {required ByteConverter min, required ByteConverter max}) → bool -
Validates that
sizeis within the specified range. -
isNonNegative(
ByteConverter size) → bool -
Validates that
sizeis non-negative (>= 0). -
isPositive(
ByteConverter size) → bool -
Validates that
sizeis positive (> 0). -
isValidFileSize(
ByteConverter size, {required ByteConverter maxSize, ByteConverter? minSize}) → bool -
Validates that
sizeis within the allowedmaxSize. -
isWithinQuota(
ByteConverter currentUsage, {required ByteConverter quota}) → bool -
Validates that
currentUsageis withinquota. -
quotaUsedPercent(
ByteConverter currentUsage, {required ByteConverter quota}) → double - Returns the percentage of quota used.
-
validate(
ByteConverter size, {ByteConverter? maxSize, ByteConverter? minSize, bool requirePositive = false}) → ValidationResult - Validates the result and returns a ValidationResult.