From 0deb16529010d128fbec81d8250c76738d3234a3 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Mon, 11 Apr 2022 15:45:23 +0200 Subject: [PATCH] feat(utilities): heapsnapshot use express helper for upload --- utilities/utils/dump.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/utilities/utils/dump.js b/utilities/utils/dump.js index c22cffc3d..3c6f2de73 100644 --- a/utilities/utils/dump.js +++ b/utilities/utils/dump.js @@ -15,20 +15,14 @@ async function createHeapSnapshot() { async function sendHeapSnapshot(req, res) { const fileName = await createHeapSnapshot(); - const file = fs.readFileSync(location + fileName, 'binary'); - const stat = fs.statSync(location + fileName); - - res.setHeader('Content-Length', stat.size); - res.setHeader('Content-Type', 'audio/mpeg'); - res.setHeader('Content-Disposition', 'attachment; filename=' + fileName); - res.write(file, 'binary'); - res.end(); - try { - fs.unlinkSync(location + fileName) - } catch (err) { - console.error("error while deleting heapsnapshot file"); - console.error(err); - } + res.download(location + fileName, function (err) { + try { + fs.unlinkSync(location + fileName) + } catch (err) { + console.error("error while deleting heapsnapshot file"); + console.error(err); + } + }); } process.on('USR2', () => {