UNPKG

5.35 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @fileoverview Defines types for interacting with blob transfer tasks.
19 */
20import { FbsBlob } from './implementation/blob';
21import { FirebaseStorageError } from './implementation/error';
22import { InternalTaskState, TaskEvent } from './implementation/taskenums';
23import { Metadata } from './metadata';
24import { CompleteFn, ErrorFn, StorageObserver, Subscribe, Unsubscribe } from './implementation/observer';
25import { UploadTaskSnapshot } from './tasksnapshot';
26import { Reference } from './reference';
27/**
28 * Represents a blob being uploaded. Can be used to pause/resume/cancel the
29 * upload and manage callbacks for various events.
30 * @internal
31 */
32export declare class UploadTask {
33 private _ref;
34 /**
35 * The data to be uploaded.
36 */
37 _blob: FbsBlob;
38 /**
39 * Metadata related to the upload.
40 */
41 _metadata: Metadata | null;
42 private _mappings;
43 /**
44 * Number of bytes transferred so far.
45 */
46 _transferred: number;
47 private _needToFetchStatus;
48 private _needToFetchMetadata;
49 private _observers;
50 private _resumable;
51 /**
52 * Upload state.
53 */
54 _state: InternalTaskState;
55 private _error?;
56 private _uploadUrl?;
57 private _request?;
58 private _chunkMultiplier;
59 private _errorHandler;
60 private _metadataErrorHandler;
61 private _resolve?;
62 private _reject?;
63 private _promise;
64 /**
65 * @param ref - The firebaseStorage.Reference object this task came
66 * from, untyped to avoid cyclic dependencies.
67 * @param blob - The blob to upload.
68 */
69 constructor(ref: Reference, blob: FbsBlob, metadata?: Metadata | null);
70 private _makeProgressCallback;
71 private _shouldDoResumable;
72 private _start;
73 private _resolveToken;
74 private _createResumable;
75 private _fetchStatus;
76 private _continueUpload;
77 private _increaseMultiplier;
78 private _fetchMetadata;
79 private _oneShotUpload;
80 private _updateProgress;
81 private _transition;
82 private completeTransitions_;
83 /**
84 * A snapshot of the current task state.
85 */
86 get snapshot(): UploadTaskSnapshot;
87 /**
88 * Adds a callback for an event.
89 * @param type - The type of event to listen for.
90 * @param nextOrObserver -
91 * The `next` function, which gets called for each item in
92 * the event stream, or an observer object with some or all of these three
93 * properties (`next`, `error`, `complete`).
94 * @param error - A function that gets called with a `FirebaseStorageError`
95 * if the event stream ends due to an error.
96 * @param completed - A function that gets called if the
97 * event stream ends normally.
98 * @returns
99 * If only the event argument is passed, returns a function you can use to
100 * add callbacks (see the examples above). If more than just the event
101 * argument is passed, returns a function you can call to unregister the
102 * callbacks.
103 */
104 on(type: TaskEvent, nextOrObserver?: StorageObserver<UploadTaskSnapshot> | ((a: UploadTaskSnapshot) => unknown), error?: ErrorFn, completed?: CompleteFn): Unsubscribe | Subscribe<UploadTaskSnapshot>;
105 /**
106 * This object behaves like a Promise, and resolves with its snapshot data
107 * when the upload completes.
108 * @param onFulfilled - The fulfillment callback. Promise chaining works as normal.
109 * @param onRejected - The rejection callback.
110 */
111 then<U>(onFulfilled?: ((value: UploadTaskSnapshot) => U | Promise<U>) | null, onRejected?: ((error: FirebaseStorageError) => U | Promise<U>) | null): Promise<U>;
112 /**
113 * Equivalent to calling `then(null, onRejected)`.
114 */
115 catch<T>(onRejected: (p1: FirebaseStorageError) => T | Promise<T>): Promise<T>;
116 /**
117 * Adds the given observer.
118 */
119 private _addObserver;
120 /**
121 * Removes the given observer.
122 */
123 private _removeObserver;
124 private _notifyObservers;
125 private _finishPromise;
126 private _notifyObserver;
127 /**
128 * Resumes a paused task. Has no effect on a currently running or failed task.
129 * @returns True if the operation took effect, false if ignored.
130 */
131 resume(): boolean;
132 /**
133 * Pauses a currently running task. Has no effect on a paused or failed task.
134 * @returns True if the operation took effect, false if ignored.
135 */
136 pause(): boolean;
137 /**
138 * Cancels a currently running or paused task. Has no effect on a complete or
139 * failed task.
140 * @returns True if the operation took effect, false if ignored.
141 */
142 cancel(): boolean;
143}