Skip to content

Commit

Permalink
chore: Add speed control to DownloaderDirect class
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilan-riviere committed Jun 13, 2024
1 parent f713044 commit 67c03b1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Utils/Downloader/DownloaderDirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DownloaderDirect extends Downloader
{
protected function __construct(
protected string $path,
protected ?int $speed = null,
) {
parent::__construct(basename($path));
}
Expand All @@ -35,6 +36,16 @@ public function autoMimeType(): self
return $this;
}

/**
* Change the speed of the download, lower is faster.
*/
public function speed(int $speed): self
{
$this->speed = $speed;

return $this;
}

/**
* Trigger the download.
*/
Expand All @@ -50,6 +61,9 @@ public function get(): void
echo fread($file, 1024 * 8);
ob_flush();
flush();
if ($this->speed) {
usleep($this->speed);
}
}

fclose($file);
Expand Down

0 comments on commit 67c03b1

Please sign in to comment.