Skip to content

Commit 2892d3b

Browse files
Merge ee67537 into 4d747b1
2 parents 4d747b1 + ee67537 commit 2892d3b

32 files changed

+812
-509
lines changed

common/api-review/storage.api.md

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

68+
// @public
69+
export function getBlob(ref: StorageReference): Promise<Blob>;
70+
71+
// @public
72+
export function getBytes(ref: StorageReference): Promise<ArrayBuffer>;
73+
6874
// @internal (undocumented)
6975
export function _getChild(ref: StorageReference, childPath: string): _Reference;
7076

packages/storage/exp/api.browser.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
import {
19+
StorageReference,
20+
} from './public-types';
21+
import {
22+
Reference,
23+
getBlobInternal
24+
} from '../src/reference';
25+
import { getModularInstance } from '@firebase/util';
26+
27+
/**
28+
* Downloads the data at the object's location. Returns an error if the object
29+
* is not found.
30+
*
31+
* To use this functionality, you have to whitelist your app's origin in your
32+
* Cloud Storage bucket. See also
33+
* https://cloud.google.com/storage/docs/configuring-cors
34+
*
35+
* @public
36+
* @param ref - StorageReference where data should be download.
37+
* @returns A Promise that resolves with a Blob containing the object's bytes
38+
*/
39+
export function getBlob(ref: StorageReference): Promise<Blob> {
40+
ref = getModularInstance(ref);
41+
return getBlobInternal(ref as Reference);
42+
}
43+

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 your
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.node.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Cloud Storage for Firebase
3+
*
4+
* @packageDocumentation
5+
*/
6+
7+
/**
8+
* @license
9+
* Copyright 2021 Google LLC
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
24+
// eslint-disable-next-line import/no-extraneous-dependencies
25+
import {
26+
_registerComponent,
27+
registerVersion,
28+
SDK_VERSION
29+
} from '@firebase/app-exp';
30+
31+
import { FirebaseStorageImpl } from '../src/service';
32+
import {
33+
Component,
34+
ComponentType,
35+
ComponentContainer,
36+
InstanceFactoryOptions
37+
} from '@firebase/component';
38+
39+
import { name, version } from '../package.json';
40+
41+
import { FirebaseStorage } from './public-types';
42+
import { STORAGE_TYPE } from './constants';
43+
44+
export { StringFormat } from '../src/implementation/string';
45+
export * from './api';
46+
47+
function factory(
48+
container: ComponentContainer,
49+
{ instanceIdentifier: url }: InstanceFactoryOptions
50+
): FirebaseStorage {
51+
const app = container.getProvider('app-exp').getImmediate();
52+
const authProvider = container.getProvider('auth-internal');
53+
const appCheckProvider = container.getProvider('app-check-internal');
54+
55+
return new FirebaseStorageImpl(
56+
app,
57+
authProvider,
58+
appCheckProvider,
59+
url,
60+
SDK_VERSION
61+
);
62+
}
63+
64+
function registerStorage(): void {
65+
_registerComponent(
66+
new Component(
67+
STORAGE_TYPE,
68+
factory,
69+
ComponentType.PUBLIC
70+
).setMultipleInstances(true)
71+
);
72+
73+
registerVersion(name, version);
74+
}
75+
76+
registerStorage();

packages/storage/exp/index.ts

Lines changed: 1 addition & 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,
@@ -43,6 +42,7 @@ import { STORAGE_TYPE } from './constants';
4342

4443
export { StringFormat } from '../src/implementation/string';
4544
export * from './api';
45+
export * from './api.browser';
4646

4747
function factory(
4848
container: ComponentContainer,
@@ -56,7 +56,6 @@ function factory(
5656
app,
5757
authProvider,
5858
appCheckProvider,
59-
new ConnectionPool(),
6059
url,
6160
SDK_VERSION
6261
);

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/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function getTestFiles(argv) {
4444
);
4545
integrationTestFiles = ['test/integration/*compat*'];
4646
} else {
47-
integrationTestFiles = ['test/integration/*'];
47+
integrationTestFiles = ['test/integration/*', 'test/browser/*'];
4848
}
4949
if (argv.unit) {
5050
return unitTestFiles;

packages/storage/rollup.config.exp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const es2017Plugins = [
7676
const es2017Builds = [
7777
// Node
7878
{
79-
input: './exp/index.ts',
79+
input: './exp/index.node.ts',
8080
output: {
8181
file: path.resolve('./exp', pkgExp.main),
8282
format: 'cjs',

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)