mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
19 lines
553 B
JavaScript
19 lines
553 B
JavaScript
/* eslint-env browser */
|
|
|
|
module.exports = source => (async function * () {
|
|
const matcher = /\r?\n/
|
|
const decoder = new TextDecoder('utf8')
|
|
let buffer = ''
|
|
for await (let chunk of source) {
|
|
if (typeof chunk === 'string') {
|
|
chunk = new TextEncoder().encode(chunk)
|
|
}
|
|
buffer += decoder.decode(chunk, { stream: true })
|
|
const parts = buffer.split(matcher)
|
|
buffer = parts.pop()
|
|
for (let i = 0; i < parts.length; i++) yield JSON.parse(parts[i])
|
|
}
|
|
buffer += decoder.decode()
|
|
if (buffer) yield JSON.parse(buffer)
|
|
})()
|