forked from angular/angularfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.ts
More file actions
39 lines (37 loc) · 1.28 KB
/
task.ts
File metadata and controls
39 lines (37 loc) · 1.28 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
33
34
35
36
37
38
39
import { UploadTask, UploadTaskSnapshot } from './interfaces';
import { fromTask } from './observable/fromTask';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
export interface AngularFireUploadTask {
task: UploadTask;
snapshotChanges(): Observable<UploadTaskSnapshot | undefined>;
percentageChanges(): Observable<number | undefined>;
pause(): boolean;
cancel(): boolean;
resume(): boolean;
then(
onFulfilled?: ((a: UploadTaskSnapshot) => any) | null,
onRejected?: ((a: Error) => any) | null
): Promise<any>;
catch(onRejected: (a: Error) => any): Promise<any>;
}
/**
* Create an AngularFireUploadTask from a regular UploadTask from the Storage SDK.
* This method creates an observable of the upload and returns on object that provides
* multiple methods for controlling and monitoring the file upload.
*/
export function createUploadTask(task: UploadTask): AngularFireUploadTask {
const inner$ = fromTask(task);
return {
task,
then: task.then.bind(task),
catch: task.catch.bind(task),
pause: task.pause.bind(task),
cancel: task.cancel.bind(task),
resume: task.resume.bind(task),
snapshotChanges: () => inner$,
percentageChanges: () => inner$.pipe(
map(s => s.bytesTransferred / s.totalBytes * 100)
)
};
}