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

@ -320,14 +320,14 @@ sub trim {
}
sub powershell_encoded {
my ($value) = $_[0];
my ($value) = $_[0];
require Encode;
require MIME::Base64;
my $bytes = Encode::encode("utf16LE", $value);
my $script = MIME::Base64::encode_base64($bytes, "\n");
$script =~ s/\n//g;
return $script;
require Encode;
require MIME::Base64;
my $bytes = Encode::encode("utf16LE", $value);
my $script = MIME::Base64::encode_base64($bytes, "\n");
$script =~ s/\n//g;
return $script;
}
sub powershell_escape {
@ -389,6 +389,19 @@ sub change_seconds {
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;
__END__