From 18754e74fa90e91ff6740d14d3ee397cde563f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gully?= Date: Tue, 12 Jun 2018 14:37:10 +0200 Subject: [PATCH] strange behavior: stream could be a string ! see https://github.com/apocas/dockerode/issues/456 --- ezmaster-api/routes/v1-instances.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ezmaster-api/routes/v1-instances.js b/ezmaster-api/routes/v1-instances.js index c8365e99..cacde2bc 100644 --- a/ezmaster-api/routes/v1-instances.js +++ b/ezmaster-api/routes/v1-instances.js @@ -687,12 +687,19 @@ router if (err) { return res.status(err.statusCode).send(err.reason).end(); } - stream.on('data', (chunk) => { - res.write(stripAnsi(chunk.toString())); - }); - stream.on('end', () => { + // strange behavior: stream could be a string ! + // see https://github.com/apocas/dockerode/issues/456 + if (typeof(stream) === 'string') { + res.write(stripAnsi(stream)); res.end(); - }); + } else { + stream.on('data', (chunk) => { + res.write(stripAnsi(chunk.toString())); + }); + stream.on('end', () => { + res.end(); + }); + } }); }); });