enhance convert_bytes

This commit is contained in:
garnier-quentin 2020-06-04 13:36:31 +02:00
parent 3bc2da30c7
commit c1f4328b25
1 changed files with 8 additions and 2 deletions

View File

@ -430,9 +430,15 @@ sub convert_bytes {
my (%options) = @_;
my %expo = (k => 1, m => 2, g => 3, t => 4, p => 5);
my $value = $options{value};
my ($value, $unit) = ($options{value}, $options{unit});
if (defined($options{pattern})) {
return undef if ($value !~ /$options{pattern}/);
$value = $1;
$unit = $2;
}
my $base = defined($options{network}) ? 1000 : 1024;
if ($options{unit} =~ /([kmgt])b/i) {
if ($unit =~ /([kmgtp])i?b/i) {
$value = $value * ($base ** $expo{lc($1)});
}