-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: download browsers as TAR #34033
Changes from all commits
a9b40bd
0b139f1
98d6138
657e435
c5ab0c5
3b72c3b
411cf29
d880a22
f39ae50
f071337
45b84b7
a497b6b
b048d2a
affff4d
879afb1
16ff2df
eaf6a52
220e28b
0ccbef1
30c5ec6
e2b1500
25494cb
2224fd2
41a552f
dce95a5
2749367
7744cc5
c717419
a2d214f
5086a56
e24a0d7
746bb68
c8b2ce0
6fb5355
3c63756
5c04f77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,8 @@ This project incorporates components from the projects listed below. The origina | |
- [email protected] (https://github.com/JoshGlazebrook/socks) | ||
- [email protected] (https://github.com/alexei/sprintf.js) | ||
- [email protected] (https://github.com/tapjs/stack-utils) | ||
- tar-fs (https://github.com/mafintosh/tar-fs) | ||
- tar-stream (https://github.com/mafintosh/tar-stream) | ||
- [email protected] (https://github.com/npm/wrappy) | ||
- [email protected] (https://github.com/websockets/ws) | ||
- [email protected] (https://github.com/eemeli/yaml) | ||
|
@@ -1112,6 +1114,58 @@ THE SOFTWARE. | |
========================================= | ||
END OF [email protected] AND INFORMATION | ||
|
||
%% tar-fs NOTICES AND INFORMATION BEGIN HERE | ||
========================================= | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Mathias Buus | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
========================================= | ||
END OF tar-fs AND INFORMATION | ||
|
||
%% tar-stream NOTICES AND INFORMATION BEGIN HERE | ||
========================================= | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Mathias Buus | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
========================================= | ||
END OF tar-stream AND INFORMATION | ||
|
||
%% [email protected] NOTICES AND INFORMATION BEGIN HERE | ||
========================================= | ||
The ISC License | ||
|
@@ -1229,6 +1283,6 @@ END OF [email protected] AND INFORMATION | |
|
||
SUMMARY BEGIN HERE | ||
========================================= | ||
Total Packages: 48 | ||
Total Packages: 50 | ||
========================================= | ||
END OF SUMMARY |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,16 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import type { WriteStream } from 'fs'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { httpRequest } from '../../utils/network'; | ||
import { ManualPromise } from '../../utils/manualPromise'; | ||
import { extract } from '../../zipBundle'; | ||
import tar from '../../utils/third_party/tar'; | ||
import { pipeline } from 'stream/promises'; | ||
import { createBrotliDecompress } from 'zlib'; | ||
import type { Writable } from 'stream'; | ||
|
||
export type DownloadParams = { | ||
title: string; | ||
|
@@ -42,7 +47,7 @@ function browserDirectoryToMarkerFilePath(browserDirectory: string): string { | |
return path.join(browserDirectory, 'INSTALLATION_COMPLETE'); | ||
} | ||
|
||
function downloadFile(options: DownloadParams): Promise<void> { | ||
function downloadFile(options: DownloadParams, file: WriteStream | Writable): Promise<void> { | ||
let downloadedBytes = 0; | ||
let totalBytes = 0; | ||
|
||
|
@@ -72,7 +77,6 @@ function downloadFile(options: DownloadParams): Promise<void> { | |
} | ||
totalBytes = parseInt(response.headers['content-length'] || '0', 10); | ||
log(`-- total bytes: ${totalBytes}`); | ||
const file = fs.createWriteStream(options.zipPath); | ||
file.on('finish', () => { | ||
if (downloadedBytes !== totalBytes) { | ||
log(`-- download failed, size mismatch: ${downloadedBytes} != ${totalBytes}`); | ||
|
@@ -86,7 +90,10 @@ function downloadFile(options: DownloadParams): Promise<void> { | |
response.pipe(file); | ||
response.on('data', onData); | ||
response.on('error', (error: any) => { | ||
file.close(); | ||
if ('close' in file) | ||
file.close(); | ||
else | ||
file.destroy(error); | ||
if (error?.code === 'ECONNRESET') { | ||
log(`-- download failed, server closed connection`); | ||
promise.reject(new Error(`Download failed: server closed connection. URL: ${options.url}`)); | ||
|
@@ -105,10 +112,29 @@ function downloadFile(options: DownloadParams): Promise<void> { | |
} | ||
|
||
async function main(options: DownloadParams) { | ||
await downloadFile(options); | ||
log(`SUCCESS downloading ${options.title}`); | ||
log(`extracting archive`); | ||
await extract(options.zipPath, { dir: options.browserDirectory }); | ||
if (options.url.endsWith('.tar.br')) { | ||
const decompress = createBrotliDecompress(); | ||
const extraction = pipeline( | ||
decompress, | ||
tar.extract(options.browserDirectory), | ||
).catch(e => { | ||
if (e.code === 'ERR_STREAM_PREMATURE_CLOSE') // caused by an upstream error in `downloadFile()`, let's no throw twice | ||
return; | ||
|
||
throw e; | ||
}); | ||
await Promise.all([ | ||
extraction, | ||
downloadFile(options, decompress) | ||
]); | ||
log(`SUCCESS downloading and extracting ${options.title}`); | ||
} else { | ||
const file = fs.createWriteStream(options.zipPath); | ||
await downloadFile(options, file); | ||
log(`SUCCESS downloading ${options.title}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should we place it before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to do that in a separate PR, but that would be a behaviour change to before. What'd be the benefit? |
||
log(`extracting archive`); | ||
await extract(options.zipPath, { dir: options.browserDirectory }); | ||
} | ||
if (options.executablePath) { | ||
log(`fixing permissions at ${options.executablePath}`); | ||
await fs.promises.chmod(options.executablePath, 0o755); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Mathias Buus | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This folder contains the `index.js` file from the [tar-fs](https://github.com/mafintosh/tar-fs/commit/7ce355d649e47d0c79ec092bb926d325884916b0) and `extract.js` and `headers.js` files from [tar-stream](https://github.com/mafintosh/tar-stream/commit/126968fd3c4a39eba5f8318c255e04cedbbad176) with the modifications seen in `diff.patch`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the motivation for changing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1010
doesn't have.tar.br
, and1010
is identical to1011
in functionality