From 900b9dd3bdf566222854e8ec3dc28caf9d095144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Tue, 7 Apr 2020 13:27:38 +0200 Subject: [PATCH] GPII-4171: Wait for the pipe close event to consider the file downloaded --- src/artifacts.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/artifacts.js b/src/artifacts.js index 63ded88..c680d80 100644 --- a/src/artifacts.js +++ b/src/artifacts.js @@ -111,7 +111,7 @@ gpii.installer.artifact.download = function (downloadUrl, defaultOutputPath, out fluid.log("Downloading ", downloadUrl); - req.pipe(outStream); + var pipe = req.pipe(outStream); req.on("error", function (err) { var err = "Couldn't download artifact, error was: " + err; @@ -124,7 +124,11 @@ gpii.installer.artifact.download = function (downloadUrl, defaultOutputPath, out req.on("end", function () { outStream.close(); outStream = null; - event.fire(outputFile); + // This way we avoid the 'End-of-central-directory signature not found' + // error that sometimes we get. + pipe.on("close", function () { + event.fire(outputFile); + }); }); };