1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-06 10:49:55 +02:00

For Issue #44, introduce a @typedef for UnarchiverOptions

This commit is contained in:
Jeff Schiller 2023-12-11 00:29:50 -08:00
parent df5c5cfa0f
commit ac6807edec
6 changed files with 73 additions and 46 deletions

View file

@ -17,6 +17,12 @@ import { findMimeType } from '../file/sniffer.js';
* @property {Uint8Array} fileData
*/
/**
* @typedef DecompressorOptions
* @property {string} pathToBitJS The path to the bitjs folder.
* @property {boolean=} debug Set to true for verbose decompressor logging.
*/
/**
* The UnarchiveEvent types.
*/
@ -188,18 +194,16 @@ export class UnarchiveExtractEvent extends UnarchiveEvent {
* to the decompress implementation.
* @param {Function(string, MessagePort):Promise<*>} connectPortFn A function that takes a path
* to a JS decompression implementation (unzip.js) and connects it to a MessagePort.
* @param {Object|string} options An optional object of options, or a string representing where
* the BitJS files are located. The string version of this argument is deprecated.
* Available options:
* 'pathToBitJS': A string indicating where the BitJS files are located.
* 'debug': A boolean where true indicates that the archivers should log debug output.
* @param {DecompressorOptions|string} options An optional object of options, or a string
* representing where the BitJS files are located. The string version of this argument is
* deprecated.
*/
constructor(arrayBuffer, connectPortFn, options = {}) {
super();
if (typeof options === 'string') {
console.warn(`Deprecated: Don't send a raw string to Unarchiver()`);
console.warn(` send {'pathToBitJS':'${options}'} instead`);
console.warn(` send DecompressorOptions instead.`);
options = { 'pathToBitJS': options };
}

View file

@ -38,6 +38,10 @@ export {
* @property {Uint8Array} fileData
*/
/**
* @typedef {import('./decompress-internal.js').DecompressorOptions} DecompressorOptions
*/
/**
* Creates a WebWorker with the given decompressor implementation (i.e. unzip.js)
* and transfers a MessagePort for communication. Returns a Promise to the Worker.
@ -78,9 +82,10 @@ export class Untarrer extends UntarrerInternal {
* in the ArrayBuffer.
* @param {ArrayBuffer} ab The ArrayBuffer to unarchive. Note that this ArrayBuffer
* must not be referenced after calling this method, as the ArrayBuffer may be
* tranferred to a different JS context once start() is called.
* @param {Object|string} options An optional object of options, or a string
* representing where the path to the unarchiver script files.
* transferred to a different JS context once start() is called.
* @param {DecompressorOptions|string} options An optional object of options, or a
* string representing where the path to the unarchiver script files. The latter
* is now deprecated (use DecompressorOptions).
* @returns {Unarchiver}
*/
export function getUnarchiver(ab, options = {}) {

View file

@ -2,12 +2,12 @@
* Factory method that creates an unarchiver based on the byte signature found
* in the arrayBuffer.
* @param {ArrayBuffer} ab
* @param {Function(string):Worker} createWorkerFn A function that creates a Worker from a script file.
* @param {Function(string):Promise<*>} connectPortFn A function that connects the impl port.
* @param {Object|string} options An optional object of options, or a string representing where
* the path to the unarchiver script files.
* @returns {Unarchiver}
*/
export function getUnarchiverInternal(ab: ArrayBuffer, createWorkerFn: any, options?: any | string): Unarchiver;
export function getUnarchiverInternal(ab: ArrayBuffer, connectPortFn: any, options?: any | string): Unarchiver;
export namespace UnarchiveEventType {
const START: string;
const APPEND: string;
@ -118,15 +118,27 @@ export class Unarchiver extends EventTarget {
/**
* @param {ArrayBuffer} arrayBuffer The Array Buffer. Note that this ArrayBuffer must not be
* referenced once it is sent to the Unarchiver, since it is marked as Transferable and sent
* to the Worker.
* @param {Function(string):Worker} createWorkerFn A function that creates a Worker from a script file.
* @param {Object|string} options An optional object of options, or a string representing where
* the BitJS files are located. The string version of this argument is deprecated.
* Available options:
* 'pathToBitJS': A string indicating where the BitJS files are located.
* 'debug': A boolean where true indicates that the archivers should log debug output.
* to the decompress implementation.
* @param {Function(string, MessagePort):Promise<*>} connectPortFn A function that takes a path
* to a JS decompression implementation (unzip.js) and connects it to a MessagePort.
* @param {UnarchiverOptions|string} options An optional object of options, or a string
* representing where the BitJS files are located. The string version of this argument is
* deprecated.
*/
constructor(arrayBuffer: ArrayBuffer, createWorkerFn: any, options?: any | string);
constructor(arrayBuffer: ArrayBuffer, connectPortFn: any, options?: UnarchiverOptions | string);
/**
* A handle to the decompressor implementation context.
* @type {Worker|*}
* @private
*/
private implRef_;
/**
* The client-side port that sends messages to, and receives messages from the
* decompressor implementation.
* @type {MessagePort}
* @private
*/
private port_;
/**
* The ArrayBuffer object.
* @type {ArrayBuffer}
@ -134,11 +146,11 @@ export class Unarchiver extends EventTarget {
*/
protected ab: ArrayBuffer;
/**
* A factory method that creates a Worker that does the unarchive work.
* @type {Function(string): Worker}
* A factory method that connects a port to the decompress implementation.
* @type {Function(MessagePort): Promise<*>}
* @private
*/
private createWorkerFn_;
private connectPortFn_;
/**
* The path to the BitJS files.
* @type {string}
@ -150,12 +162,6 @@ export class Unarchiver extends EventTarget {
* @type {boolean}
*/
debugMode_: boolean;
/**
* Private web worker initialized during start().
* @private
* @type {Worker}
*/
private worker_;
/**
* This method must be overridden by the subclass to return the script filename.
* @returns {string} The MIME type of the archive.
@ -169,7 +175,7 @@ export class Unarchiver extends EventTarget {
*/
protected getScriptFileName(): string;
/**
* Create an UnarchiveEvent out of the object sent back from the Worker.
* Create an UnarchiveEvent out of the object sent back from the implementation.
* @param {Object} obj
* @returns {UnarchiveEvent}
* @private
@ -181,37 +187,47 @@ export class Unarchiver extends EventTarget {
* @param {Object} obj
* @private
*/
private handleWorkerEvent_;
private handlePortEvent_;
/**
* Starts the unarchive in a separate Web Worker thread and returns immediately.
* Starts the unarchive by connecting the ports and sending the first ArrayBuffer.
*/
start(): void;
/**
* Adds more bytes to the unarchiver's Worker thread.
* Adds more bytes to the unarchiver.
* @param {ArrayBuffer} ab The ArrayBuffer with more bytes in it. If opt_transferable is
* set to true, this ArrayBuffer must not be referenced after calling update(), since it
* is marked as Transferable and sent to the Worker.
* is marked as Transferable and sent to the implementation.
* @param {boolean=} opt_transferable Optional boolean whether to mark this ArrayBuffer
* as a Tranferable object, which means it can no longer be referenced outside of
* the Worker thread.
* the implementation context.
*/
update(ab: ArrayBuffer, opt_transferable?: boolean | undefined): void;
/**
* Terminates the Web Worker for this Unarchiver and returns immediately.
* Closes the port to the decompressor implementation and terminates it.
*/
stop(): void;
}
export class UnzipperInternal extends Unarchiver {
constructor(arrayBuffer: any, createWorkerFn: any, options: any);
constructor(arrayBuffer: any, connectPortFn: any, options: any);
}
export class UnrarrerInternal extends Unarchiver {
constructor(arrayBuffer: any, createWorkerFn: any, options: any);
constructor(arrayBuffer: any, connectPortFn: any, options: any);
}
export class UntarrerInternal extends Unarchiver {
constructor(arrayBuffer: any, createWorkerFn: any, options: any);
constructor(arrayBuffer: any, connectPortFn: any, options: any);
}
export type UnarchivedFile = {
filename: string;
fileData: Uint8Array;
};
export type UnarchiverOptions = {
/**
* The path to the bitjs folder.
*/
pathToBitJS: string;
/**
* Set to true for verbose unarchiver logging.
*/
debug?: boolean | undefined;
};
//# sourceMappingURL=decompress-internal.d.ts.map

View file

@ -1 +1 @@
{"version":3,"file":"decompress-internal.d.ts","sourceRoot":"","sources":["../../archive/decompress-internal.js"],"names":[],"mappings":"AAiYA;;;;;;;;GAQG;AACF,0CANU,WAAW,iCAEX,MAAO,MAAM,GAEX,UAAU,CAkBtB;;;;;;;;;;AA1XD;;GAEG;AACF;IACC;;OAEG;IACH,kBAFW,MAAM,EAIhB;CACF;AAED;;GAEG;AACF;IACC;;OAEG;IACH,sBAFW,MAAM,EAUhB;IALC;;;OAGG;IACH,UAFU,MAAM,CAEQ;CAE3B;AAED;;GAEG;AACH;IAOI;;;OAGG;IACH,KAFU,MAAM,CAEF;CAEjB;AAED;;GAEG;AACH;IAOI;;;OAGG;IACH,KAFU,MAAM,CAEF;CAEjB;AAED;;GAEG;AACH;IACE,cAEC;CACF;AAED;;GAEG;AACH;IACE;;OAEG;IACH,4BAGC;IADC,cAAwB;CAE3B;AAED;;GAEG;AACH;IACE;;;;;;;;OAQG;IACH,6BARW,MAAM,qBACN,MAAM,gCACN,MAAM,0BACN,MAAM,mCACN,MAAM,uBACN,MAAM,4BACN,MAAM,EAchB;IAPC,wBAAsC;IACtC,0BAA0C;IAC1C,qCAAgE;IAChE,4BAA8C;IAC9C,+BAAoD;IACpD,wCAAsE;IACtE,iCAAwD;CAE3D;AAED;;GAEG;AACH;IACE;;OAEG;IACH,4BAFW,cAAc,EASxB;IAJC;;OAEG;IACH,gBAFU,cAAc,CAEY;CAEvC;AAED;;GAEG;AACF;IACC;;;;;;;;;;OAUG;IACH,yBAVW,WAAW,iCAIX,MAAO,MAAM,EAgDvB;IAjCC;;;;OAIG;IACH,cAHU,WAAW,CAGA;IAErB;;;;OAIG;IACH,wBAAqC;IAErC;;;;OAIG;IACH,qBAA8C;IAE9C;;;OAGG;IACH,YAFU,OAAO,CAEkB;IAEnC;;;;OAIG;IACH,gBAAmB;IAGrB;;;;OAIG;IACH,yBAHa,MAAM,CAKlB;IAED;;;;OAIG;IACH,+BAHa,MAAM,CAKlB;IAED;;;;;OAKG;IACH,8BAsBC;IAED;;;;;OAKG;IACH,2BAWC;IAED;;OAEG;IACH,cA2BC;IAID;;;;;;;;OAQG;IACH,WAPW,WAAW,qBAGX,OAAO,oBAgBjB;IAED;;OAEG;IACH,aAIC;CACF;AAED;IACE,iEAEC;CAIF;AAED;IACE,iEAEC;CAIF;AAED;IACE,iEAEC;CAIF;;cAhXa,MAAM;cACN,UAAU"}
{"version":3,"file":"decompress-internal.d.ts","sourceRoot":"","sources":["../../archive/decompress-internal.js"],"names":[],"mappings":"AAsZA;;;;;;;;GAQG;AACF,0CANU,WAAW,gCAEX,MAAO,MAAM,GAEX,UAAU,CAkBtB;;;;;;;;;;AAzYD;;GAEG;AACH;IACE;;OAEG;IACH,kBAFW,MAAM,EAIhB;CACF;AAED;;GAEG;AACH;IACE;;OAEG;IACH,sBAFW,MAAM,EAUhB;IALC;;;OAGG;IACH,UAFU,MAAM,CAEQ;CAE3B;AAED;;GAEG;AACH;IAOI;;;OAGG;IACH,KAFU,MAAM,CAEF;CAEjB;AAED;;GAEG;AACH;IAOI;;;OAGG;IACH,KAFU,MAAM,CAEF;CAEjB;AAED;;GAEG;AACH;IACE,cAEC;CACF;AAED;;GAEG;AACH;IACE;;OAEG;IACH,4BAGC;IADC,cAAwB;CAE3B;AAED;;GAEG;AACH;IACE;;;;;;;;OAQG;IACH,6BARW,MAAM,qBACN,MAAM,gCACN,MAAM,0BACN,MAAM,mCACN,MAAM,uBACN,MAAM,4BACN,MAAM,EAchB;IAPC,wBAAsC;IACtC,0BAA0C;IAC1C,qCAAgE;IAChE,4BAA8C;IAC9C,+BAAoD;IACpD,wCAAsE;IACtE,iCAAwD;CAE3D;AAED;;GAEG;AACH;IACE;;OAEG;IACH,4BAFW,cAAc,EASxB;IAJC;;OAEG;IACH,gBAFU,cAAc,CAEY;CAEvC;AAED;;GAEG;AACF;IAgBC;;;;;;;;;OASG;IACH,yBATW,WAAW,gCAKX,iBAAiB,GAAC,MAAM,EAuClC;IA5DD;;;;OAIG;IACH,iBAAS;IAET;;;;;OAKG;IACH,cAAM;IAqBJ;;;;OAIG;IACH,cAHU,WAAW,CAGA;IAErB;;;;OAIG;IACH,uBAAmC;IAEnC;;;;OAIG;IACH,qBAA8C;IAE9C;;;OAGG;IACH,YAFU,OAAO,CAEkB;IAGrC;;;;OAIG;IACH,yBAHa,MAAM,CAKlB;IAED;;;;OAIG;IACH,+BAHa,MAAM,CAKlB;IAED;;;;;OAKG;IACH,8BAsBC;IAED;;;;;OAKG;IACH,yBAWC;IAED;;OAEG;IACH,cA8BC;IAED;;;;;;;;OAQG;IACH,WAPW,WAAW,qBAGX,OAAO,oBAgBjB;IAED;;OAEG;IACH,aAWC;CACF;AAED;IACE,gEAEC;CAIF;AAED;IACE,gEAEC;CAIF;AAED;IACE,gEAEC;CAIF;;cArYa,MAAM;cACN,UAAU;;;;;;iBAKV,MAAM;;;;YACN,OAAO"}

View file

@ -1,14 +1,15 @@
/**
* Factory method that creates an unarchiver based on the byte signature found
* in the arrayBuffer.
* in the ArrayBuffer.
* @param {ArrayBuffer} ab The ArrayBuffer to unarchive. Note that this ArrayBuffer
* must not be referenced after calling this method, as the ArrayBuffer is marked
* as Transferable and sent to a Worker thread once start() is called.
* @param {Object|string} options An optional object of options, or a string
* representing where the path to the unarchiver script files.
* must not be referenced after calling this method, as the ArrayBuffer may be
* transferred to a different JS context once start() is called.
* @param {UnarchiverOptions|string} options An optional object of options, or a
* string representing where the path to the unarchiver script files. The latter
* is now deprecated (use UnarchiverOptions).
* @returns {Unarchiver}
*/
export function getUnarchiver(ab: ArrayBuffer, options?: any | string): Unarchiver;
export function getUnarchiver(ab: ArrayBuffer, options?: UnarchiverOptions | string): Unarchiver;
export class Unzipper extends UnzipperInternal {
constructor(ab: any, options: any);
}
@ -22,6 +23,7 @@ export type UnarchivedFile = {
filename: string;
fileData: Uint8Array;
};
export type UnarchiverOptions = import('./decompress-internal.js').UnarchiverOptions;
import { Unarchiver } from "./decompress-internal.js";
import { UnarchiveAppendEvent } from "./decompress-internal.js";
import { UnarchiveErrorEvent } from "./decompress-internal.js";

View file

@ -1 +1 @@
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../../archive/decompress.js"],"names":[],"mappings":"AAuEA;;;;;;;;;EASE;AACF,kCAPU,WAAW,YAGX,MAAO,MAAM,GAEX,UAAU,CAIrB;AAxBD;IACE,mCAAgE;CACjE;AAED;IACE,mCAAgE;CACjE;AAED;IACE,mCAAgE;CACjE;;cAjCa,MAAM;cACN,UAAU"}
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../../archive/decompress.js"],"names":[],"mappings":"AA+EA;;;;;;;;;;EAUE;AACF,kCARU,WAAW,YAGX,iBAAiB,GAAC,MAAM,GAGtB,UAAU,CAIrB;AAzBD;IACE,mCAA+D;CAChE;AAED;IACE,mCAA+D;CAChE;AAED;IACE,mCAA+D;CAChE;;cAzCa,MAAM;cACN,UAAU;;gCAIX,OAAO,0BAA0B,EAAE,iBAAiB"}