file download actor
This commit is contained in:
parent
0cdf3d7dbf
commit
0596fdec27
4 changed files with 179 additions and 0 deletions
37
README.md
37
README.md
|
|
@ -208,6 +208,43 @@ print((nb as NeighborsResult).neighbors['NORTH']); // u09tunu
|
|||
|
||||
---
|
||||
|
||||
## FileDownloadActor
|
||||
|
||||
Downloads a file from a URL and saves it to disk via an injected `FileActor`.
|
||||
|
||||
```dart
|
||||
final actor = FileDownloadActor(
|
||||
fileActor: FileActor(),
|
||||
);
|
||||
```
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
|---|---|---|---|
|
||||
| `fileActor` | `FileActor` | required | Actor used to write the downloaded bytes to disk |
|
||||
| `httpClient` | `http.Client?` | new client | Injectable HTTP client; provide a `MockClient` in tests |
|
||||
|
||||
Call `actor.close()` when done to release the HTTP client.
|
||||
|
||||
| Message | Result | Description |
|
||||
|---|---|---|
|
||||
| `DownloadFile(url, savePath)` | `FileDownloaded(savePath)` | GETs the URL and writes the response bytes to `savePath`. Throws if the response status is not 2xx. |
|
||||
|
||||
```dart
|
||||
final actor = FileDownloadActor(fileActor: FileActor());
|
||||
|
||||
final result = await actor.handle(
|
||||
const DownloadFile(
|
||||
url: 'https://example.com/image.jpg',
|
||||
savePath: '/tmp/image.jpg',
|
||||
),
|
||||
);
|
||||
print((result as FileDownloaded).savePath); // /tmp/image.jpg
|
||||
|
||||
await actor.close();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FileUploadActor
|
||||
|
||||
Uploads files to a Nostr-authenticated remote storage service. Handles
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue