@firebase/storage 0.8.7 → 0.9.0-canary.cb7299cbf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/index.browser.cjs.js +198 -25
  3. package/dist/index.browser.cjs.js.map +1 -1
  4. package/dist/index.esm2017.js +177 -26
  5. package/dist/index.esm2017.js.map +1 -1
  6. package/dist/index.esm5.js +196 -26
  7. package/dist/index.esm5.js.map +1 -1
  8. package/dist/index.node.cjs.js +245 -45
  9. package/dist/index.node.cjs.js.map +1 -1
  10. package/dist/node-esm/index.node.esm.js +189 -46
  11. package/dist/node-esm/index.node.esm.js.map +1 -1
  12. package/dist/node-esm/src/api.browser.d.ts +32 -1
  13. package/dist/node-esm/src/api.d.ts +15 -0
  14. package/dist/node-esm/src/api.node.d.ts +32 -1
  15. package/dist/node-esm/src/implementation/connection.d.ts +14 -4
  16. package/dist/node-esm/src/implementation/request.d.ts +5 -5
  17. package/dist/node-esm/src/implementation/requestinfo.d.ts +14 -6
  18. package/dist/node-esm/src/implementation/requests.d.ts +17 -16
  19. package/dist/node-esm/src/platform/browser/connection.d.ts +24 -7
  20. package/dist/node-esm/src/platform/connection.d.ts +6 -2
  21. package/dist/node-esm/src/platform/node/connection.d.ts +30 -14
  22. package/dist/node-esm/src/reference.d.ts +13 -0
  23. package/dist/node-esm/src/service.d.ts +3 -3
  24. package/dist/node-esm/test/integration/integration.test.d.ts +4 -0
  25. package/dist/node-esm/test/{unit → node}/connection.test.d.ts +0 -0
  26. package/dist/{test/unit/connection.test.d.ts → node-esm/test/node/stream.test.d.ts} +0 -0
  27. package/dist/node-esm/test/unit/connection.d.ts +4 -3
  28. package/dist/node-esm/test/unit/testshared.d.ts +2 -2
  29. package/dist/src/api.browser.d.ts +32 -1
  30. package/dist/src/api.d.ts +15 -0
  31. package/dist/src/api.node.d.ts +32 -1
  32. package/dist/src/implementation/connection.d.ts +14 -4
  33. package/dist/src/implementation/request.d.ts +5 -5
  34. package/dist/src/implementation/requestinfo.d.ts +14 -6
  35. package/dist/src/implementation/requests.d.ts +17 -16
  36. package/dist/src/platform/browser/connection.d.ts +24 -7
  37. package/dist/src/platform/connection.d.ts +6 -2
  38. package/dist/src/platform/node/connection.d.ts +30 -14
  39. package/dist/src/reference.d.ts +13 -0
  40. package/dist/src/service.d.ts +3 -3
  41. package/dist/storage-public.d.ts +46 -0
  42. package/dist/storage.d.ts +80 -11
  43. package/dist/test/integration/integration.test.d.ts +4 -0
  44. package/dist/test/node/connection.test.d.ts +17 -0
  45. package/dist/test/node/stream.test.d.ts +17 -0
  46. package/dist/test/unit/connection.d.ts +4 -3
  47. package/dist/test/unit/testshared.d.ts +2 -2
  48. package/package.json +6 -6
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var app = require('@firebase/app');
6
6
  var util = require('@firebase/util');
7
+ var stream = require('stream');
7
8
  var nodeFetch = require('node-fetch');
8
9
  var component = require('@firebase/component');
9
10
 
@@ -565,6 +566,14 @@ var ErrorCode;
565
566
  * See the License for the specific language governing permissions and
566
567
  * limitations under the License.
567
568
  */
569
+ /**
570
+ * Handles network logic for all Storage Requests, including error reporting and
571
+ * retries with backoff.
572
+ *
573
+ * @param I - the type of the backend's network response.
574
+ * @param - O the output type used by the rest of the SDK. The conversion
575
+ * happens in the specified `callback_`.
576
+ */
568
577
  class NetworkRequest {
569
578
  constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_) {
570
579
  this.url_ = url_;
@@ -641,7 +650,7 @@ class NetworkRequest {
641
650
  const connection = status.connection;
642
651
  if (status.wasSuccessCode) {
643
652
  try {
644
- const result = this.callback_(connection, connection.getResponseText());
653
+ const result = this.callback_(connection, connection.getResponse());
645
654
  if (isJustDef(result)) {
646
655
  resolve(result);
647
656
  }
@@ -656,7 +665,7 @@ class NetworkRequest {
656
665
  else {
657
666
  if (connection !== null) {
658
667
  const err = unknown();
659
- err.serverResponse = connection.getResponseText();
668
+ err.serverResponse = connection.getErrorText();
660
669
  if (this.errorCallback_) {
661
670
  reject(this.errorCallback_(connection, err));
662
671
  }
@@ -787,7 +796,7 @@ function getBlobBuilder() {
787
796
  * @param args The values that will make up the resulting blob.
788
797
  * @return The blob.
789
798
  */
790
- function getBlob(...args) {
799
+ function getBlob$1(...args) {
791
800
  const BlobBuilder = getBlobBuilder();
792
801
  if (BlobBuilder !== undefined) {
793
802
  const bb = new BlobBuilder();
@@ -1142,7 +1151,7 @@ class FbsBlob {
1142
1151
  return val;
1143
1152
  }
1144
1153
  });
1145
- return new FbsBlob(getBlob.apply(null, blobby));
1154
+ return new FbsBlob(getBlob$1.apply(null, blobby));
1146
1155
  }
1147
1156
  else {
1148
1157
  const uint8Arrays = args.map((val) => {
@@ -1464,6 +1473,12 @@ function fromResponseString(service, bucket, resourceString) {
1464
1473
  return fromBackendResponse(service, bucket, resource);
1465
1474
  }
1466
1475
 
1476
+ /**
1477
+ * Contains a fully specified request.
1478
+ *
1479
+ * @param I - the type of the backend's network response.
1480
+ * @param O - the output response type used by the rest of the SDK.
1481
+ */
1467
1482
  class RequestInfo {
1468
1483
  constructor(url, method,
1469
1484
  /**
@@ -1547,7 +1562,7 @@ function sharedErrorHandler(location) {
1547
1562
  if (
1548
1563
  // This exact message string is the only consistent part of the
1549
1564
  // server's error response that identifies it as an App Check error.
1550
- xhr.getResponseText().includes('Firebase App Check token is invalid')) {
1565
+ xhr.getErrorText().includes('Firebase App Check token is invalid')) {
1551
1566
  newErr = unauthorizedApp();
1552
1567
  }
1553
1568
  else {
@@ -1619,6 +1634,19 @@ function list$2(service, location, delimiter, pageToken, maxResults) {
1619
1634
  requestInfo.errorHandler = sharedErrorHandler(location);
1620
1635
  return requestInfo;
1621
1636
  }
1637
+ function getBytes$1(service, location, maxDownloadSizeBytes) {
1638
+ const urlPart = location.fullServerUrl();
1639
+ const url = makeUrl(urlPart, service.host, service._protocol) + '?alt=media';
1640
+ const method = 'GET';
1641
+ const timeout = service.maxOperationRetryTime;
1642
+ const requestInfo = new RequestInfo(url, method, (_, data) => data, timeout);
1643
+ requestInfo.errorHandler = objectErrorHandler(location);
1644
+ if (maxDownloadSizeBytes !== undefined) {
1645
+ requestInfo.headers['Range'] = `bytes=0-${maxDownloadSizeBytes}`;
1646
+ requestInfo.successCodes = [200 /* OK */, 206 /* Partial Content */];
1647
+ }
1648
+ return requestInfo;
1649
+ }
1622
1650
  function getDownloadUrl(service, location, mappings) {
1623
1651
  const urlPart = location.fullServerUrl();
1624
1652
  const url = makeUrl(urlPart, service.host, service._protocol);
@@ -2025,7 +2053,7 @@ function async(f) {
2025
2053
  * limitations under the License.
2026
2054
  */
2027
2055
  /** An override for the text-based Connection. Used in tests. */
2028
- let connectionFactoryOverride = null;
2056
+ let textFactoryOverride = null;
2029
2057
  /**
2030
2058
  * Network layer that works in Node.
2031
2059
  *
@@ -2034,31 +2062,33 @@ let connectionFactoryOverride = null;
2034
2062
  */
2035
2063
  class FetchConnection {
2036
2064
  constructor() {
2065
+ this.errorText_ = '';
2037
2066
  this.sent_ = false;
2038
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2039
2067
  this.fetch_ = nodeFetch__default["default"];
2040
2068
  this.errorCode_ = ErrorCode.NO_ERROR;
2041
2069
  }
2042
- send(url, method, body, headers) {
2070
+ async send(url, method, body, headers) {
2043
2071
  if (this.sent_) {
2044
2072
  throw internalError('cannot .send() more than once');
2045
2073
  }
2046
2074
  this.sent_ = true;
2047
- return this.fetch_(url, {
2048
- method,
2049
- headers: headers || {},
2050
- body
2051
- }).then(resp => {
2052
- this.headers_ = resp.headers;
2053
- this.statusCode_ = resp.status;
2054
- return resp.text().then(body => {
2055
- this.body_ = body;
2075
+ try {
2076
+ const response = await this.fetch_(url, {
2077
+ method,
2078
+ headers: headers || {},
2079
+ body: body
2056
2080
  });
2057
- }, (_err) => {
2058
- this.errorCode_ = ErrorCode.NETWORK_ERROR;
2081
+ this.headers_ = response.headers;
2082
+ this.statusCode_ = response.status;
2083
+ this.errorCode_ = ErrorCode.NO_ERROR;
2084
+ this.body_ = await response.arrayBuffer();
2085
+ }
2086
+ catch (e) {
2087
+ this.errorText_ = e.message;
2059
2088
  // emulate XHR which sets status to 0 when encountering a network error
2060
2089
  this.statusCode_ = 0;
2061
- });
2090
+ this.errorCode_ = ErrorCode.NETWORK_ERROR;
2091
+ }
2062
2092
  }
2063
2093
  getErrorCode() {
2064
2094
  if (this.errorCode_ === undefined) {
@@ -2072,35 +2102,86 @@ class FetchConnection {
2072
2102
  }
2073
2103
  return this.statusCode_;
2074
2104
  }
2075
- getResponseText() {
2076
- if (this.body_ === undefined) {
2077
- throw internalError('cannot .getResponseText() before receiving response');
2078
- }
2079
- return this.body_;
2105
+ getErrorText() {
2106
+ return this.errorText_;
2080
2107
  }
2081
2108
  abort() {
2082
2109
  // Not supported
2083
2110
  }
2084
2111
  getResponseHeader(header) {
2085
2112
  if (!this.headers_) {
2086
- throw internalError('cannot .getResponseText() before receiving response');
2113
+ throw internalError('cannot .getResponseHeader() before receiving response');
2087
2114
  }
2088
2115
  return this.headers_.get(header);
2089
2116
  }
2090
2117
  addUploadProgressListener(listener) {
2091
2118
  // Not supported
2092
2119
  }
2093
- /**
2094
- * @override
2095
- */
2096
2120
  removeUploadProgressListener(listener) {
2097
2121
  // Not supported
2098
2122
  }
2099
2123
  }
2100
- function newConnection() {
2101
- return connectionFactoryOverride
2102
- ? connectionFactoryOverride()
2103
- : new FetchConnection();
2124
+ class FetchTextConnection extends FetchConnection {
2125
+ getResponse() {
2126
+ if (!this.body_) {
2127
+ throw internalError('cannot .getResponse() before receiving response');
2128
+ }
2129
+ return Buffer.from(this.body_).toString('utf-8');
2130
+ }
2131
+ }
2132
+ function newTextConnection() {
2133
+ return textFactoryOverride
2134
+ ? textFactoryOverride()
2135
+ : new FetchTextConnection();
2136
+ }
2137
+ class FetchBytesConnection extends FetchConnection {
2138
+ getResponse() {
2139
+ if (!this.body_) {
2140
+ throw internalError('cannot .getResponse() before sending');
2141
+ }
2142
+ return this.body_;
2143
+ }
2144
+ }
2145
+ function newBytesConnection() {
2146
+ return new FetchBytesConnection();
2147
+ }
2148
+ class FetchStreamConnection extends FetchConnection {
2149
+ constructor() {
2150
+ super(...arguments);
2151
+ this.stream_ = null;
2152
+ }
2153
+ async send(url, method, body, headers) {
2154
+ if (this.sent_) {
2155
+ throw internalError('cannot .send() more than once');
2156
+ }
2157
+ this.sent_ = true;
2158
+ try {
2159
+ const response = await this.fetch_(url, {
2160
+ method,
2161
+ headers: headers || {},
2162
+ body: body
2163
+ });
2164
+ this.headers_ = response.headers;
2165
+ this.statusCode_ = response.status;
2166
+ this.errorCode_ = ErrorCode.NO_ERROR;
2167
+ this.stream_ = response.body;
2168
+ }
2169
+ catch (e) {
2170
+ this.errorText_ = e.message;
2171
+ // emulate XHR which sets status to 0 when encountering a network error
2172
+ this.statusCode_ = 0;
2173
+ this.errorCode_ = ErrorCode.NETWORK_ERROR;
2174
+ }
2175
+ }
2176
+ getResponse() {
2177
+ if (!this.stream_) {
2178
+ throw internalError('cannot .getResponse() before sending');
2179
+ }
2180
+ return this.stream_;
2181
+ }
2182
+ }
2183
+ function newStreamConnection() {
2184
+ return new FetchStreamConnection();
2104
2185
  }
2105
2186
 
2106
2187
  /**
@@ -2242,7 +2323,7 @@ class UploadTask {
2242
2323
  _createResumable() {
2243
2324
  this._resolveToken((authToken, appCheckToken) => {
2244
2325
  const requestInfo = createResumableUpload(this._ref.storage, this._ref._location, this._mappings, this._blob, this._metadata);
2245
- const createRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2326
+ const createRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
2246
2327
  this._request = createRequest;
2247
2328
  createRequest.getPromise().then((url) => {
2248
2329
  this._request = undefined;
@@ -2257,7 +2338,7 @@ class UploadTask {
2257
2338
  const url = this._uploadUrl;
2258
2339
  this._resolveToken((authToken, appCheckToken) => {
2259
2340
  const requestInfo = getResumableUploadStatus(this._ref.storage, this._ref._location, url, this._blob);
2260
- const statusRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2341
+ const statusRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
2261
2342
  this._request = statusRequest;
2262
2343
  statusRequest.getPromise().then(status => {
2263
2344
  status = status;
@@ -2286,7 +2367,7 @@ class UploadTask {
2286
2367
  this._transition("error" /* ERROR */);
2287
2368
  return;
2288
2369
  }
2289
- const uploadRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2370
+ const uploadRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
2290
2371
  this._request = uploadRequest;
2291
2372
  uploadRequest.getPromise().then((newStatus) => {
2292
2373
  this._increaseMultiplier();
@@ -2312,7 +2393,7 @@ class UploadTask {
2312
2393
  _fetchMetadata() {
2313
2394
  this._resolveToken((authToken, appCheckToken) => {
2314
2395
  const requestInfo = getMetadata$2(this._ref.storage, this._ref._location, this._mappings);
2315
- const metadataRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2396
+ const metadataRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
2316
2397
  this._request = metadataRequest;
2317
2398
  metadataRequest.getPromise().then(metadata => {
2318
2399
  this._request = undefined;
@@ -2324,7 +2405,7 @@ class UploadTask {
2324
2405
  _oneShotUpload() {
2325
2406
  this._resolveToken((authToken, appCheckToken) => {
2326
2407
  const requestInfo = multipartUpload(this._ref.storage, this._ref._location, this._mappings, this._blob, this._metadata);
2327
- const multipartRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2408
+ const multipartRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
2328
2409
  this._request = multipartRequest;
2329
2410
  multipartRequest.getPromise().then(metadata => {
2330
2411
  this._request = undefined;
@@ -2689,6 +2770,51 @@ class Reference {
2689
2770
  }
2690
2771
  }
2691
2772
  }
2773
+ /**
2774
+ * Download the bytes at the object's location.
2775
+ * @returns A Promise containing the downloaded bytes.
2776
+ */
2777
+ function getBytesInternal(ref, maxDownloadSizeBytes) {
2778
+ ref._throwIfRoot('getBytes');
2779
+ const requestInfo = getBytes$1(ref.storage, ref._location, maxDownloadSizeBytes);
2780
+ return ref.storage
2781
+ .makeRequestWithTokens(requestInfo, newBytesConnection)
2782
+ .then(bytes => maxDownloadSizeBytes !== undefined
2783
+ ? // GCS may not honor the Range header for small files
2784
+ bytes.slice(0, maxDownloadSizeBytes)
2785
+ : bytes);
2786
+ }
2787
+ /** Stream the bytes at the object's location. */
2788
+ function getStreamInternal(ref, maxDownloadSizeBytes) {
2789
+ ref._throwIfRoot('getStream');
2790
+ const requestInfo = getBytes$1(ref.storage, ref._location, maxDownloadSizeBytes);
2791
+ /** A transformer that passes through the first n bytes. */
2792
+ const newMaxSizeTransform = n => {
2793
+ let missingBytes = n;
2794
+ return {
2795
+ transform(chunk, encoding, callback) {
2796
+ // GCS may not honor the Range header for small files
2797
+ if (chunk.length < missingBytes) {
2798
+ this.push(chunk);
2799
+ missingBytes -= chunk.length;
2800
+ }
2801
+ else {
2802
+ this.push(chunk.slice(0, missingBytes));
2803
+ this.emit('end');
2804
+ }
2805
+ callback();
2806
+ }
2807
+ };
2808
+ };
2809
+ const result = maxDownloadSizeBytes !== undefined
2810
+ ? new stream.Transform(newMaxSizeTransform(maxDownloadSizeBytes))
2811
+ : new stream.PassThrough();
2812
+ ref.storage
2813
+ .makeRequestWithTokens(requestInfo, newStreamConnection)
2814
+ .then(stream => stream.pipe(result))
2815
+ .catch(e => result.destroy(e));
2816
+ return result;
2817
+ }
2692
2818
  /**
2693
2819
  * Uploads data to this object's location.
2694
2820
  * The upload is not resumable.
@@ -2702,7 +2828,7 @@ function uploadBytes$1(ref, data, metadata) {
2702
2828
  ref._throwIfRoot('uploadBytes');
2703
2829
  const requestInfo = multipartUpload(ref.storage, ref._location, getMappings(), new FbsBlob(data, true), metadata);
2704
2830
  return ref.storage
2705
- .makeRequestWithTokens(requestInfo, newConnection)
2831
+ .makeRequestWithTokens(requestInfo, newTextConnection)
2706
2832
  .then(finalMetadata => {
2707
2833
  return {
2708
2834
  metadata: finalMetadata,
@@ -2819,7 +2945,7 @@ function list$1(ref, options) {
2819
2945
  const op = options || {};
2820
2946
  const requestInfo = list$2(ref.storage, ref._location,
2821
2947
  /*delimiter= */ '/', op.pageToken, op.maxResults);
2822
- return ref.storage.makeRequestWithTokens(requestInfo, newConnection);
2948
+ return ref.storage.makeRequestWithTokens(requestInfo, newTextConnection);
2823
2949
  }
2824
2950
  /**
2825
2951
  * A `Promise` that resolves with the metadata for this object. If this
@@ -2831,7 +2957,7 @@ function list$1(ref, options) {
2831
2957
  function getMetadata$1(ref) {
2832
2958
  ref._throwIfRoot('getMetadata');
2833
2959
  const requestInfo = getMetadata$2(ref.storage, ref._location, getMappings());
2834
- return ref.storage.makeRequestWithTokens(requestInfo, newConnection);
2960
+ return ref.storage.makeRequestWithTokens(requestInfo, newTextConnection);
2835
2961
  }
2836
2962
  /**
2837
2963
  * Updates the metadata for this object.
@@ -2847,7 +2973,7 @@ function getMetadata$1(ref) {
2847
2973
  function updateMetadata$1(ref, metadata) {
2848
2974
  ref._throwIfRoot('updateMetadata');
2849
2975
  const requestInfo = updateMetadata$2(ref.storage, ref._location, metadata, getMappings());
2850
- return ref.storage.makeRequestWithTokens(requestInfo, newConnection);
2976
+ return ref.storage.makeRequestWithTokens(requestInfo, newTextConnection);
2851
2977
  }
2852
2978
  /**
2853
2979
  * Returns the download URL for the given Reference.
@@ -2859,7 +2985,7 @@ function getDownloadURL$1(ref) {
2859
2985
  ref._throwIfRoot('getDownloadURL');
2860
2986
  const requestInfo = getDownloadUrl(ref.storage, ref._location, getMappings());
2861
2987
  return ref.storage
2862
- .makeRequestWithTokens(requestInfo, newConnection)
2988
+ .makeRequestWithTokens(requestInfo, newTextConnection)
2863
2989
  .then(url => {
2864
2990
  if (url === null) {
2865
2991
  throw noDownloadURL();
@@ -2876,7 +3002,7 @@ function getDownloadURL$1(ref) {
2876
3002
  function deleteObject$1(ref) {
2877
3003
  ref._throwIfRoot('deleteObject');
2878
3004
  const requestInfo = deleteObject$2(ref.storage, ref._location);
2879
- return ref.storage.makeRequestWithTokens(requestInfo, newConnection);
3005
+ return ref.storage.makeRequestWithTokens(requestInfo, newTextConnection);
2880
3006
  }
2881
3007
  /**
2882
3008
  * Returns reference for object obtained by appending `childPath` to `ref`.
@@ -3133,7 +3259,7 @@ class FirebaseStorageImpl {
3133
3259
  }
3134
3260
 
3135
3261
  const name = "@firebase/storage";
3136
- const version = "0.8.7";
3262
+ const version = "0.9.0-canary.cb7299cbf";
3137
3263
 
3138
3264
  /**
3139
3265
  * @license
@@ -3172,6 +3298,24 @@ const STORAGE_TYPE = 'storage';
3172
3298
  * See the License for the specific language governing permissions and
3173
3299
  * limitations under the License.
3174
3300
  */
3301
+ /**
3302
+ * Downloads the data at the object's location. Returns an error if the object
3303
+ * is not found.
3304
+ *
3305
+ * To use this functionality, you have to whitelist your app's origin in your
3306
+ * Cloud Storage bucket. See also
3307
+ * https://cloud.google.com/storage/docs/configuring-cors
3308
+ *
3309
+ * @public
3310
+ * @param ref - StorageReference where data should be downloaded.
3311
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
3312
+ * retrieve.
3313
+ * @returns A Promise containing the object's bytes
3314
+ */
3315
+ function getBytes(ref, maxDownloadSizeBytes) {
3316
+ ref = util.getModularInstance(ref);
3317
+ return getBytesInternal(ref, maxDownloadSizeBytes);
3318
+ }
3175
3319
  /**
3176
3320
  * Uploads data to this object's location.
3177
3321
  * The upload is not resumable.
@@ -3346,6 +3490,59 @@ function connectStorageEmulator(storage, host, port, options = {}) {
3346
3490
  connectStorageEmulator$1(storage, host, port, options);
3347
3491
  }
3348
3492
 
3493
+ /**
3494
+ * @license
3495
+ * Copyright 2021 Google LLC
3496
+ *
3497
+ * Licensed under the Apache License, Version 2.0 (the "License");
3498
+ * you may not use this file except in compliance with the License.
3499
+ * You may obtain a copy of the License at
3500
+ *
3501
+ * http://www.apache.org/licenses/LICENSE-2.0
3502
+ *
3503
+ * Unless required by applicable law or agreed to in writing, software
3504
+ * distributed under the License is distributed on an "AS IS" BASIS,
3505
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3506
+ * See the License for the specific language governing permissions and
3507
+ * limitations under the License.
3508
+ */
3509
+ /**
3510
+ * Downloads the data at the object's location. Returns an error if the object
3511
+ * is not found.
3512
+ *
3513
+ * To use this functionality, you have to whitelist your app's origin in your
3514
+ * Cloud Storage bucket. See also
3515
+ * https://cloud.google.com/storage/docs/configuring-cors
3516
+ *
3517
+ * This API is not available in Node.
3518
+ *
3519
+ * @public
3520
+ * @param ref - StorageReference where data should be downloaded.
3521
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
3522
+ * retrieve.
3523
+ * @returns A Promise that resolves with a Blob containing the object's bytes
3524
+ */
3525
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3526
+ function getBlob(ref, maxDownloadSizeBytes) {
3527
+ throw new Error('getBlob() is only available in Browser-like environments');
3528
+ }
3529
+ /**
3530
+ * Downloads the data at the object's location. Raises an error event if the
3531
+ * object is not found.
3532
+ *
3533
+ * This API is only available in Node.
3534
+ *
3535
+ * @public
3536
+ * @param ref - StorageReference where data should be downloaded.
3537
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
3538
+ * retrieve.
3539
+ * @returns A stream with the object's data as bytes
3540
+ */
3541
+ function getStream(ref, maxDownloadSizeBytes) {
3542
+ ref = util.getModularInstance(ref);
3543
+ return getStreamInternal(ref, maxDownloadSizeBytes);
3544
+ }
3545
+
3349
3546
  /**
3350
3547
  * Cloud Storage for Firebase
3351
3548
  *
@@ -3375,9 +3572,12 @@ exports._invalidArgument = invalidArgument;
3375
3572
  exports._invalidRootOperation = invalidRootOperation;
3376
3573
  exports.connectStorageEmulator = connectStorageEmulator;
3377
3574
  exports.deleteObject = deleteObject;
3575
+ exports.getBlob = getBlob;
3576
+ exports.getBytes = getBytes;
3378
3577
  exports.getDownloadURL = getDownloadURL;
3379
3578
  exports.getMetadata = getMetadata;
3380
3579
  exports.getStorage = getStorage;
3580
+ exports.getStream = getStream;
3381
3581
  exports.list = list;
3382
3582
  exports.listAll = listAll;
3383
3583
  exports.ref = ref;