mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 09:39:16 +02:00
For issue #44, remove the need for a pathToBitJS while unarchiving.
This commit is contained in:
parent
f71c893f63
commit
d557383c9d
3 changed files with 13 additions and 17 deletions
|
@ -130,6 +130,8 @@ export class Zipper {
|
|||
*/
|
||||
start(files, isLastFile) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// TODO: Only use Worker if it exists (like decompress).
|
||||
// TODO: Remove need for pathToBitJS (like decompress).
|
||||
this.worker_ = new Worker(this.pathToBitJS + `archive/zip.js`);
|
||||
this.worker_.onerror = (evt) => {
|
||||
console.log('Worker error: message = ' + evt.message);
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
* Copyright(c) 2021 Google Inc.
|
||||
*/
|
||||
|
||||
// TODO(bitjs): Consider moving all this back into decompress.js to simplify the code now that
|
||||
// the implementation isn't tied to Web Workers so heavily.
|
||||
|
||||
import { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType,
|
||||
UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent,
|
||||
UnarchiveProgressEvent, UnarchiveStartEvent } from './events.js';
|
||||
|
@ -20,11 +23,12 @@ import { findMimeType } from '../file/sniffer.js';
|
|||
* @property {Uint8Array} fileData
|
||||
*/
|
||||
|
||||
// TODO: Remove pathToBitJS completely from this.
|
||||
|
||||
/**
|
||||
* @typedef UnarchiverOptions
|
||||
* @property {string} pathToBitJS The path to the bitjs folder.
|
||||
* @property {boolean=} debug Set to true for verbose unarchiver logging.
|
||||
* @property {ThreadingMode=} threadingMode The default is WEB_WORKER.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -72,13 +76,6 @@ export class Unarchiver extends EventTarget {
|
|||
*/
|
||||
this.connectPortFn_ = connectPortFn;
|
||||
|
||||
/**
|
||||
* The path to the BitJS files.
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.pathToBitJS_ = options.pathToBitJS || '/';
|
||||
|
||||
/**
|
||||
* @orivate
|
||||
* @type {boolean}
|
||||
|
@ -160,8 +157,7 @@ export class Unarchiver extends EventTarget {
|
|||
const me = this;
|
||||
const messageChannel = new MessageChannel();
|
||||
this.port_ = messageChannel.port1;
|
||||
this.connectPortFn_(this.pathToBitJS_,
|
||||
this.getScriptFileName(), messageChannel.port2).then(() => {
|
||||
this.connectPortFn_(this.getScriptFileName(), messageChannel.port2).then(() => {
|
||||
this.port_.onerror = function (e) {
|
||||
console.log('Impl error: message = ' + e.message);
|
||||
throw e;
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue