Re-factor the readChunk
function in ChunkedStreamManager.sendRequest
Move the `done` branch to the top of the function, similar to how we usually format things when `ReadableStream`s are used.
This commit is contained in:
parent
a49d1d1615
commit
323d3d246a
@ -291,21 +291,21 @@ class ChunkedStreamManager {
|
|||||||
let chunks = [],
|
let chunks = [],
|
||||||
loaded = 0;
|
loaded = 0;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const readChunk = chunk => {
|
const readChunk = ({ value, done }) => {
|
||||||
try {
|
try {
|
||||||
if (!chunk.done) {
|
if (done) {
|
||||||
const data = chunk.value;
|
const chunkData = arraysToBytes(chunks);
|
||||||
chunks.push(data);
|
chunks = null;
|
||||||
loaded += arrayByteLength(data);
|
resolve(chunkData);
|
||||||
if (rangeReader.isStreamingSupported) {
|
|
||||||
this.onProgress({ loaded });
|
|
||||||
}
|
|
||||||
rangeReader.read().then(readChunk, reject);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const chunkData = arraysToBytes(chunks);
|
|
||||||
chunks = null;
|
chunks.push(value);
|
||||||
resolve(chunkData);
|
loaded += arrayByteLength(value);
|
||||||
|
if (rangeReader.isStreamingSupported) {
|
||||||
|
this.onProgress({ loaded });
|
||||||
|
}
|
||||||
|
rangeReader.read().then(readChunk, reject);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e);
|
reject(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user