从我从wind7迁移到win10的那一天起,PowerShell代码将文件转换为base64所需的时间从10到50s不等

问题描述 投票:0回答:1

用于将文件转换为Base64格式的Powershell代码:

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
windows powershell
1个回答
0
投票

这应该更快:

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 )
© www.soinside.com 2019 - 2024. All rights reserved.