1 | export type TransferTaskState = 'IN_PROGRESS' | 'PAUSED' | 'CANCELED' | 'SUCCESS' | 'ERROR';
|
2 | export type TransferProgressEvent = {
|
3 | transferredBytes: number;
|
4 | totalBytes?: number;
|
5 | };
|
6 | export type TransferTask<Result> = {
|
7 | /**
|
8 | * Cancel an ongoing transfer(upload/download) task. This will reject the `result` promise with an `AbortError` by
|
9 | * default. You can use `isCancelError` to check if the error is caused by cancellation.
|
10 | *
|
11 | * @param message - Optional error message to overwrite the default `canceled` message thrown when the task is
|
12 | * canceled. If provided, the `result` promise will be rejected with a {@link CanceledError} with supplied error
|
13 | * message instead.
|
14 | */
|
15 | cancel: (message?: string) => void;
|
16 | /**
|
17 | * Pause an ongoing transfer(upload/download) task. This method does not support the following scenarios:
|
18 | * * Downloading data or file from given key.
|
19 | */
|
20 | pause: () => void;
|
21 | /**
|
22 | * Resume a paused transfer(upload/download) task. This method does not support the following scenarios:
|
23 | * * Downloading data or file from given key.
|
24 | */
|
25 | resume: () => void;
|
26 | /**
|
27 | * Current state of the transfer task.
|
28 | */
|
29 | readonly state: TransferTaskState;
|
30 | /**
|
31 | * Promise that resolves when the transfer task is completed. The promise will be rejected if the task is canceled.
|
32 | */
|
33 | result: Promise<Result>;
|
34 | };
|
35 | export type DownloadTask<Result> = Omit<TransferTask<Result>, 'pause' | 'resume'>;
|
36 | export type UploadTask<Result> = TransferTask<Result>;
|