Method: Specinfra::Backend::PowerShell::ScriptHelper#encode_script

Defined in:
lib/specinfra/backend/powershell/script_helper.rb

#encode_script(script) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/specinfra/backend/powershell/script_helper.rb', line 36

def encode_script script
  script_text = script.chars.to_a.join("\x00").chomp
  script_text << "\x00" unless script_text[-1].eql? "\x00"
  if script_text.respond_to?(:encode)
    script_text = script_text.encode('ASCII-8BIT')
  end
  if Base64.respond_to?(:strict_encode64)
    Base64.strict_encode64(script_text)
  else
    [ script_text ].pack("m").strip
  end
end