In Node.js, I want to use a Base64Stream from one module and use it as a file in another.
I am getting email attachments from mail-listener2 which return like this:
{
contentType: 'image/png',
contentDisposition: 'attachment',
transferEncoding: 'base64',
generatedFileName: 'attachment.png',
contentId: '4b07159b34f1287079d4bdf7e77bc295@mailparser',
stream: Base64Stream {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
writable: true,
checksum: Hash {
_options: undefined,
[Symbol(kHandle)]: Hash {},
[Symbol(kState)]: [Object]
},
length: 5245,
current: '',
[Symbol(kCapture)]: false
},
checksum: '8d8c71ac84d23f92e171922eb89e1271',
length: 5245
}
I want to attach those to an email using gmail-send which expects filepath.
Do I have to save the attachment to disk? If so, how?
Or can I somehow convert it "in memory"?
I tried
base64Data = attachment.stream;
require("fs").writeFile("out.png", base64Data, 'base64', function(err) {
console.log(err);
});
but got a 0-length file.