Debian Codegraph @

lib/ansible/executor/powershell/psrp_fetch_file.ps1

raw
1 # (c) 2025 Ansible Project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
4 using namespace System.IO
5
6 [CmdletBinding()]
7 param(
8 [Parameter(Mandatory)]
9 [string]
10 $Path,
11
12 [Parameter(Mandatory)]
13 [int]
14 $BufferSize
15 )
16
17 if (Test-Path -LiteralPath $Path -PathType Leaf) {
18 "[FILE]"
19
20 $fs = [FileStream]::new(
21 $path,
22 [FileMode]::Open,
23 [FileAccess]::Read,
24 [FileShare]::Read)
25
26 try {
27 $buffer = [byte[]]::new($BufferSize)
28 while ($read = $fs.Read($buffer, 0, $buffer.Length)) {
29 [Convert]::ToBase64String($buffer, 0, $read)
30 }
31 }
32 finally {
33 $fs.Dispose()
34 }
35 }
36 elseif (Test-Path -LiteralPath $Path -PathType Container) {
37 "[DIR]"
38 }
39 else {
40 Write-Error -Message "$Path does not exist"
41 }