laravel-aria2

Builder Methods

To start using builder methods, first create a pending transfer:

use Pullr\LaravelAria2\Facades\Aria2;
 
$transfer = Aria2::url('https://example.com/file.iso');

Aria2::magnet($uri) returns the same builder.


dir()

The dir method sets the destination directory. It is required before download().

$transfer->dir(storage_path('app/downloads/1'));

id()

The id method associates an application transfer identifier. Events include it, and cancellation uses it.

$transfer->id($pull->id);

The identifier may be an integer or a string.


gid()

The gid method resumes an existing aria2 download instead of starting a new one. Blank or null values are ignored.

$transfer->gid($previousGid);

If that GID is still active, waiting, paused, or complete, the package reuses it. Otherwise it calls addUri for a new download.


continue()

The continue method sets aria2's continue option so an incomplete file in the destination can resume.

$transfer->continue();
$transfer->continue(false);

connections()

The connections method sets max-connection-per-server. Values below 1 are raised to 1.

$transfer->connections(16);

option()

The option method sets a single aria2 option. Values are normalized to the strings aria2 expects (true / false for booleans).

$transfer->option('seed-time', '0');
$transfer->option('bt-max-peers', 60);

options()

The options method merges several aria2 options at once.

$transfer->options([
'seed-time' => '0',
'seed-ratio' => '0',
]);

onProgress()

The onProgress method registers a callback invoked whenever a field changes.

use Pullr\LaravelAria2\Transfer\TransferStatus;
 
$transfer->onProgress(function (TransferStatus $status) {
$status->gid();
$status->percent();
$status->speed();
$status->totalBytes();
$status->displayName();
});

previousProgress()

The previousProgress method seeds the last reported percent so later updates stay monotonic across process restarts.

$transfer->previousProgress($pull->progress);

previousSpeed()

The previousSpeed method seeds the last reported speed string.

$transfer->previousSpeed($pull->speed);

previousTotalBytes()

The previousTotalBytes method seeds the last known total size.

$transfer->previousTotalBytes($pull->total_bytes);

previousDisplayName()

The previousDisplayName method seeds the last known display name so it is not rediscovered.

$transfer->previousDisplayName($pull->display_name);

getOptions()

The getOptions method returns the aria2 options queued on the builder.

$options = $transfer->getOptions();

download()

The download method runs the transfer to completion and returns the last TransferStatus. You must call this method at the end of the builder chain.

$status = $transfer->dir($directory)->download();