Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: judge file format by server's content-type header #125

Merged
merged 4 commits into from Feb 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/download.ts
Expand Up @@ -86,6 +86,9 @@ async function downloadVSCodeArchive(options: DownloadOptions) {

const download = await request.getStream(url);
const totalBytes = Number(download.headers['content-length']);
const contentType = download.headers['content-type'];
const isZip = contentType ? contentType === 'application/zip' : url.endsWith('.zip');
Comment on lines +89 to +90
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const contentType = download.headers['content-type'];
const isZip = contentType ? contentType === 'application/zip' : url.endsWith('.zip');
const isZip = download.headers['content-type'] === 'application/zip' ?? url.endsWith('.zip');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

download.headers['content-type'] === 'application/zip' is always true or false, so url.endsWith('.zip') will never be reached.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. Nevermind then 👍


options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar: 0, totalBytes });

let bytesSoFar = 0;
Expand All @@ -98,7 +101,7 @@ async function downloadVSCodeArchive(options: DownloadOptions) {
options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar: totalBytes, totalBytes });
});

return { stream: download, format: url.endsWith('.zip') ? 'zip' : 'tgz' } as const;
return { stream: download, format: isZip ? 'zip' : 'tgz' } as const;
}

/**
Expand Down