byte_converter 2.6.0
byte_converter: ^2.6.0 copied to clipboard
High-performance byte and data-rate conversions with BigInt precision, expression parsing, transfer planning, storage profiles, and localization-ready formatting.
Changelog #
2.6.0 - 2025-12-06 #
π Major Features #
New Utilities & Namespaces
-
Byte Division (
ByteDivisionNamespace): Split and distribute bytessplit(chunkSize)- Divide bytes into chunksdistribute(numParts)- Evenly distribute across partsmodulo(boundary)- Calculate remainderpaddingTo(boundary)- Calculate padding needed
-
Bit Operations (
BitOperationsNamespace): Low-level bit manipulation- CPU Cache line alignment (L1/L2/L3)
- Byte alignment helpers
- Binary operations and utilities
-
Network Overhead utilities for calculating protocol overhead
-
Byte Pluralization with locale-aware rules
-
Natural Time Delta for human-readable time differences
-
Ordinal Numbers for ranking and positioning
-
SI Number Formatting for scientific notation
-
Storage Alignment for filesystem operations
Advanced Features
- BandwidthAccumulator: Track and analyze bandwidth usage over time
- ByteAccessibility: Screen reader and accessibility support
- ByteComparison: Rich comparison utilities
- ByteValidation: Input validation helpers
- NegativeValue: Handle negative byte values
- RelativeTime: Format relative timestamps
Parsing Enhancements
- Forced humanization parsing: Parse ambiguous formats
- Expression parsing: Evaluate arithmetic expressions like "10MB + 5GB"
- Duration parsing: Convert time durations to data sizes
- Improved error messages and edge case handling
π§ͺ Testing #
- 200+ new test cases for namespaces and utilities
- Comprehensive coverage for BandwidthAccumulator
- Tests for all display options and output formats
- Edge case validation across all features
- Performance benchmarks for new features
π¨ Developer Experience #
- Better IDE autocomplete with namespace organization
- Improved error messages with actionable hints
- Consistent API patterns across all features
- Zero breaking changes - fully backward compatible
π¦ Package Structure #
byte_converter.dart- Core functionality (recommended)byte_converter_full.dart- All features including statisticsbyte_converter_intl.dart- With intl localizationbyte_converter_lite.dart- Minimal without dependencies
Migration Notes #
- All existing code continues to work without changes
- New namespace APIs provide better organization
- Consider migrating from deprecated methods to namespaces for future-proofing
- See v2.5.0 changelog for namespace migration guide
2.5.0 #
Added - Namespace-Based API #
- New
storagenamespace: Access storage alignment utilities viasize.storage.sectors,size.storage.blocks,size.storage.roundToBlock(), etc. - New
ratenamespace: Access network rate utilities viasize.rate.bitsPerSecond,size.rate.transferTime(dataRate), etc. - Enhanced
displaynamespace: New methodsauto(),compound(),inUnit(), andpattern()for formatting - New export file:
byte_converter_full.dartfor users who need all advanced features
Added - Pluralization Utilities #
- New
BytePluralizationclass: Smart pluralization for byte-related termsBytePluralization.format(1, 'byte')β"1 byte"BytePluralization.format(2, 'byte')β"2 bytes"BytePluralization.format(0, 'byte')β"0 bytes"
- Locale-aware pluralization: Support for English, French, Slavic, East Asian, and Arabic rules
BytePluralization.optionsForLocale('fr')for French rules (0 and 1 are singular)BytePluralization.ruleForLocale('ja')βPluralizationRule.eastAsian(no plural forms)
- Extension methods: Quick pluralization on
intanddouble1536.withUnit('byte', useCommas: true)β"1,536 bytes"1.5.withUnit('megabyte')β"1.5 megabytes"
Deprecated - Migration to Namespaces #
The following methods on ByteConverter are now deprecated in favor of namespace-based alternatives:
| Deprecated | Use Instead |
|---|---|
sectors, blocks, pages, words |
storage.sectors, storage.blocks, etc. |
isWholeSector, isWholeBlock, etc. |
storage.isWholeSector, etc. |
roundToSector(), roundToBlock(), etc. |
storage.roundToSector(), etc. |
roundToProfile(), alignmentSlack(), isAligned() |
storage.roundToProfile(), etc. |
bitsPerSecond, kiloBitsPerSecond, etc. |
rate.bitsPerSecond, etc. |
transferTimeAt(), downloadTimeAt() |
rate.transferTime(), rate.transferTimeAt() |
toHumanReadable(unit) |
display.inUnit(unit) |
toHumanReadableAuto() |
display.auto() |
toHumanReadableAutoWith(options) |
display.format(options) |
toHumanReadableCompound() |
display.compound() |
formatWith(pattern) |
display.pattern(pattern) |
toFullWords() |
display.fullWords() |
largestWholeNumber() |
output.largestWholeNumber() |
Migration Example #
// Before (deprecated)
final size = ByteConverter.fromGigaBytes(1.5);
print(size.toHumanReadableAuto(standard: ByteStandard.iec));
print(size.sectors);
print(size.roundToBlock());
// After (recommended)
final size = ByteConverter.fromGigaBytes(1.5);
print(size.display.auto(standard: ByteStandard.iec));
print(size.storage.sectors);
print(size.storage.roundToBlock());
Notes #
- All deprecated methods will continue to work in v2.x releases
- Deprecated methods will be removed in v3.0.0
- The namespace-based API provides better organization and discoverability
- No breaking changes - existing code continues to work with deprecation warnings
2.4.2 #
Added / Improved #
- Package-wide public API documentation completed and enforced via
public_member_api_docs. - Clarified docs across
BigByteConverter,ByteConverter, compound formatting, parse results, storage profiles, and unified parsing types. - Resolved all analyzer warnings; repository is analyzer-clean.
Notes #
- No functional changes. This is a documentation-only release to improve API discoverability and consistency.
2.4.1 #
Added / Improved #
- Compound mixed-unit formatting (e.g.,
toHumanReadableCompound) now honorsCompoundFormatOptions.useGroupingandlocaleto render integers with locale-aware thousands separators (viaintl). This especially improves IEC outputs where counts can exceed 999 (for example,1,023 MiB). - Expanded Dartdoc for compound formatting options and behavior.
- README polish: added a friendly intro/personality, richer examples, and centered the title/badges for a more inviting presentation.
Notes #
- No breaking API changes. This is a visual formatting enhancement only. SI compound counts typically remain below 1000 per part; IEC benefits most from grouping.
2.4.0 #
Added / Improved #
- Fixed-width alignment for the numeric portion via
ByteFormatOptions.fixedWidth(also supported inDataRate.toHumanReadableAuto). includeSignInWidthoption to count the sign when padding withfixedWidthfor tighter column alignment.- Pattern formatting token
Sto explicitly render the sign ('+', '-', or space whensigned=true). - CLI:
bytecgains--fixed-width ninformatandratecommands; help updated.ratealso exposes--perfor choosing time base. - Docs: expanded formatting guide and data-rate examples to cover NBSP, truncation, SI k-case, fixed width, and pattern
S.
Notes #
- Default SI kilo symbol remains
KBfor backward compatibility; opt intokBusingsiKSymbolCase: lowerKor--si-lower-kin CLI.
2.3.1 #
Fixed #
- Size and data-rate parsing now fall back across SI, IEC, and JEDEC symbols so expression evaluation accepts mixed-unit inputs regardless of the selected standard.
2.3.0 #
Added / Improved #
- Transfer planning helpers (
TransferPlan,DataRate.transferableBytes,BigDataRate.transferableBytes) with ETAs, remaining payload metrics, and friendly strings. - Storage alignment profiles that round converters to device-specific blocks and surface slack diagnostics.
ByteStats/BigByteStatsaggregations for sums, averages, percentiles, and histogram buckets across mixed inputs.- Composite expression parsing for sizes and rates, including arithmetic operators, parentheses, and duration tokens.
FormatterSnapshotutilities for generating Markdown/CSV matrices reused in documentation and snapshot tests.BigDataRatefor BigInt-precise throughput conversions that interoperate withDataRate.- Built-in localized unit names now include Hindi (hi/hi_IN), Spanish (es), Portuguese (pt), Japanese (ja), Chinese (zh), Russian (ru), and English (en_IN) alongside the existing English, German, and French defaults.
- Locale-aware humanize formatting via new
ByteFormatOptions.localeanduseGroupingcontrols, powered byintl. - Shared humanize pipeline now caches
NumberFormatinstances and gracefully falls back to legacy formatting if locale data is missing. - Added regression tests covering localized output and grouping toggles for sizes and rates.
- New
byte_converter_intl.dartopt-in entry enables locale formatting without forcingintlon the default import. - Built-in localized unit-name maps (en, de, fr) plus
registerLocalizedUnitNames/clearLocalizedUnitNameshelpers for custom translations.
Notes #
- Requires the
intlpackage (already listed inpubspec.yaml). Consumers can ignorebyte_converter_intl.dartto avoid the extra dependency in their build output.
2.2.0 #
Added / Improved #
- Locale-aware parsing for sizes and rates: accepts nonβbreaking spaces, underscores, and mixed decimal/group separators (comma/dot) with robust normalization.
- Stricter DataRate parsing with additional IEC/SI synonyms (e.g., KiB/s, kibps) and clear errors for unknown units.
- Internal parsing regexes hardened; number formatting remains trimmed (no trailing zeros).
Notes #
- No breaking API changes. Existing parse and humanization behavior preserved.
2.1.0 #
Added - BigInt Support #
- BigByteConverter: New class for arbitrary precision byte calculations using BigInt
- Extended unit support: Added Exabytes (EB), Zettabytes (ZB), and Yottabytes (YB) for both decimal and binary units
- BigInt extensions: Extensions for BigInt type to create BigByteConverter instances
- Exact arithmetic methods:
*Exactgetters that return BigInt values without precision loss - Cross-type conversion: Convert between ByteConverter and BigByteConverter
- Large-scale JSON serialization: Support for serializing/deserializing extremely large numbers
Use Cases for BigInt Support #
- Data center storage calculations requiring exact precision
- Scientific computing with massive datasets
- Cryptographic applications where precision is critical
- Blockchain and distributed systems with large data requirements
- Future-proofing for exascale computing scenarios
API Examples #
// Ultra-precise calculations
final dataCenter = BigByteConverter.fromExaBytes(BigInt.from(5));
final cosmic = BigByteConverter.fromYottaBytes(BigInt.one);
// BigInt extensions
final huge = BigInt.parse('999999999999999999999').bytes;
// Exact arithmetic (no precision loss)
final exact = BigInt.from(1000000000).bytes;
print(exact.gigaBytesExact); // BigInt result
print(exact.gigaBytes); // double approximation
2.0.0 #
Breaking Changes #
- Made ByteConverter class immutable
- Changed static factory methods to named constructors
- Removed deprecated methods
- Updated precision handling for integer values
Added #
- Binary unit support (KiB, MiB, GiB, TiB, PiB)
- Extension methods for fluent API
- JSON serialization support
- Math operations (+, -, *, /)
- Comparison operators
- Cached calculations for better performance
Comparableinterface implementation
Optimized #
- String formatting and caching
- Unit conversion calculations
- Memory usage with lazy initialization
- Binary search for best unit selection
- Precision handling for whole numbers
Fixed #
- Incorrect KB unit display in string output
- Precision handling for integer values
- Memory leaks from repeated calculations
- Unit conversion accuracy