hashion
Version:
40 lines (39 loc) • 1.35 kB
JavaScript
var d = Object.defineProperty;
var h = (o, e, r) => e in o ? d(o, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[e] = r;
var s = (o, e, r) => h(o, typeof e != "symbol" ? e + "" : e, r);
import { workerCode as W } from "./core/workerCode.js";
const L = !!window.Worker;
class g {
constructor() {
s(this, "name");
this.name = "sparkMd5Webworker";
}
computeHash(e, r) {
if (!L) {
r(new Error("Web worker is not supported"), { progress: 0 });
return;
}
console.log("In Web Worker");
const { file: u, chunkSize: w } = e, i = URL.createObjectURL(new Blob([W])), t = new Worker(i), p = new AbortController(), l = p.signal, c = () => {
t.postMessage({ type: "DONE" }), t.terminate();
};
return l.addEventListener("abort", () => t.postMessage({ type: "CANCELED" })), t.postMessage({ file: u, chunkSize: w }), t.onmessage = (m) => {
const { error: n, progress: a, hash: k, time: b } = m.data;
if (n) {
r(n, { progress: 0 }), c();
return;
}
if (a === 100) {
c(), r(null, { progress: a, hash: k, time: b }), URL.revokeObjectURL(i);
return;
}
r(n, { progress: a });
}, {
abort: () => p.abort()
};
}
}
s(g, "pluginName", "hash-plugin"), s(g, "name", "sparkMd5Webworker");
export {
g as SparkWorker
};