Skip to content

Commit

Permalink
fix(downloader): bun support
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed Sep 10, 2023
1 parent fc1697f commit 36cf2f0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/download/stream-progress/fast-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {IStreamProgress} from "./istream-progress.js";


export default class FastDownload implements IStreamProgress {
private _downloader?: typeof TurboDownloader;
private _downloader?: TurboDownloader.default;
private _redirectedURL?: string;

constructor(private _url: string, private _savePath: string, private _options?: Partial<TurboDownloaderOptions>) {
}

public async init() {
await fs.ensureFile(this._savePath);
this._downloader = new (TurboDownloader.default as any)({
this._downloader = new FastDownload._TurboDownloaderClass({
url: await this._getRedirectedURL(),
destFile: this._savePath,
chunkSize: 50 * 1024 * 1024,
Expand All @@ -38,4 +38,9 @@ export default class FastDownload implements IStreamProgress {
throw new Error("Downloader is not initialized");
await (this._downloader as any).download(callback);
}

private static get _TurboDownloaderClass(): typeof TurboDownloader.default {
if (TurboDownloader && "default" in TurboDownloader) return TurboDownloader.default;
return TurboDownloader;
}
}

0 comments on commit 36cf2f0

Please sign in to comment.