How to convert Render Results to base64?

Hello, I would like to know how to convert the Render Result to a base64 string without writing the file to disk.

I’m trying with the code below, but I did not succeed. :no:

import base64
import bpy

chunk = bpy.data.images['Render Result'].pixels

chunkb64 = base64.b64encode(chunk)
f = open(arq.replace(".png", ".txt"), 'w')
f.write(str(chunkb64))
f.close()