Skip to content

Commit d557383

Browse files
committed
For issue #44, remove the need for a pathToBitJS while unarchiving.
1 parent f71c893 commit d557383

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

archive/compress.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ export class Zipper {
130130
*/
131131
start(files, isLastFile) {
132132
return new Promise((resolve, reject) => {
133+
// TODO: Only use Worker if it exists (like decompress).
134+
// TODO: Remove need for pathToBitJS (like decompress).
133135
this.worker_ = new Worker(this.pathToBitJS + `archive/zip.js`);
134136
this.worker_.onerror = (evt) => {
135137
console.log('Worker error: message = ' + evt.message);

archive/decompress-internal.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* Copyright(c) 2021 Google Inc.
1010
*/
1111

12+
// TODO(bitjs): Consider moving all this back into decompress.js to simplify the code now that
13+
// the implementation isn't tied to Web Workers so heavily.
14+
1215
import { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType,
1316
UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent,
1417
UnarchiveProgressEvent, UnarchiveStartEvent } from './events.js';
@@ -20,11 +23,12 @@ import { findMimeType } from '../file/sniffer.js';
2023
* @property {Uint8Array} fileData
2124
*/
2225

26+
// TODO: Remove pathToBitJS completely from this.
27+
2328
/**
2429
* @typedef UnarchiverOptions
2530
* @property {string} pathToBitJS The path to the bitjs folder.
2631
* @property {boolean=} debug Set to true for verbose unarchiver logging.
27-
* @property {ThreadingMode=} threadingMode The default is WEB_WORKER.
2832
*/
2933

3034
/**
@@ -72,13 +76,6 @@ export class Unarchiver extends EventTarget {
7276
*/
7377
this.connectPortFn_ = connectPortFn;
7478

75-
/**
76-
* The path to the BitJS files.
77-
* @type {string}
78-
* @private
79-
*/
80-
this.pathToBitJS_ = options.pathToBitJS || '/';
81-
8279
/**
8380
* @orivate
8481
* @type {boolean}
@@ -160,8 +157,7 @@ export class Unarchiver extends EventTarget {
160157
const me = this;
161158
const messageChannel = new MessageChannel();
162159
this.port_ = messageChannel.port1;
163-
this.connectPortFn_(this.pathToBitJS_,
164-
this.getScriptFileName(), messageChannel.port2).then(() => {
160+
this.connectPortFn_(this.getScriptFileName(), messageChannel.port2).then(() => {
165161
this.port_.onerror = function (e) {
166162
console.log('Impl error: message = ' + e.message);
167163
throw e;

archive/decompress.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,19 @@ export {
4747
* (e.g. web browsers or deno), imports the implementation inside a Web Worker. Otherwise, it
4848
* dynamically imports the implementation inside the current JS context.
4949
* The MessagePort is used for communication between host and implementation.
50-
* @param {string} pathToBitJS The path to the bitjs folder.
5150
* @param {string} implFilename The decompressor implementation filename relative to this path
5251
* (e.g. './unzip.js').
5352
* @param {MessagePort} implPort The MessagePort to connect to the decompressor implementation.
5453
* @returns {Promise<void>} The Promise resolves once the ports are connected.
5554
*/
56-
const connectPortFn = async (pathToBitJS, implFilename, implPort) => {
55+
const connectPortFn = async (implFilename, implPort) => {
5756
if (typeof Worker === 'undefined') {
58-
return import(`${implFilename}`).then(implModule => {
59-
implModule.connect(implPort)
60-
});
57+
return import(`${implFilename}`).then(implModule => implModule.connect(implPort));
6158
}
62-
59+
6360
return new Promise((resolve, reject) => {
64-
const worker = new Worker(pathToBitJS + 'archive/unarchiver-webworker.js', { type: 'module' });
61+
const workerScriptPath = new URL(`./unarchiver-webworker.js`, import.meta.url).href;
62+
const worker = new Worker(workerScriptPath, { type: 'module' });
6563
worker.postMessage({ implSrc: implFilename }, [implPort]);
6664
resolve();
6765
});

0 commit comments

Comments
 (0)