@firebase/storage 0.9.6-canary.cec9946c7 → 0.9.6-canary.d6338f0af

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.
@@ -3407,7 +3407,7 @@ var FirebaseStorageImpl = /** @class */ (function () {
3407
3407
  }());
3408
3408
 
3409
3409
  var name = "@firebase/storage";
3410
- var version = "0.9.6-canary.cec9946c7";
3410
+ var version = "0.9.6-canary.d6338f0af";
3411
3411
 
3412
3412
  /**
3413
3413
  * @license
@@ -3230,7 +3230,7 @@ class FirebaseStorageImpl {
3230
3230
  }
3231
3231
 
3232
3232
  const name = "@firebase/storage";
3233
- const version = "0.9.6-canary.cec9946c7";
3233
+ const version = "0.9.6-canary.d6338f0af";
3234
3234
 
3235
3235
  /**
3236
3236
  * @license
@@ -3403,7 +3403,7 @@ var FirebaseStorageImpl = /** @class */ (function () {
3403
3403
  }());
3404
3404
 
3405
3405
  var name = "@firebase/storage";
3406
- var version = "0.9.6-canary.cec9946c7";
3406
+ var version = "0.9.6-canary.d6338f0af";
3407
3407
 
3408
3408
  /**
3409
3409
  * @license
@@ -3277,7 +3277,7 @@ class FirebaseStorageImpl {
3277
3277
  }
3278
3278
 
3279
3279
  const name = "@firebase/storage";
3280
- const version = "0.9.6-canary.cec9946c7";
3280
+ const version = "0.9.6-canary.d6338f0af";
3281
3281
 
3282
3282
  /**
3283
3283
  * @license
@@ -1,5 +1,6 @@
1
1
  import { getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION } from '@firebase/app';
2
2
  import { FirebaseError, createMockUserToken, getModularInstance } from '@firebase/util';
3
+ import { Transform, PassThrough } from 'stream';
3
4
  import nodeFetch from 'node-fetch';
4
5
  import { Component } from '@firebase/component';
5
6
 
@@ -2153,8 +2154,44 @@ class FetchBytesConnection extends FetchConnection {
2153
2154
  function newBytesConnection() {
2154
2155
  return new FetchBytesConnection();
2155
2156
  }
2156
- function newBlobConnection() {
2157
- throw new Error('Blobs are not supported on Node');
2157
+ class FetchStreamConnection extends FetchConnection {
2158
+ constructor() {
2159
+ super(...arguments);
2160
+ this.stream_ = null;
2161
+ }
2162
+ async send(url, method, body, headers) {
2163
+ var _a;
2164
+ if (this.sent_) {
2165
+ throw internalError('cannot .send() more than once');
2166
+ }
2167
+ this.sent_ = true;
2168
+ try {
2169
+ const response = await this.fetch_(url, {
2170
+ method,
2171
+ headers: headers || {},
2172
+ body: body
2173
+ });
2174
+ this.headers_ = response.headers;
2175
+ this.statusCode_ = response.status;
2176
+ this.errorCode_ = ErrorCode.NO_ERROR;
2177
+ this.stream_ = response.body;
2178
+ }
2179
+ catch (e) {
2180
+ this.errorText_ = (_a = e) === null || _a === void 0 ? void 0 : _a.message;
2181
+ // emulate XHR which sets status to 0 when encountering a network error
2182
+ this.statusCode_ = 0;
2183
+ this.errorCode_ = ErrorCode.NETWORK_ERROR;
2184
+ }
2185
+ }
2186
+ getResponse() {
2187
+ if (!this.stream_) {
2188
+ throw internalError('cannot .getResponse() before sending');
2189
+ }
2190
+ return this.stream_;
2191
+ }
2192
+ }
2193
+ function newStreamConnection() {
2194
+ return new FetchStreamConnection();
2158
2195
  }
2159
2196
 
2160
2197
  /**
@@ -2757,19 +2794,36 @@ function getBytesInternal(ref, maxDownloadSizeBytes) {
2757
2794
  bytes.slice(0, maxDownloadSizeBytes)
2758
2795
  : bytes);
2759
2796
  }
2760
- /**
2761
- * Download the bytes at the object's location.
2762
- * @returns A Promise containing the downloaded blob.
2763
- */
2764
- function getBlobInternal(ref, maxDownloadSizeBytes) {
2765
- ref._throwIfRoot('getBlob');
2797
+ /** Stream the bytes at the object's location. */
2798
+ function getStreamInternal(ref, maxDownloadSizeBytes) {
2799
+ ref._throwIfRoot('getStream');
2766
2800
  const requestInfo = getBytes$1(ref.storage, ref._location, maxDownloadSizeBytes);
2767
- return ref.storage
2768
- .makeRequestWithTokens(requestInfo, newBlobConnection)
2769
- .then(blob => maxDownloadSizeBytes !== undefined
2770
- ? // GCS may not honor the Range header for small files
2771
- blob.slice(0, maxDownloadSizeBytes)
2772
- : blob);
2801
+ /** A transformer that passes through the first n bytes. */
2802
+ const newMaxSizeTransform = n => {
2803
+ let missingBytes = n;
2804
+ return {
2805
+ transform(chunk, encoding, callback) {
2806
+ // GCS may not honor the Range header for small files
2807
+ if (chunk.length < missingBytes) {
2808
+ this.push(chunk);
2809
+ missingBytes -= chunk.length;
2810
+ }
2811
+ else {
2812
+ this.push(chunk.slice(0, missingBytes));
2813
+ this.emit('end');
2814
+ }
2815
+ callback();
2816
+ }
2817
+ };
2818
+ };
2819
+ const result = maxDownloadSizeBytes !== undefined
2820
+ ? new Transform(newMaxSizeTransform(maxDownloadSizeBytes))
2821
+ : new PassThrough();
2822
+ ref.storage
2823
+ .makeRequestWithTokens(requestInfo, newStreamConnection)
2824
+ .then(stream => stream.pipe(result))
2825
+ .catch(e => result.destroy(e));
2826
+ return result;
2773
2827
  }
2774
2828
  /**
2775
2829
  * Uploads data to this object's location.
@@ -3215,7 +3269,7 @@ class FirebaseStorageImpl {
3215
3269
  }
3216
3270
 
3217
3271
  const name = "@firebase/storage";
3218
- const version = "0.9.6-canary.cec9946c7";
3272
+ const version = "0.9.6-canary.d6338f0af";
3219
3273
 
3220
3274
  /**
3221
3275
  * @license
@@ -3478,9 +3532,9 @@ function connectStorageEmulator(storage, host, port, options = {}) {
3478
3532
  * retrieve.
3479
3533
  * @returns A Promise that resolves with a Blob containing the object's bytes
3480
3534
  */
3535
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3481
3536
  function getBlob(ref, maxDownloadSizeBytes) {
3482
- ref = getModularInstance(ref);
3483
- return getBlobInternal(ref, maxDownloadSizeBytes);
3537
+ throw new Error('getBlob() is only available in Browser-like environments');
3484
3538
  }
3485
3539
  /**
3486
3540
  * Downloads the data at the object's location. Raises an error event if the
@@ -3495,7 +3549,8 @@ function getBlob(ref, maxDownloadSizeBytes) {
3495
3549
  * @returns A stream with the object's data as bytes
3496
3550
  */
3497
3551
  function getStream(ref, maxDownloadSizeBytes) {
3498
- throw new Error('getStream() is only supported by NodeJS builds');
3552
+ ref = getModularInstance(ref);
3553
+ return getStreamInternal(ref, maxDownloadSizeBytes);
3499
3554
  }
3500
3555
 
3501
3556
  /**
@@ -3511,10 +3566,7 @@ function factory(container, { instanceIdentifier: url }) {
3511
3566
  }
3512
3567
  function registerStorage() {
3513
3568
  _registerComponent(new Component(STORAGE_TYPE, factory, "PUBLIC" /* PUBLIC */).setMultipleInstances(true));
3514
- //RUNTIME_ENV will be replaced during the compilation to "node" for nodejs and an empty string for browser
3515
- registerVersion(name, version, 'node');
3516
- // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
3517
- registerVersion(name, version, 'esm2017');
3569
+ registerVersion(name, version);
3518
3570
  }
3519
3571
  registerStorage();
3520
3572