Skip to content

getBytes #4973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions common/api-review/storage.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class _FirebaseStorageImpl implements FirebaseStorage {
constructor(
app: FirebaseApp, _authProvider: Provider<FirebaseAuthInternalName>,
_appCheckProvider: Provider<AppCheckInternalComponentName>,
_pool: ConnectionPool, _url?: string | undefined, _firebaseVersion?: string | undefined);
_url?: string | undefined, _firebaseVersion?: string | undefined);
readonly app: FirebaseApp;
// (undocumented)
readonly _appCheckProvider: Provider<AppCheckInternalComponentName>;
Expand All @@ -78,23 +78,20 @@ export class _FirebaseStorageImpl implements FirebaseStorage {
get host(): string;
set host(host: string);
// Warning: (ae-forgotten-export) The symbol "RequestInfo" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Connection" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Request" needs to be exported by the entry point index.d.ts
//
// (undocumented)
_makeRequest<T>(requestInfo: RequestInfo_2<T>, authToken: string | null, appCheckToken: string | null): Request_2<T>;
_makeRequest<I, O>(requestInfo: RequestInfo_2<I, O>, requestFactory: () => Connection<I>, authToken: string | null, appCheckToken: string | null): Request_2<O>;
// (undocumented)
makeRequestWithTokens<T>(requestInfo: RequestInfo_2<T>): Promise<Request_2<T>>;
makeRequestWithTokens<I, O>(requestInfo: RequestInfo_2<I, O>, requestFactory: () => Connection<I>): Promise<O>;
_makeStorageReference(loc: _Location): _Reference;
get maxOperationRetryTime(): number;
set maxOperationRetryTime(time: number);
get maxUploadRetryTime(): number;
set maxUploadRetryTime(time: number);
// (undocumented)
_overrideAuthToken?: string;
// Warning: (ae-forgotten-export) The symbol "ConnectionPool" needs to be exported by the entry point index.d.ts
//
// (undocumented)
readonly _pool: ConnectionPool;
// (undocumented)
_protocol: string;
// (undocumented)
Expand All @@ -115,6 +112,12 @@ export interface FullMetadata extends UploadMetadata {
updated: string;
}

// @public
export function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<Blob>;

// @public
export function getBytes(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<ArrayBuffer>;

// @internal (undocumented)
export function _getChild(ref: StorageReference, childPath: string): _Reference;

Expand Down Expand Up @@ -179,18 +182,26 @@ export function ref(storage: FirebaseStorage, url?: string): StorageReference;
// @public
export function ref(storageOrRef: FirebaseStorage | StorageReference, path?: string): StorageReference;

// @internal
// @public (undocumented)
export class _Reference {
// Warning: (ae-incompatible-release-tags) The symbol "__constructor" is marked as @public, but its signature references "FirebaseStorageImpl" which is marked as @internal
// Warning: (ae-incompatible-release-tags) The symbol "__constructor" is marked as @public, but its signature references "Location" which is marked as @internal
constructor(_service: _FirebaseStorageImpl, location: string | _Location);
get bucket(): string;
get fullPath(): string;
// Warning: (ae-incompatible-release-tags) The symbol "_location" is marked as @public, but its signature references "Location" which is marked as @internal
//
// (undocumented)
_location: _Location;
get name(): string;
// Warning: (ae-incompatible-release-tags) The symbol "_newRef" is marked as @public, but its signature references "FirebaseStorageImpl" which is marked as @internal
// Warning: (ae-incompatible-release-tags) The symbol "_newRef" is marked as @public, but its signature references "Location" which is marked as @internal
//
// (undocumented)
protected _newRef(service: _FirebaseStorageImpl, location: _Location): _Reference;
get parent(): _Reference | null;
get root(): _Reference;
// Warning: (ae-incompatible-release-tags) The symbol "storage" is marked as @public, but its signature references "FirebaseStorageImpl" which is marked as @internal
get storage(): _FirebaseStorageImpl;
_throwIfRoot(name: string): void;
// @override
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/.run/All Tests.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<env name="TS_NODE_CACHE" value="NO" />
</envs>
<ui>bdd</ui>
<extra-mocha-options>--require ts-node/register/type-check --require index.ts</extra-mocha-options>
<extra-mocha-options>--require ts-node/register/type-check --require src/index.node.ts</extra-mocha-options>
<test-kind>PATTERN</test-kind>
<test-pattern>test/{,!(browser)/**/}*.test.ts</test-pattern>
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function (config) {

function getTestFiles(argv) {
let unitTestFiles = ['test/unit/*'];
let integrationTestFiles = ['test/integration/*'];
let integrationTestFiles = ['test/integration/*', 'test/browser/*'];

if (argv.unit) {
return unitTestFiles;
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test:browser:unit": "karma start --single-run --unit",
"test:browser:integration": "karma start --single-run --integration",
"test:browser": "karma start --single-run",
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.ts --config ../../config/mocharc.node.js",
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
"test:debug": "karma start --browser=Chrome",
"prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
"api-report": "api-extractor run --local --verbose && ts-node-script ../../repo-scripts/prune-dts/prune-dts.ts --input dist/storage-public.d.ts --output dist/storage-public.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const es2017Plugins = [
const es2017Builds = [
// Node
{
input: './src/index.ts',
input: './src/index.node.ts',
output: {
file: pkg.main,
format: 'cjs',
Expand Down
44 changes: 44 additions & 0 deletions packages/storage/src/api.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { StorageReference } from './public-types';
import { Reference, getBlobInternal } from '../src/reference';
import { getModularInstance } from '@firebase/util';

/**
* Downloads the data at the object's location. Returns an error if the object
* is not found.
*
* To use this functionality, you have to whitelist your app's origin in your
* Cloud Storage bucket. See also
* https://cloud.google.com/storage/docs/configuring-cors
*
* This API is not available in Node.
*
* @public
* @param ref - StorageReference where data should be download.
* @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
* retrieve.
* @returns A Promise that resolves with a Blob containing the object's bytes
*/
export function getBlob(
ref: StorageReference,
maxDownloadSizeBytes?: number
): Promise<Blob> {
ref = getModularInstance(ref);
return getBlobInternal(ref as Reference, maxDownloadSizeBytes);
}
40 changes: 40 additions & 0 deletions packages/storage/src/api.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { StorageReference } from './public-types';
import { Reference, getStreamInternal } from '../src/reference';
import { getModularInstance } from '@firebase/util';

/**
* Downloads the data at the object's location. Raises an error event if the
* object is not found.
*
* This API is only available in Node.
*
* @public
* @param ref - StorageReference where data should be download.
* @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
* retrieve.
* @returns A stream with the object's data as bytes
*/
export function getStream(
ref: StorageReference,
maxDownloadSizeBytes?: number
): NodeJS.ReadableStream {
ref = getModularInstance(ref);
return getStreamInternal(ref as Reference, maxDownloadSizeBytes);
}
28 changes: 25 additions & 3 deletions packages/storage/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import {
getDownloadURL as getDownloadURLInternal,
deleteObject as deleteObjectInternal,
Reference,
_getChild as _getChildInternal
_getChild as _getChildInternal,
getBytesInternal
} from './reference';
import { STORAGE_TYPE } from './constants';
import { EmulatorMockTokenOptions, getModularInstance } from '@firebase/util';
Expand All @@ -74,6 +75,29 @@ export {
TaskEvent as _TaskEvent,
TaskState as _TaskState
} from './implementation/taskenums';
export { StringFormat };

/**
* Downloads the data at the object's location. Returns an error if the object
* is not found.
*
* To use this functionality, you have to whitelist your app's origin in your
* Cloud Storage bucket. See also
* https://cloud.google.com/storage/docs/configuring-cors
*
* @public
* @param ref - StorageReference where data should be download.
* @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
* retrieve.
* @returns A Promise containing the object's bytes
*/
export function getBytes(
ref: StorageReference,
maxDownloadSizeBytes?: number
): Promise<ArrayBuffer> {
ref = getModularInstance(ref);
return getBytesInternal(ref as Reference, maxDownloadSizeBytes);
}

/**
* Uploads data to this object's location.
Expand Down Expand Up @@ -290,8 +314,6 @@ export function _getChild(ref: StorageReference, childPath: string): Reference {
return _getChildInternal(ref as Reference, childPath);
}

export { StringFormat } from './implementation/string';

/**
* Gets a {@link FirebaseStorage} instance for the given Firebase app.
* @public
Expand Down
18 changes: 10 additions & 8 deletions packages/storage/src/implementation/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
* limitations under the License.
*/

/**
* Network headers
*/
export interface Headers {
[name: string]: string;
}
/** Network headers */
export type Headers = Record<string, string>;

/**
* A lightweight wrapper around XMLHttpRequest with a
* goog.net.XhrIo-like interface.
*
* ResponseType is generally either `string`, `ArrayBuffer` or `ReadableSteam`.
* You can create a new connection by invoking `newTextConnection()`,
* `newBytesConnection()` or `newStreamConnection()`.
*/
export interface Connection {
export interface Connection<ResponseType> {
send(
url: string,
method: string,
Expand All @@ -38,7 +38,9 @@ export interface Connection {

getStatus(): number;

getResponseText(): string;
getResponse(): ResponseType;

getErrorText(): string;

/**
* Abort the request.
Expand Down
31 changes: 0 additions & 31 deletions packages/storage/src/implementation/connectionPool.ts

This file was deleted.

10 changes: 2 additions & 8 deletions packages/storage/src/implementation/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ export function invalidRootOperation(name: string): StorageError {
* @param format - The format that was not valid.
* @param message - A message describing the format violation.
*/
export function invalidFormat(
format: string,
message: string
): StorageError {
export function invalidFormat(format: string, message: string): StorageError {
return new StorageError(
StorageErrorCode.INVALID_FORMAT,
"String does not match format '" + format + "': " + message
Expand All @@ -326,10 +323,7 @@ export function invalidFormat(
* @param message - A message describing the internal error.
*/
export function unsupportedEnvironment(message: string): StorageError {
throw new StorageError(
StorageErrorCode.UNSUPPORTED_ENVIRONMENT,
message
);
throw new StorageError(StorageErrorCode.UNSUPPORTED_ENVIRONMENT, message);
}

/**
Expand Down
Loading