add convert misc function

This commit is contained in:
qgarnier 2017-06-26 15:52:03 +02:00
parent f672ade530
commit 03e874c75b
1 changed files with 20 additions and 7 deletions

View File

@ -389,6 +389,19 @@ sub change_seconds {
return $str; return $str;
} }
sub convert_bytes {
my (%options) = @_;
my %expo = (k => 1, m => 2, g => 3, t => 4);
my $value = $options{value};
my $base = defined($options{network}) ? 1000 : 1020;
if ($options{unit} =~ /([kmgt])b/i) {
$value = $value * ($base ** $expo{lc($1)});
}
return $value;
}
1; 1;
__END__ __END__