From 2737d6b23f3a0fd2314236a85fbdee536df745a2 Mon Sep 17 00:00:00 2001 From: "Sam X. Chen" Date: Fri, 11 Oct 2019 11:56:44 -0400 Subject: Bug Fix:2093, need to clean up the temporary file --- models/export.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'models/export.js') diff --git a/models/export.js b/models/export.js index 3f4c8590..5d356487 100644 --- a/models/export.js +++ b/models/export.js @@ -140,9 +140,11 @@ export class Exporter { const getBase64Data = function(doc, callback) { let buffer = new Buffer(0); // callback has the form function (err, res) {} - const tmpWriteable = fs.createWriteStream( - path.join(os.tmpdir(), `tmpexport${process.pid}`), + const tmpFile = path.join( + os.tmpdir(), + `tmpexport${process.pid}${Math.radom()}`, ); + const tmpWriteable = fs.createWriteStream(tmpFile); const readStream = doc.createReadStream(); readStream.on('data', function(chunk) { buffer = Buffer.concat([buffer, chunk]); @@ -152,6 +154,9 @@ export class Exporter { }); readStream.on('end', function() { // done + fs.unlink(tmpFile, () => { + //ignored + }); callback(null, buffer.toString('base64')); }); readStream.pipe(tmpWriteable); -- cgit v1.2.3-1-g7c22