Last active
October 26, 2018 20:12
-
-
Save RangerMauve/8178c58245d6c9a05003c34fe3ecbbc1 to your computer and use it in GitHub Desktop.
Patch `window.fetch` to support dat:// URLs
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
window._fetch = fetch | |
window.fetch = async function(url) { | |
if(url.startsWith("dat://")) { | |
const parsed = new URL(url) | |
const archive = await DatArchive.load(`dat://${parsed.hostname}`) | |
return { | |
text: async () => { | |
return archive.readFile(parsed.path, "utf8") | |
} | |
} | |
} else { | |
return _fetch(url) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment