Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patch `window.fetch` to support dat:// URLs
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