@axium/client 0.39.6 → 0.39.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/dist/uploads.js +21 -2
- package/package.json +1 -1
package/dist/uploads.js
CHANGED
|
@@ -11,6 +11,25 @@ async function handleError(response) {
|
|
|
11
11
|
const json = await response.json();
|
|
12
12
|
throw json.message;
|
|
13
13
|
}
|
|
14
|
+
/** Whether request bodies can be streams, rather than being coerced to a string. */
|
|
15
|
+
let supportsRequestStreams;
|
|
16
|
+
try {
|
|
17
|
+
const request = new Request('about:blank', {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
body: new ReadableStream({
|
|
20
|
+
start(controller) {
|
|
21
|
+
controller.enqueue(new Uint8Array([0]));
|
|
22
|
+
controller.close();
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
duplex: 'half',
|
|
26
|
+
});
|
|
27
|
+
const data = await request.arrayBuffer();
|
|
28
|
+
supportsRequestStreams = data.byteLength == 1;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
supportsRequestStreams = false;
|
|
32
|
+
}
|
|
14
33
|
/**
|
|
15
34
|
* Does a chunked upload to a given endpoint
|
|
16
35
|
*/
|
|
@@ -63,10 +82,10 @@ export async function uploadChunked(options) {
|
|
|
63
82
|
});
|
|
64
83
|
let init = { duplex: 'half' };
|
|
65
84
|
/** @see https://bugzilla.mozilla.org/show_bug.cgi?id=1387483 */
|
|
66
|
-
if (
|
|
85
|
+
if (!supportsRequestStreams) {
|
|
67
86
|
await body.cancel();
|
|
68
87
|
init = {};
|
|
69
|
-
warnOnce('Using a workaround
|
|
88
|
+
warnOnce('Using a workaround since upload streams are not supported [https://bugzilla.mozilla.org/show_bug.cgi?id=1387483]');
|
|
70
89
|
const chunkData = new Uint8Array(chunkSize);
|
|
71
90
|
let bytesReadForChunk = 0;
|
|
72
91
|
if (buffer.length > 0) {
|