From 2a9813bc2429c0870e8ff6c2047d3e8077301d24 Mon Sep 17 00:00:00 2001 From: Tom Cully Date: Fri, 1 May 2020 15:53:02 +1200 Subject: [PATCH] Remove tmp file after fromBufferWithMime --- lib/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 991e641..0054ed4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -97,8 +97,13 @@ function fromBufferWithMime( type, bufferContent, options, cb, withPath ) { bufferContent && bufferContent instanceof Buffer && ( typeof options === 'function' || typeof cb === 'function' ) ) { + if(typeof options === 'function') { cb = options; options = {} } _writeBufferToDisk( bufferContent, function( newPath ) { - fromFileWithMimeAndPath( type, newPath, options, cb ); + fromFileWithMimeAndPath( type, newPath, options, function( err, text ) { + // Remove temporary file regardless of error, ignore error on unlink + fs.unlink(newPath, function() {}) + if(cb) cb( err, text ) + }); }); } else { _returnArgsError( arguments );