diff --git a/src/main/frontend/worker/sync/download.cljs b/src/main/frontend/worker/sync/download.cljs index 71e04dddaf..6ac59cb290 100644 --- a/src/main/frontend/worker/sync/download.cljs +++ b/src/main/frontend/worker/sync/download.cljs @@ -58,19 +58,43 @@ ( resp .-headers (.get "content-encoding"))] - (cond - (nil? (.-body resp)) - nil +(defn- (.read reader) + (p/then (fn [result] + (if (.-done result) + false + (gzip-bytes? (->uint8 (.-value result)))))) + (p/catch (fn [_] false)) + (p/finally (fn [] + (try + (.releaseLock reader) + (catch :default _))))))) - (= "gzip" encoding) - (when (exists? js/DecompressionStream) - (.pipeThrough (.-body resp) (js/DecompressionStream. "gzip"))) +(defn- resp .-headers (.get "content-encoding"))] + (cond + (nil? body) + (p/resolved nil) + + (and (= "gzip" encoding) (exists? js/DecompressionStream)) + (if (fn? (.-tee body)) + (let [branches (.tee body) + probe (aget branches 0) + payload (aget branches 1)] + (-> (uint8 (.-value result))) - pending (into pending rows)] - (p/let [pending (uint8 (.-value result))) + pending (into pending rows)] + (p/let [pending ( (#'sync-download/