Saving a base 64 string to a file via createWriteStream

I have an image coming into my Node.js application via email (through cloud service provider Mandrill). The image comes in as a base64 encoded string, email.content in the example below. I'm currently writing the image to a buffer, and then a file like this:

//create buffer and write to file
var dataBuffer = new Buffer(email.content, 'base64');                        
var writeStream = fs.createWriteStream(tmpFileName);

writeStream.once('open', function(fd) {
    console.log('Our steam is open, lets write to it');
    writeStream.write(dataBuffer);
    writeStream.end();
}); //writeSteam.once('open')

writeStream.on('close', function() {
    fileStats = fs.statSync(tmpFileName);

This works fine and is all well and good, but am I essentially doubling the memory requirements for this section of code, since I have my image in memory (as the original string), and then create a buffer of that same string before writing the file? I'm going to be dealing with a lot of inbound images so doubling my memory requirements is a concern.

I tried several ways to write email.content directly to the stream, but it always produced an invalid file. I'm a rank amateur with modern coding, so you're welcome to tell me this concern is completely unfounded as long as you tell me why so some light will dawn on marble head.

Thanks!

Since you already have the entire file in memory, there's no point in creating a write stream. Just use fs.writeFile

fs.writeFile(tmpFileName, email.content, 'base64', callback)

@Jonathan's answer is a better way to shorten the code you already have, so definitely do that.

I will expand on your question about memory though. The fact is that Node will not write anything to a file without converting it to a Buffer first, so given when you have told us about email.content, there is nothing more you can do.

If you are really worried about this though, then you would need some way to process the value of email.content as it comes in from where ever you are getting it from, as a stream. Then as the data is being streamed into the server, you immediately write it to a file, thus not taking up any more RAM than needed.

If you elaborate more, I can try to fill in more info.