@@ -15,7 +15,7 @@ import { getConnectedPort } from './common.js';
1515import { findMimeType } from '../file/sniffer.js' ;
1616
1717// Exported as a convenience (and also because this module used to contain these).
18- // TODO(2.0): Remove this export, since they have moved to events.js.
18+ // TODO(2.0): Remove this export, since they have moved to events.js?
1919export {
2020 UnarchiveAppendEvent ,
2121 UnarchiveErrorEvent ,
@@ -31,6 +31,7 @@ export {
3131/**
3232 * All extracted files returned by an Unarchiver will implement
3333 * the following interface:
34+ * TODO: Move this interface into common.js?
3435 */
3536
3637/**
@@ -49,7 +50,7 @@ export {
4950 */
5051export class Unarchiver extends EventTarget {
5152 /**
52- * The client-side port that sends messages to, and receives messages from the
53+ * The client-side port that sends messages to, and receives messages from, the
5354 * decompressor implementation.
5455 * @type {MessagePort }
5556 * @private
@@ -74,6 +75,7 @@ export class Unarchiver extends EventTarget {
7475 constructor ( arrayBuffer , options = { } ) {
7576 super ( ) ;
7677
78+ // TODO(2.0): Remove this.
7779 if ( typeof options === 'string' ) {
7880 console . warn ( `Deprecated: Don't send a raw string to Unarchiver()` ) ;
7981 console . warn ( ` send UnarchiverOptions instead.` ) ;
@@ -95,7 +97,7 @@ export class Unarchiver extends EventTarget {
9597 }
9698
9799 /**
98- * Overridden so that the type hints for eventType are specific.
100+ * Overridden so that the type hints for eventType are specific. Prefer onExtract(), etc.
99101 * @param {'progress'|'extract'|'finish' } eventType
100102 * @param {EventListenerOrEventListenerObject } listener
101103 * @override
@@ -104,6 +106,36 @@ export class Unarchiver extends EventTarget {
104106 super . addEventListener ( eventType , listener ) ;
105107 }
106108
109+ /**
110+ * Type-safe way to subscribe to an UnarchiveExtractEvent.
111+ * @param {function(UnarchiveExtractEvent) } listener
112+ * @returns {Unarchiver } for chaining.
113+ */
114+ onExtract ( listener ) {
115+ super . addEventListener ( UnarchiveEventType . EXTRACT , listener ) ;
116+ return this ;
117+ }
118+
119+ /**
120+ * Type-safe way to subscribe to an UnarchiveFinishEvent.
121+ * @param {function(UnarchiveFinishEvent) } listener
122+ * @returns {Unarchiver } for chaining.
123+ */
124+ onFinish ( listener ) {
125+ super . addEventListener ( UnarchiveEventType . FINISH , listener ) ;
126+ return this ;
127+ }
128+
129+ /**
130+ * Type-safe way to subscribe to an UnarchiveProgressEvent.
131+ * @param {function(UnarchiveProgressEvent) } listener
132+ * @returns {Unarchiver } for chaining.
133+ */
134+ onProgress ( listener ) {
135+ super . addEventListener ( UnarchiveEventType . PROGRESS , listener ) ;
136+ return this ;
137+ }
138+
107139 /**
108140 * This method must be overridden by the subclass to return the script filename.
109141 * @returns {string } The MIME type of the archive.
@@ -154,7 +186,6 @@ export class Unarchiver extends EventTarget {
154186
155187 /**
156188 * Receive an event and pass it to the listener functions.
157- *
158189 * @param {Object } obj
159190 * @returns {boolean } Returns true if the decompression is finished.
160191 * @private
0 commit comments