update method

void update(
  1. TransferProgress p
)

Renders p, throttled; safe to call on every chunk.

Implementation

void update(TransferProgress p) {
  if (!_enabled) return;
  final ms = _sw.elapsedMilliseconds;
  final complete = p.bytesDone >= p.bytesTotal;
  if (!complete && ms - _lastRenderMs < 100) return;
  _lastRenderMs = ms;

  final frac = p.bytesTotal == 0 ? 1.0 : p.bytesDone / p.bytesTotal;
  final pct = (frac * 100).clamp(0, 100).toStringAsFixed(0).padLeft(3);
  final filled = (frac * _width).round().clamp(0, _width);
  final bar = '#' * filled + '-' * (_width - filled);
  final secs = ms / 1000.0;
  final rate = secs > 0 ? (p.bytesDone / secs).round() : 0;
  final line =
      '[$bar] $pct%  ${_fmt(p.bytesDone)}/${_fmt(p.bytesTotal)}  '
      '${_fmt(rate)}/s  ${_short(p.currentPath)}';
  final pad = _lastLen > line.length ? ' ' * (_lastLen - line.length) : '';
  _out.write('\r$line$pad');
  _lastLen = line.length;
}