Merge pull request #49708 from rallytime/bp-49555

Back-port #49555 to 2018.3
This commit is contained in:
Nicole Thomas 2018-09-19 09:12:11 -04:00 committed by GitHub
commit b082f79fcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,9 +17,10 @@ import salt.utils.hashutils
import salt.utils.stringutils
if six.PY2:
import StringIO
from StringIO import StringIO
BytesIO = StringIO
elif six.PY3:
from io import StringIO
from io import BytesIO, StringIO
def digest(instr, checksum='md5'):
@ -155,13 +156,13 @@ def base64_encodefile(fname):
salt '*' hashutil.base64_encodefile /path/to/binary_file
'''
encoded_f = StringIO.StringIO()
encoded_f = BytesIO()
with salt.utils.files.fopen(fname, 'rb') as f:
base64.encode(f, encoded_f)
encoded_f.seek(0)
return encoded_f.read()
return salt.utils.stringutils.to_str(encoded_f.read())
def base64_decodestring(instr):
@ -192,7 +193,7 @@ def base64_decodefile(instr, outfile):
salt '*' hashutil.base64_decodefile instr='Z2V0IHNhbHRlZAo=' outfile='/path/to/binary_file'
'''
encoded_f = StringIO.StringIO(instr)
encoded_f = StringIO(instr)
with salt.utils.files.fopen(outfile, 'wb') as f:
base64.decode(encoded_f, f)