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 );