Skip to content

Commit 5ad8989

Browse files
committed
Move archive events into its own module.
1 parent 483f51c commit 5ad8989

File tree

10 files changed

+317
-271
lines changed

10 files changed

+317
-271
lines changed

archive/archive.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
* Copyright(c) 2011 Google Inc.
1010
*/
1111

12+
// TODO: When up-revving to a major new version, remove this module.
13+
1214
import { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType,
1315
UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent,
14-
UnarchiveProgressEvent, UnarchiveStartEvent, Unarchiver,
15-
UnrarrerInternal, UntarrerInternal, UnzipperInternal,
16-
getUnarchiverInternal } from './decompress-internal.js';
16+
UnarchiveProgressEvent, UnarchiveStartEvent } from './events.js';
17+
import { Unarchiver } from './decompress-internal.js';
1718
import { Unzipper, Unrarrer, Untarrer, getUnarchiver } from './decompress.js';
1819

1920
export {

archive/decompress-internal.js

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

12+
import { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType,
13+
UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent,
14+
UnarchiveProgressEvent, UnarchiveStartEvent } from './events.js';
1215
import { findMimeType } from '../file/sniffer.js';
1316

1417
/**
@@ -31,152 +34,6 @@ export const ThreadingMode = {
3134
* @property {ThreadingMode=} threadingMode The default is WEB_WORKER.
3235
*/
3336

34-
/**
35-
* The UnarchiveEvent types.
36-
*/
37-
export const UnarchiveEventType = {
38-
START: 'start',
39-
APPEND: 'append',
40-
PROGRESS: 'progress',
41-
EXTRACT: 'extract',
42-
FINISH: 'finish',
43-
INFO: 'info',
44-
ERROR: 'error'
45-
};
46-
47-
/**
48-
* An unarchive event.
49-
*/
50-
export class UnarchiveEvent extends Event {
51-
/**
52-
* @param {string} type The event type.
53-
*/
54-
constructor(type) {
55-
super(type);
56-
}
57-
}
58-
59-
/**
60-
* Updates all Archiver listeners that an append has occurred.
61-
*/
62-
export class UnarchiveAppendEvent extends UnarchiveEvent {
63-
/**
64-
* @param {number} numBytes The number of bytes appended.
65-
*/
66-
constructor(numBytes) {
67-
super(UnarchiveEventType.APPEND);
68-
69-
/**
70-
* The number of appended bytes.
71-
* @type {number}
72-
*/
73-
this.numBytes = numBytes;
74-
}
75-
}
76-
77-
/**
78-
* Useful for passing info up to the client (for debugging).
79-
*/
80-
export class UnarchiveInfoEvent extends UnarchiveEvent {
81-
/**
82-
* @param {string} msg The info message.
83-
*/
84-
constructor(msg) {
85-
super(UnarchiveEventType.INFO);
86-
87-
/**
88-
* The information message.
89-
* @type {string}
90-
*/
91-
this.msg = msg;
92-
}
93-
}
94-
95-
/**
96-
* An unrecoverable error has occured.
97-
*/
98-
export class UnarchiveErrorEvent extends UnarchiveEvent {
99-
/**
100-
* @param {string} msg The error message.
101-
*/
102-
constructor(msg) {
103-
super(UnarchiveEventType.ERROR);
104-
105-
/**
106-
* The information message.
107-
* @type {string}
108-
*/
109-
this.msg = msg;
110-
}
111-
}
112-
113-
/**
114-
* Start event.
115-
*/
116-
export class UnarchiveStartEvent extends UnarchiveEvent {
117-
constructor() {
118-
super(UnarchiveEventType.START);
119-
}
120-
}
121-
122-
/**
123-
* Finish event.
124-
*/
125-
export class UnarchiveFinishEvent extends UnarchiveEvent {
126-
/**
127-
* @param {Object} metadata A collection fo metadata about the archive file.
128-
*/
129-
constructor(metadata = {}) {
130-
super(UnarchiveEventType.FINISH);
131-
this.metadata = metadata;
132-
}
133-
}
134-
135-
/**
136-
* Progress event.
137-
*/
138-
export class UnarchiveProgressEvent extends UnarchiveEvent {
139-
/**
140-
* @param {string} currentFilename
141-
* @param {number} currentFileNumber
142-
* @param {number} currentBytesUnarchivedInFile
143-
* @param {number} currentBytesUnarchived
144-
* @param {number} totalUncompressedBytesInArchive
145-
* @param {number} totalFilesInArchive
146-
* @param {number} totalCompressedBytesRead
147-
*/
148-
constructor(currentFilename, currentFileNumber, currentBytesUnarchivedInFile,
149-
currentBytesUnarchived, totalUncompressedBytesInArchive, totalFilesInArchive,
150-
totalCompressedBytesRead) {
151-
super(UnarchiveEventType.PROGRESS);
152-
153-
this.currentFilename = currentFilename;
154-
this.currentFileNumber = currentFileNumber;
155-
this.currentBytesUnarchivedInFile = currentBytesUnarchivedInFile;
156-
this.totalFilesInArchive = totalFilesInArchive;
157-
this.currentBytesUnarchived = currentBytesUnarchived;
158-
this.totalUncompressedBytesInArchive = totalUncompressedBytesInArchive;
159-
this.totalCompressedBytesRead = totalCompressedBytesRead;
160-
}
161-
}
162-
163-
/**
164-
* Extract event.
165-
*/
166-
export class UnarchiveExtractEvent extends UnarchiveEvent {
167-
/**
168-
* @param {UnarchivedFile} unarchivedFile
169-
*/
170-
constructor(unarchivedFile) {
171-
super(UnarchiveEventType.EXTRACT);
172-
173-
/**
174-
* @type {UnarchivedFile}
175-
*/
176-
this.unarchivedFile = unarchivedFile;
177-
}
178-
}
179-
18037
/**
18138
* Base class for all Unarchivers.
18239
*/
@@ -422,3 +279,17 @@ export class UntarrerInternal extends Unarchiver {
422279
}
423280
return unarchiver;
424281
}
282+
283+
// Re-export things that used to live here.
284+
// TODO: When up-revving to a major new version, remove these exports?
285+
export {
286+
UnarchiveAppendEvent,
287+
UnarchiveErrorEvent,
288+
UnarchiveEvent,
289+
UnarchiveEventType,
290+
UnarchiveExtractEvent,
291+
UnarchiveFinishEvent,
292+
UnarchiveInfoEvent,
293+
UnarchiveProgressEvent,
294+
UnarchiveStartEvent,
295+
};

archive/decompress.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
* Copyright(c) 2021 Google Inc.
99
*/
1010

11-
import { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType,
12-
UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent,
13-
UnarchiveProgressEvent, UnarchiveStartEvent, Unarchiver,
14-
UnrarrerInternal, UntarrerInternal, UnzipperInternal,
15-
getUnarchiverInternal } from './decompress-internal.js';
11+
import { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType,
12+
UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent,
13+
UnarchiveProgressEvent, UnarchiveStartEvent } from './events.js';
14+
import { Unarchiver, UnrarrerInternal, UntarrerInternal, UnzipperInternal,
15+
getUnarchiverInternal } from './decompress-internal.js';
1616

1717
export {
1818
UnarchiveAppendEvent,

archive/events.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/**
2+
* events.js
3+
*
4+
* Licensed under the MIT License
5+
*
6+
* Copyright(c) 2023 Google Inc.
7+
*/
8+
9+
/**
10+
* The UnarchiveEvent types.
11+
*/
12+
export const UnarchiveEventType = {
13+
START: 'start',
14+
APPEND: 'append',
15+
PROGRESS: 'progress',
16+
EXTRACT: 'extract',
17+
FINISH: 'finish',
18+
INFO: 'info',
19+
ERROR: 'error'
20+
};
21+
22+
/**
23+
* An unarchive event.
24+
*/
25+
export class UnarchiveEvent extends Event {
26+
/**
27+
* @param {string} type The event type.
28+
*/
29+
constructor(type) {
30+
super(type);
31+
}
32+
}
33+
34+
/**
35+
* Updates all Archiver listeners that an append has occurred.
36+
*/
37+
export class UnarchiveAppendEvent extends UnarchiveEvent {
38+
/**
39+
* @param {number} numBytes The number of bytes appended.
40+
*/
41+
constructor(numBytes) {
42+
super(UnarchiveEventType.APPEND);
43+
44+
/**
45+
* The number of appended bytes.
46+
* @type {number}
47+
*/
48+
this.numBytes = numBytes;
49+
}
50+
}
51+
52+
/**
53+
* Useful for passing info up to the client (for debugging).
54+
*/
55+
export class UnarchiveInfoEvent extends UnarchiveEvent {
56+
/**
57+
* @param {string} msg The info message.
58+
*/
59+
constructor(msg) {
60+
super(UnarchiveEventType.INFO);
61+
62+
/**
63+
* The information message.
64+
* @type {string}
65+
*/
66+
this.msg = msg;
67+
}
68+
}
69+
70+
/**
71+
* An unrecoverable error has occured.
72+
*/
73+
export class UnarchiveErrorEvent extends UnarchiveEvent {
74+
/**
75+
* @param {string} msg The error message.
76+
*/
77+
constructor(msg) {
78+
super(UnarchiveEventType.ERROR);
79+
80+
/**
81+
* The information message.
82+
* @type {string}
83+
*/
84+
this.msg = msg;
85+
}
86+
}
87+
88+
/**
89+
* Start event.
90+
*/
91+
export class UnarchiveStartEvent extends UnarchiveEvent {
92+
constructor() {
93+
super(UnarchiveEventType.START);
94+
}
95+
}
96+
97+
/**
98+
* Finish event.
99+
*/
100+
export class UnarchiveFinishEvent extends UnarchiveEvent {
101+
/**
102+
* @param {Object} metadata A collection fo metadata about the archive file.
103+
*/
104+
constructor(metadata = {}) {
105+
super(UnarchiveEventType.FINISH);
106+
this.metadata = metadata;
107+
}
108+
}
109+
110+
/**
111+
* Progress event.
112+
*/
113+
export class UnarchiveProgressEvent extends UnarchiveEvent {
114+
/**
115+
* @param {string} currentFilename
116+
* @param {number} currentFileNumber
117+
* @param {number} currentBytesUnarchivedInFile
118+
* @param {number} currentBytesUnarchived
119+
* @param {number} totalUncompressedBytesInArchive
120+
* @param {number} totalFilesInArchive
121+
* @param {number} totalCompressedBytesRead
122+
*/
123+
constructor(currentFilename, currentFileNumber, currentBytesUnarchivedInFile,
124+
currentBytesUnarchived, totalUncompressedBytesInArchive, totalFilesInArchive,
125+
totalCompressedBytesRead) {
126+
super(UnarchiveEventType.PROGRESS);
127+
128+
this.currentFilename = currentFilename;
129+
this.currentFileNumber = currentFileNumber;
130+
this.currentBytesUnarchivedInFile = currentBytesUnarchivedInFile;
131+
this.totalFilesInArchive = totalFilesInArchive;
132+
this.currentBytesUnarchived = currentBytesUnarchived;
133+
this.totalUncompressedBytesInArchive = totalUncompressedBytesInArchive;
134+
this.totalCompressedBytesRead = totalCompressedBytesRead;
135+
}
136+
}
137+
138+
/**
139+
* Extract event.
140+
*/
141+
export class UnarchiveExtractEvent extends UnarchiveEvent {
142+
/**
143+
* @param {UnarchivedFile} unarchivedFile
144+
*/
145+
constructor(unarchivedFile) {
146+
super(UnarchiveEventType.EXTRACT);
147+
148+
/**
149+
* @type {UnarchivedFile}
150+
*/
151+
this.unarchivedFile = unarchivedFile;
152+
}
153+
}

0 commit comments

Comments
 (0)