Write bytes to a file natively in PowerShell

后端 未结 3 2024
失恋的感觉
失恋的感觉 2020-12-17 09:16

I have a script for testing an API which returns a base64 encoded image. My current solution is this.

$e = (curl.exe -H \"Content-Type: multipart/form-data\"         


        
3条回答
  •  醉梦人生
    2020-12-17 09:38

    Running C# assemblies is native to PowerShell, therefore you are already writing bytes to a file "natively".

    If you insist, you can use a construction like set-content test.jpg -value (([char[]]$decoded) -join ""), this has a drawback of adding #13#10 to the end of written data. With JPEGs it's bearable, but other files may get corrupt from this alteration. So please stick with byte-optimized routines of .NET instead of searching for "native" approaches - these are already native.

提交回复
热议问题