Created
November 6, 2017 19:19
-
-
Save andreasvirkus/83d73d87ba13ef461d906c5e69a895b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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