human_file_size library
A robust, customisable package to get a human representation of the size of your files.
Classes
- BestFitUnitConversion
- The size is converted to the largest possible unit that most accurately describes its magnitude, subject to the NumeralSystem used. The conversion works identically for negative values.
- BinaryNumeralSystem
- The binary numeral system with the factor between sequential magnitudes being 1024 or 2^10. Commonly used in Linux systems.
- CustomQuantityDisplayMode
- The quantity passes through a custom converter to get its display format.
- DecimalNumeralSystem
- The decimal numeral system with the factor between sequential magnitudes being 1000 or 10^3. This is the common system used to represent sizes of data for regular users.
- IntlQuantityDisplayMode
-
The quantity is displayed using basic calls to
Decimal.toStringandDecimal.toStringAsFixed. - LongLowercaseUnitStyle
- The unit will be displayed in its long form with the prefix in lowercase.
- LongUppercaseUnitStyle
- The unit will be displayed in its long form with the prefix in lowercase.
- NumeralSystem
- Represents the numeral system of units.
- OutputFormatter
- Defines how to format the output.
- PrettyQuantityDisplayMode
- A QuantityDisplayMode that formats the quantity with a fixed number of decimal places dependant on the the unit.
- QuantityDisplayMode
- Defines how the final quantity should be displayed, where the quantity is the amount of a given unit.
- ShortLowercaseUnitStyle
- The unit will be displayed concisely with the prefix in lowercase.
- ShortUppercaseUnitStyle
- The unit will be displayed concisely with the prefix in uppercase.
- SimpleOutputFormatter
- The quantity and unit are formatted as '${quantity} ${unit}'.
- SimpleQuantityDisplayMode
-
The quantity is displayed using basic calls to
Decimal.toStringandDecimal.toStringAsFixed. - SpecificUnitConversion
- data.
- Unit
- Represents a unit used for describing the size of digital information.
- UnitConversion
- Defines which unit the file size should be converted into before displaying.
- UnitStyle
- Represents the display style of a unit.
- UnitSymbols
- Stores the symbols used to represent a given unit.
Enums
- UnitMagnitude
- Magnitude of units to return
Extensions
- NumHumanFileSize on num
- Adds a method humanFileSize to nums.
Constants
- defaultOutputFormatter → const SimpleOutputFormatter
- The default number format is SimpleOutputFormatter.
- defaultQuantityDisplayMode → const SimpleQuantityDisplayMode
- The default quantity display mode is SimpleQuantityDisplayMode.
- defaultUnitConversion → const BestFitUnitConversion
- The default unit conversion is BestFitUnitConversion with the DecimalNumeralSystem.
- defaultUnitStyle → const ShortUppercaseUnitStyle
- The default unit style is ShortUppercaseUnitStyle.
- fileSizeToString → const String Function(num quantity, {Unit? inputUnit, OutputFormatter outputFormatter = defaultOutputFormatter, QuantityDisplayMode quantityDisplayMode = defaultQuantityDisplayMode, UnitConversion unitConversion = defaultUnitConversion, UnitStyle unitStyle = defaultUnitStyle})
- Alias of humanFileSize.
Properties
- defaultDecimalPlacesResolver ↔ DecimalPlacesResolver
-
Default implementation of DecimalPlacesResolver.
Example:
512 bytes: 512 B
128.43 kilobytes: 128 KB
1.01442 megabytes: 1.0 MB
1.44112 megabytes: 1.4 MB
1.23446 gigabytes: 1.23 GB
2.34507 terabytes: 2.345 TB
getter/setter pair
- defaultNumberFormat → NumberFormat
-
The default number format is
NumberFormat.decimalPattern.final - defaultUnit → Unit
-
The default unit is Unit.byte.
final
Functions
-
humanFileSize(
num quantity, {Unit? inputUnit, UnitConversion unitConversion = defaultUnitConversion, QuantityDisplayMode quantityDisplayMode = defaultQuantityDisplayMode, UnitStyle unitStyle = defaultUnitStyle, OutputFormatter outputFormatter = defaultOutputFormatter}) → String -
Given a
quantity, formats the quantity as a human-readable string.
Typedefs
- BestFitConversion = BestFitUnitConversion
- Alias of BestFitUnitConversion.
- BinarylSystem = BinaryNumeralSystem
- Alias of BinaryNumeralSystem.
- DecimalPlacesResolver = int Function(Decimal quantity, Unit unit)
- A resolver for the number of decimal places to use for a given unit.
- DecimalSystem = DecimalNumeralSystem
- Alias of DecimalNumeralSystem.
- LongLowercaseStyle = LongLowercaseUnitStyle
- Alias of LongLowercaseUnitStyle.
- LongUppercaseStyle = LongUppercaseUnitStyle
- Alias of LongUppercaseUnitStyle.
- QuantityFormatter = String Function(Decimal quantity, {required Unit unit})
-
A function used to format a
quantitybased on itsunit. - ShortLowercaseStyle = ShortLowercaseUnitStyle
- Alias of ShortLowercaseUnitStyle.
- ShortUppercaseStyle = ShortUppercaseUnitStyle
- Alias of ShortUppercaseUnitStyle.
- SimpleDisplayMode = SimpleQuantityDisplayMode
- Alias of SimpleQuantityDisplayMode.