Skip to content

Provides a simple interface for conversion of Digital values such as Bytes, KiloBytes etc.

License

Notifications You must be signed in to change notification settings

ArunPrakashG/byte_converter

Repository files navigation

ByteConverter

Pub Version License: MIT

High-performance byte unit converter for Dart with automatic caching and fluent API inspired by ByteSize library from C#.

Features

  • 🚀 High-performance with cached calculations
  • 📦 Decimal (KB, MB, GB, TB, PB) and Binary (KiB, MiB, GiB, TiB, PiB) units
  • 🔢 Math operations (+, -, *, /)
  • 🔄 JSON serialization
  • 💫 Fluent API with extensions
  • 📐 Precise number formatting
  • 🧮 Storage units (sectors, blocks, pages)
  • 📈 Network transfer rates
  • ⏱️ Time-based calculations

Installation

dependencies:
  byte_converter: ^2.0.0

Quick Start

// Basic Usage
final size = 1.5.gigaBytes;
print(size); // 1.5 GB

// Math Operations
final total = 1.5.gigaBytes + 500.megaBytes;
print(total); // 2 GB

// Binary Units
final ram = 16.gibiBytes;
print(ram.toHumanReadable(SizeUnit.GB)); // 17.18 GB

// Network Rates
final speed = 100.megaBytes;
print(speed.megaBitsPerSecond); // 800 Mbps

// Storage Units
final disk = 4.kibiBytes;
print(disk.sectors); // 8 sectors

Advanced Usage

final data = ByteConverter.fromGigaBytes(1.5);

// Precision Control
print(data.toHumanReadable(SizeUnit.MB, precision: 3)); // 1536.000 MB

// Transfer Time
final downloadTime = data.downloadTimeAt(10.megaBitsPerSecond);
print(downloadTime); // Duration

// Storage Alignment
final aligned = data.roundToBlock();
print(aligned.isWholeBlock); // true

Performance

  • 🚀 Cached calculations for frequent operations
  • 🧠 Lazy initialization for better memory usage
  • 🔒 Immutable design for thread safety
  • ⚡ Optimized string formatting

License

This project is licensed under MIT License. Read about it here: MIT License

Features and bugs

Please file feature requests and bugs here issue tracker.

About

Provides a simple interface for conversion of Digital values such as Bytes, KiloBytes etc.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages