Skip to content

Commit

Permalink
fix(lib): corrupted manifests when including large files (#350)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
Elad Ben-Israel authored Oct 20, 2020
1 parent bed9eed commit 649f41b
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions packages/cdk8s/src/_loadurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 649f41b

Please sign in to comment.