mirror of
https://github.com/codedread/bitjs
synced 2025-10-04 01:59:15 +02:00
Surface metadata from zip files to clients
This commit is contained in:
parent
2916cf0926
commit
58ac1aed25
2 changed files with 12 additions and 5 deletions
|
@ -88,8 +88,12 @@ bitjs.archive.UnarchiveStartEvent = class extends bitjs.archive.UnarchiveEvent {
|
|||
* Finish event.
|
||||
*/
|
||||
bitjs.archive.UnarchiveFinishEvent = class extends bitjs.archive.UnarchiveEvent {
|
||||
constructor() {
|
||||
/**
|
||||
* @param {Object} metadata A collection fo metadata about the archive file.
|
||||
*/
|
||||
constructor(metadata = {}) {
|
||||
super(bitjs.archive.UnarchiveEvent.Type.FINISH);
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +148,7 @@ bitjs.archive.UnarchiveExtractEvent = class extends bitjs.archive.UnarchiveEvent
|
|||
*
|
||||
* interface UnarchivedFile {
|
||||
* string filename
|
||||
* TypedArray fileData
|
||||
* TypedArray fileData
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
@ -281,6 +285,7 @@ bitjs.archive.Unarchiver = class {
|
|||
|
||||
/**
|
||||
* Adds more bytes to the unarchiver's Worker thread.
|
||||
* @param {ArrayBuffer} ab The ArrayBuffer with more bytes in it.
|
||||
*/
|
||||
update(ab) {
|
||||
if (this.worker_) {
|
||||
|
|
|
@ -574,7 +574,6 @@ function unzip() {
|
|||
}
|
||||
|
||||
// read all file headers
|
||||
// TODO: This structure tells us the intended order of the files in the zip.
|
||||
while (bstream.peekNumber(4) == zCentralFileHeaderSignature) {
|
||||
bstream.readNumber(4); // signature
|
||||
const cdfh = {
|
||||
|
@ -618,6 +617,7 @@ function unzip() {
|
|||
bstream.readString(sizeOfSignature); // digital signature data
|
||||
}
|
||||
|
||||
let metadata = {};
|
||||
if (bstream.peekNumber(4) == zEndOfCentralDirSignature) {
|
||||
bstream.readNumber(4); // signature
|
||||
const eocds = {
|
||||
|
@ -636,11 +636,15 @@ function unzip() {
|
|||
console.log(` ${field} = ${eocds[field]}`);
|
||||
}
|
||||
}
|
||||
metadata.comment = eocds.comment;
|
||||
}
|
||||
|
||||
postProgress();
|
||||
|
||||
bytestream = bstream.tee();
|
||||
|
||||
unarchiveState = UnarchiveState.FINISHED;
|
||||
postMessage(new bitjs.archive.UnarchiveFinishEvent(metadata));
|
||||
}
|
||||
|
||||
// event.data.file has the first ArrayBuffer.
|
||||
|
@ -677,8 +681,6 @@ onmessage = function(event) {
|
|||
unarchiveState === UnarchiveState.WAITING) {
|
||||
try {
|
||||
unzip();
|
||||
unarchiveState = UnarchiveState.FINISHED;
|
||||
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
||||
} catch (e) {
|
||||
if (typeof e === 'string' && e.startsWith('Error! Overflowed')) {
|
||||
// Overrun the buffer.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue