Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 45551cc

Browse files
committed
Add missing file commit (protocols/dat.js)
1 parent 32a9772 commit 45551cc

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

app/bg/protocols/dat.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* HACK
3+
* Electron has an issue that's causing file read streams to fail to serve
4+
* Reading into memory seems to resolve the issue
5+
* https://github.com/electron/electron/issues/21018
6+
* -prf
7+
*/
8+
import { PassThrough } from 'stream'
9+
function intoStream (text) {
10+
const rv = new PassThrough()
11+
rv.push(text)
12+
rv.push(null)
13+
return rv
14+
}
15+
16+
// exported api
17+
// =
18+
19+
export function register (protocol) {
20+
protocol.registerStreamProtocol('dat', electronHandler)
21+
}
22+
23+
export const electronHandler = async function (request, respond) {
24+
respond({
25+
statusCode: 200,
26+
headers: {
27+
Location: request.replace('dat:', 'hd:')
28+
},
29+
data: intoStream(`Redirecting...`)
30+
})
31+
}

0 commit comments

Comments
 (0)