-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibhttp_downloader_adapter.php
More file actions
32 lines (26 loc) · 1 KB
/
Copy pathlibhttp_downloader_adapter.php
File metadata and controls
32 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
declare(strict_types=1);
use imperazim\assets\remote\AssetDownloader;
use imperazim\assets\remote\AssetDownloadResult;
use imperazim\http\HttpRequest;
use imperazim\http\download\FileDownloader;
/**
* Optional example adapter: keep HTTP transport in LibHttp while LibAssets owns
* checksum validation, cache paths and resource-pack inspection.
*/
final class LibHttpAssetDownloader implements AssetDownloader {
public function __construct(private readonly FileDownloader $downloader = new FileDownloader()) {}
public function download(string $url, string $targetPath, ?string $expectedSha256 = null): AssetDownloadResult {
$result = $this->downloader->download(
HttpRequest::get($url)->withTimeout(30.0),
$targetPath,
maxBytes: 128 * 1024 * 1024,
expectedSha256: $expectedSha256
);
return new AssetDownloadResult(
$result->getPath(),
$result->getBytes(),
$result->getSha256()
);
}
}