Unable to create file from file content API

Hi,

Actually, I am trying to retrieve image’s content from file API. But when I try to write to a file, my newly created file gets corrupt.

Here is the code for node:

const file = await openai.files.retrieveContent(req.params.id);
fs.writeFileSync("output.png", file);

Here is the code for python:

content = client.files.retrieve_content(id)
file_path = 'output.png'
with open(file_path, 'wb') as file:
    file.write(content)

Can anyone assist me to make a image from content in correct way? Or Am I missing something here.

Thanks