Skip to content

Commit ca48914

Browse files
Add getBytes
1 parent 2901ed0 commit ca48914

27 files changed

+525
-498
lines changed

common/api-review/storage.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export interface FullMetadata extends UploadMetadata {
6565
updated: string;
6666
}
6767

68+
// @public
69+
export function getBytes(ref: StorageReference): Promise<ArrayBuffer>;
70+
6871
// @internal (undocumented)
6972
export function _getChild(ref: StorageReference, childPath: string): _Reference;
7073

packages/storage/exp/api.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ import {
4747
getDownloadURL as getDownloadURLInternal,
4848
deleteObject as deleteObjectInternal,
4949
Reference,
50-
_getChild as _getChildInternal
50+
_getChild as _getChildInternal,
51+
getBytesInternal
5152
} from '../src/reference';
5253
import { STORAGE_TYPE } from './constants';
5354
import { EmulatorMockTokenOptions, getModularInstance } from '@firebase/util';
@@ -62,6 +63,23 @@ export { UploadTask as _UploadTask } from '../src/task';
6263
export type { Reference as _Reference } from '../src/reference';
6364
export { FbsBlob as _FbsBlob } from '../src/implementation/blob';
6465

66+
/**
67+
* Downloads the data at the object's location. Returns an error if the object
68+
* is not found.
69+
*
70+
* To use this functionality, you have to whitelist your app's origin in you
71+
* Cloud Storage bucket. See also
72+
* https://cloud.google.com/storage/docs/configuring-cors
73+
*
74+
* @public
75+
* @param ref - StorageReference where data should be download.
76+
* @returns A Promise containing the object's bytes
77+
*/
78+
export function getBytes(ref: StorageReference): Promise<ArrayBuffer> {
79+
ref = getModularInstance(ref);
80+
return getBytesInternal(ref as Reference);
81+
}
82+
6583
/**
6684
* Uploads data to this object's location.
6785
* The upload is not resumable.

packages/storage/exp/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
SDK_VERSION
2828
} from '@firebase/app-exp';
2929

30-
import { ConnectionPool } from '../src/implementation/connectionPool';
3130
import { FirebaseStorageImpl } from '../src/service';
3231
import {
3332
Component,
@@ -56,7 +55,6 @@ function factory(
5655
app,
5756
authProvider,
5857
appCheckProvider,
59-
new ConnectionPool(),
6058
url,
6159
SDK_VERSION
6260
);

packages/storage/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { _FirebaseNamespace } from '@firebase/app-types/private';
2020
import { StringFormat } from './src/implementation/string';
2121
import { TaskEvent, TaskState } from './src/implementation/taskenums';
2222

23-
import { ConnectionPool } from './src/implementation/connectionPool';
2423
import { ReferenceCompat } from './compat/reference';
2524
import { StorageServiceCompat } from './compat/service';
2625
import { FirebaseStorageImpl } from './src/service';
@@ -59,7 +58,6 @@ function factory(
5958
app,
6059
authProvider,
6160
appCheckProvider,
62-
new ConnectionPool(),
6361
url,
6462
firebase.SDK_VERSION
6563
)

packages/storage/src/implementation/connection.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
* limitations under the License.
1616
*/
1717

18-
/**
19-
* Network headers
20-
*/
21-
export interface Headers {
22-
[name: string]: string;
23-
}
18+
/** Network headers */
19+
export type Headers = Record<string, string>;
2420

2521
/**
2622
* A lightweight wrapper around XMLHttpRequest with a
2723
* goog.net.XhrIo-like interface.
24+
*
25+
* ResponseType is generally either `string` or `ArrayBuffer`. You can create
26+
* a new connection by invoking `newTextConnection()` or
27+
* `newBytesConnection()`.
2828
*/
29-
export interface Connection {
29+
export interface Connection<ResponseType> {
3030
send(
3131
url: string,
3232
method: string,
@@ -38,6 +38,8 @@ export interface Connection {
3838

3939
getStatus(): number;
4040

41+
getResponse(): ResponseType;
42+
4143
getResponseText(): string;
4244

4345
/**

packages/storage/src/implementation/connectionPool.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)