format_bytes 2.1.0 copy "format_bytes: ^2.1.0" to clipboard
format_bytes: ^2.1.0 copied to clipboard

Format byte amounts in human readable form. Includes support for localization and custom formatting options.

example/main.dart

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);
  }).asBroadcastStream();

  var totalSize = statStream.fold<int>(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 : '.');
  processDirectory(root);
}
0
likes
130
pub points
46%
popularity

Publisher

unverified uploader

Format byte amounts in human readable form. Includes support for localization and custom formatting options.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

intl

More

Packages that depend on format_bytes