From 649f41ba65a9bb7f8c7d0c4a260ae9ddd773afb8 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 20 Oct 2020 12:00:46 +0300 Subject: [PATCH] fix(lib): corrupted manifests when including large files (#350) The code in `_loadurl.js` which reads manifests from files did not wait until the entire input was written to stdout before it exited. The fix is not to `exit(0)` but rather just let node exit gracefully. *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/cdk8s/src/_loadurl.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/cdk8s/src/_loadurl.js b/packages/cdk8s/src/_loadurl.js index b94b6e6146..995e4c0c40 100644 --- a/packages/cdk8s/src/_loadurl.js +++ b/packages/cdk8s/src/_loadurl.js @@ -22,24 +22,22 @@ if (!purl.protocol) { throw new Error(`unable to parse pathname from file url: ${url}`); } - process.stdout.write(fs.readFileSync(purl.pathname, 'utf-8')); - process.exit(0); + fs.createReadStream(purl.pathname).pipe(process.stdout); +} else { + const client = getHttpClient(); + const get = client.get(url, response => { + if (response.statusCode !== 200) { + throw new Error(`${response.statusCode} response from http get: ${response.statusMessage}`); + } + + response.on('data', chunk => process.stdout.write(chunk)); + }); + + get.once('error', err => { + throw new Error(`http error: ${err.message}`); + }); } -const client = getHttpClient(); - -const get = client.get(url, response => { - if (response.statusCode !== 200) { - throw new Error(`${response.statusCode} response from http get: ${response.statusMessage}`); - } - - response.on('data', chunk => process.stdout.write(chunk)); -}); - -get.once('error', err => { - throw new Error(`http error: ${err.message}`); -}); - function getHttpClient() { switch (purl.protocol) { case 'http:': return http;