@firebase/storage 0.9.6-canary.497d34c84 → 0.9.6-canary.59cc9ce3d
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.
package/dist/index.esm2017.js
CHANGED
package/dist/index.esm5.js
CHANGED
package/dist/index.node.cjs.js
CHANGED
|
@@ -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
|
-
|
|
2157
|
-
|
|
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
|
-
|
|
2762
|
-
|
|
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
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
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.
|
|
3272
|
+
const version = "0.9.6-canary.59cc9ce3d";
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|