From 695505cf1aa3a3aa2b730314c9002fa521770c77 Mon Sep 17 00:00:00 2001 From: Lang Ming Date: Thu, 3 Feb 2022 18:52:43 +0800 Subject: [PATCH 1/4] fix: judge file format by server's content-type header --- lib/download.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/download.ts b/lib/download.ts index c088211c..b65ab2b0 100644 --- a/lib/download.ts +++ b/lib/download.ts @@ -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') + options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar: 0, totalBytes }); let bytesSoFar = 0; @@ -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; } /** From 9bc31eb3d47512813296bc9bd5743aae28372683 Mon Sep 17 00:00:00 2001 From: Lang Ming Date: Thu, 3 Feb 2022 19:04:46 +0800 Subject: [PATCH 2/4] typo --- lib/download.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/download.ts b/lib/download.ts index b65ab2b0..667c2a73 100644 --- a/lib/download.ts +++ b/lib/download.ts @@ -87,7 +87,7 @@ 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') + const isZip = contentType ? contentType === 'application/zip' : url.endsWith('.zip'); options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar: 0, totalBytes }); From 23fe097bffb59c22f08bc0562bd717a12bb5312a Mon Sep 17 00:00:00 2001 From: Zhonglei Qiu Date: Fri, 4 Feb 2022 18:08:57 +0800 Subject: [PATCH 3/4] Update lib/download.ts Co-authored-by: Connor Peet --- lib/download.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/download.ts b/lib/download.ts index 667c2a73..e7f3006e 100644 --- a/lib/download.ts +++ b/lib/download.ts @@ -86,8 +86,7 @@ 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'); + const isZip = download.headers['content-type'] === 'application/zip' ?? url.endsWith('.zip'); options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar: 0, totalBytes }); From a1f0f8751aeb6f7d5052226ab351f2f07674024a Mon Sep 17 00:00:00 2001 From: Lang Ming Date: Fri, 4 Feb 2022 18:33:56 +0800 Subject: [PATCH 4/4] switch back --- lib/download.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/download.ts b/lib/download.ts index e7f3006e..667c2a73 100644 --- a/lib/download.ts +++ b/lib/download.ts @@ -86,7 +86,8 @@ async function downloadVSCodeArchive(options: DownloadOptions) { const download = await request.getStream(url); const totalBytes = Number(download.headers['content-length']); - const isZip = download.headers['content-type'] === 'application/zip' ?? url.endsWith('.zip'); + const contentType = download.headers['content-type']; + const isZip = contentType ? contentType === 'application/zip' : url.endsWith('.zip'); options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar: 0, totalBytes });