Commit Diff
Diff:
09cbeefa6773efae0c0e89e8149e057909f8fc00
6240f9b84ab152b622940a098379f74513e170a3
Commit:
6240f9b84ab152b622940a098379f74513e170a3
Tree:
ef3eb792241a5790fcb5f6d00a7761d6851e2442
Author:
Omar Polo <op@omarpolo.com>
Date:
Tue Sep 13 19:46:59 2022 UTC
Message:
"humanize" the attachment size
commit - 09cbeefa6773efae0c0e89e8149e057909f8fc00
commit + 6240f9b84ab152b622940a098379f74513e170a3
blob - ac942c38ee512078d6857518f35fb4f0cce0a641
blob + fb58b75049afccb735eaa8a43ed57846bb7f76d0
--- mexp
+++ mexp
@@ -46,6 +46,20 @@ my $tid;
die "mshow exited with $? ($n, $fname)" if $?;
}
+# like libutil' fmt_scaled
+sub humanize {
+ my $number = shift;
+ my @units = qw( G M K B);
+ my @scale = (1024*1024*1024, 1024*1024, 1024, 1);
+
+ for (my $i = 0; $i < @scale; $i++) {
+ if ($scale[$i] < $number) {
+ my $r = $number / $scale[$i];
+ return sprintf "%.0f%s", $r, $units[$i];
+ }
+ }
+}
+
my $tid;
while (<>) {
my ($level, $fname, $mid, $date, $from, $subj) = parse;
@@ -130,7 +144,8 @@ while (<>) {
$path =~ s,^.*/parts/,/parts/,;
my $url = san("$path.$ext");
- say $fh "<li><a href='$url'>$name ($size)</a></li>";
+ my $hs = humanize $size;
+ say $fh "<li><a href='$url'>$name ($hs)</a></li>";
}
say $fh "</ul>" if $part_seen;
Omar Polo