@firebase/storage 0.9.6-canary.f84cacd70 → 0.9.7
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/CHANGELOG.md +12 -0
- package/dist/index.browser.cjs.js +1 -1
- package/dist/index.browser.cjs.js.map +1 -1
- package/dist/index.esm2017.js +1 -1
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +1 -1
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +5 -3
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/node-esm/index.node.esm.js +76 -23
- package/dist/node-esm/index.node.esm.js.map +1 -1
- package/package.json +6 -6
|
@@ -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
|
|
|
@@ -2075,6 +2076,7 @@ class FetchConnection {
|
|
|
2075
2076
|
this.errorCode_ = ErrorCode.NO_ERROR;
|
|
2076
2077
|
}
|
|
2077
2078
|
async send(url, method, body, headers) {
|
|
2079
|
+
var _a;
|
|
2078
2080
|
if (this.sent_) {
|
|
2079
2081
|
throw internalError('cannot .send() more than once');
|
|
2080
2082
|
}
|
|
@@ -2091,7 +2093,7 @@ class FetchConnection {
|
|
|
2091
2093
|
this.body_ = await response.arrayBuffer();
|
|
2092
2094
|
}
|
|
2093
2095
|
catch (e) {
|
|
2094
|
-
this.errorText_ = e.message;
|
|
2096
|
+
this.errorText_ = (_a = e) === null || _a === void 0 ? void 0 : _a.message;
|
|
2095
2097
|
// emulate XHR which sets status to 0 when encountering a network error
|
|
2096
2098
|
this.statusCode_ = 0;
|
|
2097
2099
|
this.errorCode_ = ErrorCode.NETWORK_ERROR;
|
|
@@ -2152,8 +2154,44 @@ class FetchBytesConnection extends FetchConnection {
|
|
|
2152
2154
|
function newBytesConnection() {
|
|
2153
2155
|
return new FetchBytesConnection();
|
|
2154
2156
|
}
|
|
2155
|
-
|
|
2156
|
-
|
|
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();
|
|
2157
2195
|
}
|
|
2158
2196
|
|
|
2159
2197
|
/**
|
|
@@ -2756,19 +2794,36 @@ function getBytesInternal(ref, maxDownloadSizeBytes) {
|
|
|
2756
2794
|
bytes.slice(0, maxDownloadSizeBytes)
|
|
2757
2795
|
: bytes);
|
|
2758
2796
|
}
|
|
2759
|
-
/**
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
*/
|
|
2763
|
-
function getBlobInternal(ref, maxDownloadSizeBytes) {
|
|
2764
|
-
ref._throwIfRoot('getBlob');
|
|
2797
|
+
/** Stream the bytes at the object's location. */
|
|
2798
|
+
function getStreamInternal(ref, maxDownloadSizeBytes) {
|
|
2799
|
+
ref._throwIfRoot('getStream');
|
|
2765
2800
|
const requestInfo = getBytes$1(ref.storage, ref._location, maxDownloadSizeBytes);
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
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;
|
|
2772
2827
|
}
|
|
2773
2828
|
/**
|
|
2774
2829
|
* Uploads data to this object's location.
|
|
@@ -3214,7 +3269,7 @@ class FirebaseStorageImpl {
|
|
|
3214
3269
|
}
|
|
3215
3270
|
|
|
3216
3271
|
const name = "@firebase/storage";
|
|
3217
|
-
const version = "0.9.
|
|
3272
|
+
const version = "0.9.7";
|
|
3218
3273
|
|
|
3219
3274
|
/**
|
|
3220
3275
|
* @license
|
|
@@ -3477,9 +3532,9 @@ function connectStorageEmulator(storage, host, port, options = {}) {
|
|
|
3477
3532
|
* retrieve.
|
|
3478
3533
|
* @returns A Promise that resolves with a Blob containing the object's bytes
|
|
3479
3534
|
*/
|
|
3535
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3480
3536
|
function getBlob(ref, maxDownloadSizeBytes) {
|
|
3481
|
-
|
|
3482
|
-
return getBlobInternal(ref, maxDownloadSizeBytes);
|
|
3537
|
+
throw new Error('getBlob() is only available in Browser-like environments');
|
|
3483
3538
|
}
|
|
3484
3539
|
/**
|
|
3485
3540
|
* Downloads the data at the object's location. Raises an error event if the
|
|
@@ -3494,7 +3549,8 @@ function getBlob(ref, maxDownloadSizeBytes) {
|
|
|
3494
3549
|
* @returns A stream with the object's data as bytes
|
|
3495
3550
|
*/
|
|
3496
3551
|
function getStream(ref, maxDownloadSizeBytes) {
|
|
3497
|
-
|
|
3552
|
+
ref = getModularInstance(ref);
|
|
3553
|
+
return getStreamInternal(ref, maxDownloadSizeBytes);
|
|
3498
3554
|
}
|
|
3499
3555
|
|
|
3500
3556
|
/**
|
|
@@ -3510,10 +3566,7 @@ function factory(container, { instanceIdentifier: url }) {
|
|
|
3510
3566
|
}
|
|
3511
3567
|
function registerStorage() {
|
|
3512
3568
|
_registerComponent(new Component(STORAGE_TYPE, factory, "PUBLIC" /* PUBLIC */).setMultipleInstances(true));
|
|
3513
|
-
|
|
3514
|
-
registerVersion(name, version, 'node');
|
|
3515
|
-
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
|
|
3516
|
-
registerVersion(name, version, 'esm2017');
|
|
3569
|
+
registerVersion(name, version);
|
|
3517
3570
|
}
|
|
3518
3571
|
registerStorage();
|
|
3519
3572
|
|