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 = [],
|
||||
loaded = 0;
|
||||
return new Promise((resolve, reject) => {
|
||||
const readChunk = chunk => {
|
||||
const readChunk = ({ value, done }) => {
|
||||
try {
|
||||
if (!chunk.done) {
|
||||
const data = chunk.value;
|
||||
chunks.push(data);
|
||||
loaded += arrayByteLength(data);
|
||||
if (done) {
|
||||
const chunkData = arraysToBytes(chunks);
|
||||
chunks = null;
|
||||
resolve(chunkData);
|
||||
return;
|
||||
}
|
||||
|
||||
chunks.push(value);
|
||||
loaded += arrayByteLength(value);
|
||||
if (rangeReader.isStreamingSupported) {
|
||||
this.onProgress({ loaded });
|
||||
}
|
||||
rangeReader.read().then(readChunk, reject);
|
||||
return;
|
||||
}
|
||||
const chunkData = arraysToBytes(chunks);
|
||||
chunks = null;
|
||||
resolve(chunkData);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user