Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gilnobrega/proper_filesize
a self-contained dart library that converts bytes to human readable file sizes and backwards. Also supports binary units.
https://github.com/gilnobrega/proper_filesize
Last synced: about 2 months ago
JSON representation
a self-contained dart library that converts bytes to human readable file sizes and backwards. Also supports binary units.
- Host: GitHub
- URL: https://github.com/gilnobrega/proper_filesize
- Owner: gilnobrega
- License: bsd-3-clause
- Created: 2021-07-26T05:58:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-26T07:10:52.000Z (over 3 years ago)
- Last Synced: 2023-08-20T22:57:38.115Z (over 1 year ago)
- Language: Dart
- Homepage:
- Size: 5.86 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# proper_filesize
a self-contained dart library that converts bytes to human readable file sizes and backwards.Supports binary and metric units. (KB, KiB, MB, MiB, GB, GiB, TB, TiB, PB, PiB, EB, EiB, etc.)
## Usage
Add ``proper_filesize`` as a dependency to your project's ``pubspec.yaml`` file.#### String to bytes
Converts human readable string and its units to an integer number of bytes
```dart
String metricFilesize = "1.2 EB";
int metricBytes = ProperFilesize.parseHumanReadableFilesize(metricFilesize).toInt();
print("$metricFilesize is $metricBytes bytes");
```This will print:
```
1.2 EB is 1200000000000000000 bytes
```Also works with binary units:
```dart
String binaryFilesize = "1.2 EiB";
int binaryBytes = ProperFilesize.parseHumanReadableFilesize(binaryFilesize).toInt();
print("$binaryFilesize is $binaryBytes bytes");
```This will print:
```
1.2 EiB is 1383505805528216320 bytes
```#### Bytes to String
Converts integer number of bytes to a human-readable filesize string
```dart
int bytes = 1.24356e9.toInt();
String binaryHumanReadableFilesize = ProperFilesize.generateHumanReadableFilesize(bytes, base: Bases.Binary, decimals: 3);
print("$bytes bytes is $binaryHumanReadableFilesize");
```This will print:
```
1243560000 bytes is 1.158 GiB
```