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.fromMegaBytes(100))) {
  throw ArgumentError('File too large');
}

// Check quota
if (!ByteValidation.isWithinQuota(currentUsage, quota: ByteConverter.fromGigaBytes(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 size is within the specified range.
assertMaxSize(ByteConverter size, {required ByteConverter maxSize, String? name}) → void
Asserts that size does not exceed maxSize.
assertMinSize(ByteConverter size, {required ByteConverter minSize, String? name}) → void
Asserts that size is at least minSize.
assertNonNegative(ByteConverter size, [String? name]) → void
Asserts that size is non-negative, throwing ArgumentError if not.
assertPositive(ByteConverter size, [String? name]) → void
Asserts that size is positive, throwing ArgumentError if not.
isApproachingQuota(ByteConverter currentUsage, {required ByteConverter quota, double warningThreshold = 0.8}) → bool
Checks if currentUsage exceeds warningThreshold of quota.
isInRange(ByteConverter size, {required ByteConverter min, required ByteConverter max}) → bool
Validates that size is within the specified range.
isNonNegative(ByteConverter size) → bool
Validates that size is non-negative (>= 0).
isPositive(ByteConverter size) → bool
Validates that size is positive (> 0).
isValidFileSize(ByteConverter size, {required ByteConverter maxSize, ByteConverter? minSize}) → bool
Validates that size is within the allowed maxSize.
isWithinQuota(ByteConverter currentUsage, {required ByteConverter quota}) → bool
Validates that currentUsage is within quota.
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.