format_bytes 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

Build Status

Format byte amounts in human readable form.

Usage #

A simple usage example:

import 'package:format_bytes/format_bytes.dart';

main() {
  print(format(1024)); // 1 KiB

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.1 #

  • Some minor improvements to make Dart Pub happier. No code changes to the actual library have been made.

1.0.0 #

  • Initial version, created by Huulivoide


import 'dart:io';

import 'package:format_bytes/format_bytes.dart';

class PathAndSize {
  final String path;
  final int size;

  PathAndSize(this.path, this.size);

void processDirectory(Directory dir) {
  var statStream = dir.list(recursive: true).where((entry) {
    return entry is File;
  }).asyncMap((entry) async {
    return PathAndSize(entry.path, (await entry.stat()).size);

  var totalSize = statStream.fold(0, (total, entry) {
    return total + entry.size;

  statStream.listen((entry) {
    print('${entry.path} ${format(entry.size)}');
  }).onDone(() async {
    print('Total size: ${format(await totalSize)}');

main(List<String> args) {
  Directory root = Directory(args.isNotEmpty ? args.first : '.');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  format_bytes: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:format_bytes/format_bytes.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Fix lib/src/units.dart. (-9.99 points)

Analysis of lib/src/units.dart reported 21 hints, including:

line 53 col 23: Avoid const keyword.

line 54 col 23: Avoid const keyword.

line 56 col 27: Avoid const keyword.

line 57 col 27: Avoid const keyword.

line 58 col 27: Avoid const keyword.

Fix lib/src/localizations.dart. (-3.45 points)

Analysis of lib/src/localizations.dart reported 7 hints, including:

line 11 col 25: Avoid const keyword.

line 12 col 9: Avoid const keyword.

line 12 col 53: Avoid const keyword.

line 31 col 9: Avoid const keyword.

line 31 col 53: Avoid const keyword.

Format lib/src/format_bytes_base.dart.

Run dartfmt to format lib/src/format_bytes_base.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (intl).

Package is getting outdated. (-36.71 points)

The package was last published 71 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
intl ^0.15.7 0.15.8 0.16.1
Transitive dependencies
path 1.7.0
Dev dependencies
test ^1.0.0