- From: HP4k1h5 <notifications@github.com>
- Date: Tue, 04 Feb 2020 19:19:39 -0800
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 5 February 2020 03:19:41 UTC
I have achieved similar results with almost no perf loss using ```javascript async function prog(response) { store.state.search.viewProg = 0 const reader = response.body.getReader() const contentLengthHeader = response.headers.get('Content-Length') const resourceSize = parseInt(contentLengthHeader, 10) let res = [] async function read(reader, totalChunkSize = 0) { const { value = {}, done } = await reader.read() if (done) { store.state.search.viewProg = 0 let r = Buffer.from(res) return JSON.parse(r.toString()) } // push new bytes to res const length = value.byteLength for (let i = 0; i < length; i++) { res.push(value[i]) } const percentComplete = Math.round( ((totalChunkSize + length) / resourceSize) * 100, ) store.state.search.viewProg = percentComplete return await read(reader, totalChunkSize + length) } return await read(reader) } ``` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/607#issuecomment-582222334
Received on Wednesday, 5 February 2020 03:19:41 UTC