This commit is contained in:
@@ -4,9 +4,9 @@ import fse from "fs-extra";
|
||||
import got, { type Progress, type Request } from "got";
|
||||
import path from "path";
|
||||
import ps from "promise-streams";
|
||||
import type { Stream, Writable } from "stream";
|
||||
import { type Stream, type Writable } from "stream";
|
||||
import { x as tarX } from "tar";
|
||||
import unzip from "unzip-stream";
|
||||
import unzipper from "unzipper";
|
||||
|
||||
export interface DownloadOptions {
|
||||
progress?: boolean;
|
||||
@@ -19,7 +19,7 @@ const DEFAULT_OPTIONS: DownloadOptions = { progress: true, strip: 1, executable:
|
||||
type Extractor = (stream: Request, dest: string, options: DownloadOptions) => Stream;
|
||||
|
||||
const ZIP_EXTRACTOR: Extractor = (stream: Request, dest: string, options: DownloadOptions): Stream => {
|
||||
return stream.pipe(unzip.Parse()).on("entry", (entry: any) => {
|
||||
return stream.pipe(unzipper.Parse()).on("entry", (entry: unzipper.Entry) => {
|
||||
const filePath = entry.path.split("/").slice(options.strip).join(path.sep);
|
||||
if (filePath.length > 0) {
|
||||
if (entry.type === "Directory") {
|
||||
@@ -94,7 +94,7 @@ const progressBar = new ProgressBar();
|
||||
export const download = async (url: string, dest: string, options?: DownloadOptions): Promise<void> => {
|
||||
options = { ...DEFAULT_OPTIONS, ...options };
|
||||
fse.ensureDirSync(dest);
|
||||
let stream: Request = got.stream(url);
|
||||
let stream: Request = got.stream(url, { decompress: false });
|
||||
if (options.progress) {
|
||||
stream = progressBar.handle(stream);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user