Skip to content

Commit 8e1f8b1

Browse files
committed
Rename DecompressorOptions to UnarchiverOptions. Add a ThreadingMode enum (only WebWorkers for now). Remove need to keep a handle to the decompressor impl from Unarchiver.
1 parent ac6807e commit 8e1f8b1

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

archive/decompress-internal.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ import { findMimeType } from '../file/sniffer.js';
1818
*/
1919

2020
/**
21-
* @typedef DecompressorOptions
21+
* An enum for threading mode. Currently supporting only WebWorkers.
22+
*/
23+
export const ThreadingMode = {
24+
WEB_WORKER: 'WEB_WORKER',
25+
}
26+
27+
/**
28+
* @typedef UnarchiverOptions
2229
* @property {string} pathToBitJS The path to the bitjs folder.
23-
* @property {boolean=} debug Set to true for verbose decompressor logging.
30+
* @property {boolean=} debug Set to true for verbose unarchiver logging.
31+
* @property {ThreadingMode=} threadingMode The default is WEB_WORKER.
2432
*/
2533

2634
/**
@@ -172,14 +180,7 @@ export class UnarchiveExtractEvent extends UnarchiveEvent {
172180
/**
173181
* Base class for all Unarchivers.
174182
*/
175-
export class Unarchiver extends EventTarget {
176-
/**
177-
* A handle to the decompressor implementation context.
178-
* @type {Worker|*}
179-
* @private
180-
*/
181-
implRef_;
182-
183+
export class Unarchiver extends EventTarget {
183184
/**
184185
* The client-side port that sends messages to, and receives messages from the
185186
* decompressor implementation.
@@ -194,7 +195,7 @@ export class UnarchiveExtractEvent extends UnarchiveEvent {
194195
* to the decompress implementation.
195196
* @param {Function(string, MessagePort):Promise<*>} connectPortFn A function that takes a path
196197
* to a JS decompression implementation (unzip.js) and connects it to a MessagePort.
197-
* @param {DecompressorOptions|string} options An optional object of options, or a string
198+
* @param {UnarchiverOptions|string} options An optional object of options, or a string
198199
* representing where the BitJS files are located. The string version of this argument is
199200
* deprecated.
200201
*/
@@ -203,7 +204,7 @@ export class UnarchiveExtractEvent extends UnarchiveEvent {
203204

204205
if (typeof options === 'string') {
205206
console.warn(`Deprecated: Don't send a raw string to Unarchiver()`);
206-
console.warn(` send DecompressorOptions instead.`);
207+
console.warn(` send UnarchiverOptions instead.`);
207208
options = { 'pathToBitJS': options };
208209
}
209210

@@ -310,10 +311,7 @@ export class UnarchiveExtractEvent extends UnarchiveEvent {
310311
const messageChannel = new MessageChannel();
311312
this.port_ = messageChannel.port1;
312313
this.connectPortFn_(this.pathToBitJS_,
313-
this.getScriptFileName(),
314-
messageChannel.port2).then((implRef) => {
315-
this.implRef_ = implRef;
316-
314+
this.getScriptFileName(), messageChannel.port2).then(() => {
317315
this.port_.onerror = function (e) {
318316
console.log('Impl error: message = ' + e.message);
319317
throw e;
@@ -368,12 +366,6 @@ export class UnarchiveExtractEvent extends UnarchiveEvent {
368366
this.port_.close();
369367
this.port_ = null;
370368
}
371-
if (this.implRef_) {
372-
if (this.implRef_ instanceof Worker) {
373-
this.implRef_.terminate();
374-
this.implRef_ = null;
375-
}
376-
}
377369
}
378370
}
379371

archive/decompress.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ export {
3939
*/
4040

4141
/**
42-
* @typedef {import('./decompress-internal.js').DecompressorOptions} DecompressorOptions
42+
* @typedef {import('./decompress-internal.js').UnarchiverOptions} UnarchiverOptions
4343
*/
4444

4545
/**
46-
* Creates a WebWorker with the given decompressor implementation (i.e. unzip.js)
46+
* Creates a WebWorker with the given decompressor implementation (e.g. unzip.js)
4747
* and transfers a MessagePort for communication. Returns a Promise to the Worker.
4848
* @param {string} pathToBitJS The path to the bitjs folder.
4949
* @param {string} implFilename The decompressor implementation filename
50-
* relative to the bitjs root (e.g. archive/unzip.js)
50+
* relative to this path (e.g. './unzip.js').
5151
* @param {MessagePort} implPort The MessagePort to connect to the decompressor
5252
* implementation.
5353
* @returns {Promise<*>} Returns a Promise that resolves to the Worker object.
@@ -83,9 +83,9 @@ export class Untarrer extends UntarrerInternal {
8383
* @param {ArrayBuffer} ab The ArrayBuffer to unarchive. Note that this ArrayBuffer
8484
* must not be referenced after calling this method, as the ArrayBuffer may be
8585
* transferred to a different JS context once start() is called.
86-
* @param {DecompressorOptions|string} options An optional object of options, or a
86+
* @param {UnarchiverOptions|string} options An optional object of options, or a
8787
* string representing where the path to the unarchiver script files. The latter
88-
* is now deprecated (use DecompressorOptions).
88+
* is now deprecated (use UnarchiverOptions).
8989
* @returns {Unarchiver}
9090
*/
9191
export function getUnarchiver(ab, options = {}) {

0 commit comments

Comments
 (0)