|
|
|
@ -22,26 +22,43 @@ $params = Parse-Args $args;
|
|
|
|
|
$src = '';
|
|
|
|
|
If ($params.src.GetType)
|
|
|
|
|
{
|
|
|
|
|
$src = $params.src;
|
|
|
|
|
$src = $params.src;
|
|
|
|
|
}
|
|
|
|
|
Else
|
|
|
|
|
{
|
|
|
|
|
If ($params.path.GetType)
|
|
|
|
|
{
|
|
|
|
|
$src = $params.path;
|
|
|
|
|
}
|
|
|
|
|
If ($params.path.GetType)
|
|
|
|
|
{
|
|
|
|
|
$src = $params.path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
If (-not $src)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$result = New-Object psobject @{};
|
|
|
|
|
Fail-Json $result "missing required argument: src";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bytes = [System.IO.File]::ReadAllBytes($src);
|
|
|
|
|
$content = [System.Convert]::ToBase64String($bytes);
|
|
|
|
|
If (Test-Path $src)
|
|
|
|
|
{
|
|
|
|
|
If ((Get-Item $src).Directory) # Only files have the .Directory attribute.
|
|
|
|
|
{
|
|
|
|
|
$bytes = [System.IO.File]::ReadAllBytes($src);
|
|
|
|
|
$content = [System.Convert]::ToBase64String($bytes);
|
|
|
|
|
|
|
|
|
|
$result = New-Object psobject @{
|
|
|
|
|
changed = $false
|
|
|
|
|
encoding = "base64"
|
|
|
|
|
};
|
|
|
|
|
Set-Attr $result "content" $content;
|
|
|
|
|
Exit-Json $result;
|
|
|
|
|
$result = New-Object psobject @{
|
|
|
|
|
changed = $false
|
|
|
|
|
encoding = "base64"
|
|
|
|
|
};
|
|
|
|
|
Set-Attr $result "content" $content;
|
|
|
|
|
Exit-Json $result;
|
|
|
|
|
}
|
|
|
|
|
Else
|
|
|
|
|
{
|
|
|
|
|
$result = New-Object psobject @{};
|
|
|
|
|
Fail-Json $result ("is a directory: " + $src);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Else
|
|
|
|
|
{
|
|
|
|
|
$result = New-Object psobject @{};
|
|
|
|
|
Fail-Json $result ("file not found: " + $src);
|
|
|
|
|
}
|
|
|
|
|