Skip to content

Commit 87dab4e

Browse files
authored
fix: handle pull requests (#56)
1 parent 20dbb67 commit 87dab4e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

example/sw.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Want to remove this postMessage hack, tell them u want transferable streams:
2+
// https://bugs.webkit.org/show_bug.cgi?id=215485
3+
14
const WRITE = 0
25
const PULL = 0
36
const ERROR = 1
@@ -24,6 +27,10 @@ class MessagePortSource {
2427
this.controller = controller
2528
}
2629

30+
pull () {
31+
this.port.postMessage({ type: PULL })
32+
}
33+
2734
/** @param {Error} reason */
2835
cancel (reason) {
2936
// Firefox can notify a cancel event, chrome can't
@@ -37,7 +44,6 @@ class MessagePortSource {
3744
// enqueue() will call pull() if needed when there's no backpressure
3845
if (message.type === WRITE) {
3946
this.controller.enqueue(message.chunk)
40-
this.port.postMessage({ type: PULL })
4147
}
4248
if (message.type === ABORT) {
4349
this.controller.error(message.reason)

src/adapters/downloader.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const {
99
} = config
1010

1111
const { GONE } = errors
12-
// @ts-ignore
13-
const isSafari = /constructor/i.test(window.HTMLElement) || window.safari || window.WebKitPoint
12+
// @ts-ignore - Don't match newer versions of Safari, but that's okay
13+
const isOldSafari = /constructor/i.test(window.HTMLElement)
1414

1515
export class FileHandle {
1616
constructor (name = 'unkown') {
@@ -37,7 +37,7 @@ export class FileHandle {
3737

3838
link.download = this.name
3939

40-
if (isSafari || !sw) {
40+
if (isOldSafari || !sw) {
4141
/** @type {Blob[]} */
4242
let chunks = []
4343
ts.readable.pipeTo(new WritableStream({
@@ -93,6 +93,9 @@ export class FileHandle {
9393
}
9494
}
9595

96+
// Want to remove this postMessage hack, tell them u want transferable streams:
97+
// https://bugs.webkit.org/show_bug.cgi?id=215485
98+
9699
const WRITE = 0
97100
const PULL = 0
98101
const ERROR = 1

0 commit comments

Comments
 (0)