Powershell 用于将文件转换为 Base64 格式的代码:
param(
[Parameter(Position=0,mandatory=$true)]
[String] $FilePath,
[Parameter(Position=1,mandatory=$true)]
[String] $Base64OutPutFilePath
)
$FileContent= Get-Content -Path $FilePath -Encoding Byte
$FileContentBase64= [System.convert]::ToBase64String($FileContent)
$FileContentBase64 | Out-File $Base64OutPutFilePath
这应该更快:
param(
[Parameter(Position=0,mandatory=$true)]
[String] $FilePath,
[Parameter(Position=1,mandatory=$true)]
[String] $Base64OutPutFilePath
)
[byte[]]$FileContent = [System.IO.File]::ReadAllBytes( $FilePath )
$FileContentBase64 = [System.convert]::ToBase64String($FileContent)
[System.IO.File]::WriteAllText( $Base64OutPutFilePath, $FileContentBase64 )