1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-05 18:34:17 +02:00

For issue #44, remove the need for a pathToBitJS while unarchiving.

This commit is contained in:
Jeff Schiller 2023-12-12 17:18:42 -08:00
parent f71c893f63
commit d557383c9d
3 changed files with 13 additions and 17 deletions

View file

@ -47,21 +47,19 @@ export {
* (e.g. web browsers or deno), imports the implementation inside a Web Worker. Otherwise, it
* dynamically imports the implementation inside the current JS context.
* The MessagePort is used for communication between host and implementation.
* @param {string} pathToBitJS The path to the bitjs folder.
* @param {string} implFilename The decompressor implementation filename relative to this path
* (e.g. './unzip.js').
* @param {MessagePort} implPort The MessagePort to connect to the decompressor implementation.
* @returns {Promise<void>} The Promise resolves once the ports are connected.
*/
const connectPortFn = async (pathToBitJS, implFilename, implPort) => {
const connectPortFn = async (implFilename, implPort) => {
if (typeof Worker === 'undefined') {
return import(`${implFilename}`).then(implModule => {
implModule.connect(implPort)
});
return import(`${implFilename}`).then(implModule => implModule.connect(implPort));
}
return new Promise((resolve, reject) => {
const worker = new Worker(pathToBitJS + 'archive/unarchiver-webworker.js', { type: 'module' });
const workerScriptPath = new URL(`./unarchiver-webworker.js`, import.meta.url).href;
const worker = new Worker(workerScriptPath, { type: 'module' });
worker.postMessage({ implSrc: implFilename }, [implPort]);
resolve();
});