Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created November 6, 2017 19:19
Show Gist options
  • Save andreasvirkus/83d73d87ba13ef461d906c5e69a895b0 to your computer and use it in GitHub Desktop.
Save andreasvirkus/83d73d87ba13ef461d906c5e69a895b0 to your computer and use it in GitHub Desktop.
function fetchStream(url) {
const req = new Request(url)
return fetch(req).then(rs => {
const reader = rs.body.getReader()
return reader.read().then(({ done, value }) => {
const decoder = new TextDecoder('utf-8')
return decoder.decode(value)
}).catch(err => console.log(`Could not fetch from ${url}!`, err))
})
}
module.exports = fetchStream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment