Debian Codegraph @

lib/ansible/executor/powershell/winrm_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 [Parameter(Mandatory)]
17 [long]
18 $Offset
19 )
20
21 if (Test-Path -LiteralPath $Path -PathType Leaf) {
22 $stream = [FileStream]::new(
23 $Path,
24 [FileMode]::Open,
25 [FileAccess]::Read,
26 [FileShare]::ReadWrite)
27
28 try {
29 $null = $stream.Seek($Offset, [SeekOrigin]::Begin)
30 $buffer = [byte[]]::new($BufferSize)
31 $read = $stream.Read($buffer, 0, $buffer.Length)
32 if ($read) {
33 [Convert]::ToBase64String($buffer, 0, $read)
34 }
35 }
36 finally {
37 $stream.Dispose()
38 }
39 }
40 elseif (Test-Path -LiteralPath $Path -PathType Container) {
41 "[DIR]"
42 }
43 else {
44 $host.UI.WriteErrorLine("$Path does not exist")
45 exit 1
46 }