format_bytes 1.0.1

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

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

Use this package as a library

1. Depend on it

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


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Aug 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:format_bytes/format_bytes.dart.

Health suggestions

Format lib/src/format_bytes_base.dart.

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

Dependencies

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