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

Remove unzip/unrar/untar worker dependency on archive.js so that we can turn it into an ES module for Issue #16

This commit is contained in:
codedread 2020-04-02 09:35:31 -07:00
parent 1b00fdaae3
commit 78a11e1b12
4 changed files with 72 additions and 42 deletions

View file

@ -12,7 +12,6 @@
// This file expects to be invoked as a Worker (see onmessage below).
importScripts('../io/bytestream-worker.js');
importScripts('archive.js');
const UnarchiveState = {
NOT_STARTED: 0,
@ -37,21 +36,22 @@ let totalFilesInArchive = 0;
// Helper functions.
const info = function (str) {
postMessage(new bitjs.archive.UnarchiveInfoEvent(str));
postMessage({ type: 'info', msg: str });
};
const err = function (str) {
postMessage(new bitjs.archive.UnarchiveErrorEvent(str));
postMessage({ type: 'error', msg: str });
};
const postProgress = function () {
postMessage(new bitjs.archive.UnarchiveProgressEvent(
postMessage({
type: 'progress',
currentFilename,
currentFileNumber,
currentBytesUnarchivedInFile,
currentBytesUnarchived,
totalUncompressedBytesInArchive,
totalFilesInArchive,
bytestream.getNumBytesRead(),
));
totalCompressedBytesRead: bytestream.getNumBytesRead(),
});
};
// Removes all characters from the first zero-byte in the string onwards.
@ -146,7 +146,7 @@ const untar = function () {
currentFileNumber = totalFilesInArchive++;
currentBytesUnarchivedInFile = oneLocalFile.size;
currentBytesUnarchived += oneLocalFile.size;
postMessage(new bitjs.archive.UnarchiveExtractEvent(oneLocalFile));
postMessage({ type: 'extract', unarchivedFile: oneLocalFile });
postProgress();
}
}
@ -179,7 +179,7 @@ onmessage = function (event) {
totalFilesInArchive = 0;
allLocalFiles = [];
postMessage(new bitjs.archive.UnarchiveStartEvent());
postMessage({ type: 'start' });
unarchiveState = UnarchiveState.UNARCHIVING;
@ -191,7 +191,7 @@ onmessage = function (event) {
try {
untar();
unarchiveState = UnarchiveState.FINISHED;
postMessage(new bitjs.archive.UnarchiveFinishEvent());
postMessage({ type: 'finish', metadata: {} });
} catch (e) {
if (typeof e === 'string' && e.startsWith('Error! Overflowed')) {
// Overrun the buffer.