mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 17:49:16 +02:00
Move archive events into its own module.
This commit is contained in:
parent
483f51ceeb
commit
5ad89892bd
10 changed files with 317 additions and 271 deletions
|
@ -9,6 +9,9 @@
|
|||
* Copyright(c) 2021 Google Inc.
|
||||
*/
|
||||
|
||||
import { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType,
|
||||
UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent,
|
||||
UnarchiveProgressEvent, UnarchiveStartEvent } from './events.js';
|
||||
import { findMimeType } from '../file/sniffer.js';
|
||||
|
||||
/**
|
||||
|
@ -31,152 +34,6 @@ export const ThreadingMode = {
|
|||
* @property {ThreadingMode=} threadingMode The default is WEB_WORKER.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The UnarchiveEvent types.
|
||||
*/
|
||||
export const UnarchiveEventType = {
|
||||
START: 'start',
|
||||
APPEND: 'append',
|
||||
PROGRESS: 'progress',
|
||||
EXTRACT: 'extract',
|
||||
FINISH: 'finish',
|
||||
INFO: 'info',
|
||||
ERROR: 'error'
|
||||
};
|
||||
|
||||
/**
|
||||
* An unarchive event.
|
||||
*/
|
||||
export class UnarchiveEvent extends Event {
|
||||
/**
|
||||
* @param {string} type The event type.
|
||||
*/
|
||||
constructor(type) {
|
||||
super(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all Archiver listeners that an append has occurred.
|
||||
*/
|
||||
export class UnarchiveAppendEvent extends UnarchiveEvent {
|
||||
/**
|
||||
* @param {number} numBytes The number of bytes appended.
|
||||
*/
|
||||
constructor(numBytes) {
|
||||
super(UnarchiveEventType.APPEND);
|
||||
|
||||
/**
|
||||
* The number of appended bytes.
|
||||
* @type {number}
|
||||
*/
|
||||
this.numBytes = numBytes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful for passing info up to the client (for debugging).
|
||||
*/
|
||||
export class UnarchiveInfoEvent extends UnarchiveEvent {
|
||||
/**
|
||||
* @param {string} msg The info message.
|
||||
*/
|
||||
constructor(msg) {
|
||||
super(UnarchiveEventType.INFO);
|
||||
|
||||
/**
|
||||
* The information message.
|
||||
* @type {string}
|
||||
*/
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An unrecoverable error has occured.
|
||||
*/
|
||||
export class UnarchiveErrorEvent extends UnarchiveEvent {
|
||||
/**
|
||||
* @param {string} msg The error message.
|
||||
*/
|
||||
constructor(msg) {
|
||||
super(UnarchiveEventType.ERROR);
|
||||
|
||||
/**
|
||||
* The information message.
|
||||
* @type {string}
|
||||
*/
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start event.
|
||||
*/
|
||||
export class UnarchiveStartEvent extends UnarchiveEvent {
|
||||
constructor() {
|
||||
super(UnarchiveEventType.START);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish event.
|
||||
*/
|
||||
export class UnarchiveFinishEvent extends UnarchiveEvent {
|
||||
/**
|
||||
* @param {Object} metadata A collection fo metadata about the archive file.
|
||||
*/
|
||||
constructor(metadata = {}) {
|
||||
super(UnarchiveEventType.FINISH);
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Progress event.
|
||||
*/
|
||||
export class UnarchiveProgressEvent extends UnarchiveEvent {
|
||||
/**
|
||||
* @param {string} currentFilename
|
||||
* @param {number} currentFileNumber
|
||||
* @param {number} currentBytesUnarchivedInFile
|
||||
* @param {number} currentBytesUnarchived
|
||||
* @param {number} totalUncompressedBytesInArchive
|
||||
* @param {number} totalFilesInArchive
|
||||
* @param {number} totalCompressedBytesRead
|
||||
*/
|
||||
constructor(currentFilename, currentFileNumber, currentBytesUnarchivedInFile,
|
||||
currentBytesUnarchived, totalUncompressedBytesInArchive, totalFilesInArchive,
|
||||
totalCompressedBytesRead) {
|
||||
super(UnarchiveEventType.PROGRESS);
|
||||
|
||||
this.currentFilename = currentFilename;
|
||||
this.currentFileNumber = currentFileNumber;
|
||||
this.currentBytesUnarchivedInFile = currentBytesUnarchivedInFile;
|
||||
this.totalFilesInArchive = totalFilesInArchive;
|
||||
this.currentBytesUnarchived = currentBytesUnarchived;
|
||||
this.totalUncompressedBytesInArchive = totalUncompressedBytesInArchive;
|
||||
this.totalCompressedBytesRead = totalCompressedBytesRead;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract event.
|
||||
*/
|
||||
export class UnarchiveExtractEvent extends UnarchiveEvent {
|
||||
/**
|
||||
* @param {UnarchivedFile} unarchivedFile
|
||||
*/
|
||||
constructor(unarchivedFile) {
|
||||
super(UnarchiveEventType.EXTRACT);
|
||||
|
||||
/**
|
||||
* @type {UnarchivedFile}
|
||||
*/
|
||||
this.unarchivedFile = unarchivedFile;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for all Unarchivers.
|
||||
*/
|
||||
|
@ -422,3 +279,17 @@ export class UntarrerInternal extends Unarchiver {
|
|||
}
|
||||
return unarchiver;
|
||||
}
|
||||
|
||||
// Re-export things that used to live here.
|
||||
// TODO: When up-revving to a major new version, remove these exports?
|
||||
export {
|
||||
UnarchiveAppendEvent,
|
||||
UnarchiveErrorEvent,
|
||||
UnarchiveEvent,
|
||||
UnarchiveEventType,
|
||||
UnarchiveExtractEvent,
|
||||
UnarchiveFinishEvent,
|
||||
UnarchiveInfoEvent,
|
||||
UnarchiveProgressEvent,
|
||||
UnarchiveStartEvent,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue