decompress and extract
This commit is contained in:
parent
e8ce8ca2cd
commit
b177157220
|
|
@ -19,10 +19,12 @@ import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import childProcess from 'child_process';
|
import childProcess from 'child_process';
|
||||||
|
import zlib from 'zlib';
|
||||||
import { existsAsync } from '../../utils/fileUtils';
|
import { existsAsync } from '../../utils/fileUtils';
|
||||||
import { debugLogger } from '../../utils/debugLogger';
|
import { debugLogger } from '../../utils/debugLogger';
|
||||||
import { ManualPromise } from '../../utils/manualPromise';
|
import { ManualPromise } from '../../utils/manualPromise';
|
||||||
import { colors, multiProgress as MultiProgressBar } from '../../utilsBundle';
|
import { colors, multiProgress as MultiProgressBar } from '../../utilsBundle';
|
||||||
|
import { tarFs } from '../../zipBundle';
|
||||||
import { browserDirectoryToMarkerFilePath } from '.';
|
import { browserDirectoryToMarkerFilePath } from '.';
|
||||||
import { getUserAgent } from '../../utils/userAgent';
|
import { getUserAgent } from '../../utils/userAgent';
|
||||||
import type { DownloadParams } from './oopDownloadBrowserMain';
|
import type { DownloadParams } from './oopDownloadBrowserMain';
|
||||||
|
|
@ -149,21 +151,26 @@ async function downloadBrotli(title: string, browserDirectory: string, url: stri
|
||||||
}
|
}
|
||||||
totalBytes = parseInt(response.headers['content-length'] || '0', 10);
|
totalBytes = parseInt(response.headers['content-length'] || '0', 10);
|
||||||
debugLogger.log('install', `-- total bytes: ${totalBytes}`);
|
debugLogger.log('install', `-- total bytes: ${totalBytes}`);
|
||||||
const file = fs.createWriteStream(zipPath);
|
|
||||||
file.on('finish', () => {
|
const decompress = zlib.createBrotliDecompress();
|
||||||
if (downloadedBytes !== totalBytes) {
|
const extract = tarFs.extract(browserDirectory);
|
||||||
debugLogger.log('install', `-- download failed, size mismatch: ${downloadedBytes} != ${totalBytes}`);
|
|
||||||
promise.resolve({ error: new Error(`Download failed: size mismatch, file size: ${downloadedBytes}, expected size: ${totalBytes} URL: ${url}`) });
|
response
|
||||||
} else {
|
.pipe(decompress)
|
||||||
debugLogger.log('install', `-- download complete, size: ${downloadedBytes}`);
|
.pipe(extract)
|
||||||
promise.resolve({ error: null });
|
.on('finish', () => {
|
||||||
}
|
if (downloadedBytes !== totalBytes) {
|
||||||
});
|
debugLogger.log('install', `-- download failed, size mismatch: ${downloadedBytes} != ${totalBytes}`);
|
||||||
file.on('error', error => promise.resolve({ error }));
|
promise.resolve({ error: new Error(`Download failed: size mismatch, file size: ${downloadedBytes}, expected size: ${totalBytes} URL: ${url}`) });
|
||||||
response.pipe(file);
|
} else {
|
||||||
|
debugLogger.log('install', `-- download complete, size: ${downloadedBytes}`);
|
||||||
|
promise.resolve({ error: null });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on('error', error => promise.resolve({ error }));
|
||||||
|
|
||||||
response.on('data', onData);
|
response.on('data', onData);
|
||||||
response.on('error', (error: any) => {
|
response.on('error', (error: any) => {
|
||||||
file.close();
|
|
||||||
if (error?.code === 'ECONNRESET') {
|
if (error?.code === 'ECONNRESET') {
|
||||||
debugLogger.log('install', `-- download failed, server closed connection`);
|
debugLogger.log('install', `-- download failed, server closed connection`);
|
||||||
promise.resolve({ error: new Error(`Download failed: server closed connection. URL: ${url}`) });
|
promise.resolve({ error: new Error(`Download failed: server closed connection. URL: ${url}`) });
|
||||||
|
|
|
||||||
|
|
@ -19,3 +19,4 @@ export type { ZipFile } from '../bundles/zip/node_modules/@types/yazl';
|
||||||
export const yauzl: typeof import('../bundles/zip/node_modules/@types/yauzl') = require('./zipBundleImpl').yauzl;
|
export const yauzl: typeof import('../bundles/zip/node_modules/@types/yauzl') = require('./zipBundleImpl').yauzl;
|
||||||
export type { ZipFile as UnzipFile, Entry } from '../bundles/zip/node_modules/@types/yauzl';
|
export type { ZipFile as UnzipFile, Entry } from '../bundles/zip/node_modules/@types/yauzl';
|
||||||
export const extract: typeof import('../bundles/zip/node_modules/extract-zip') = require('./zipBundleImpl').extract;
|
export const extract: typeof import('../bundles/zip/node_modules/extract-zip') = require('./zipBundleImpl').extract;
|
||||||
|
export const tarFs: typeof import('../bundles/zip/node_modules/@types/tar-fs') = require('./zipBundleImpl').tarFs;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue