MCPcopy
hub / github.com/gildas-lormeau/zip.js / getEntriesGenerator

Method getEntriesGenerator

index-native.cjs:3528–3749  ·  view source on GitHub ↗
(options = {})

Source from the content-addressed store, hash-verified

3526 }
3527
3528 async* getEntriesGenerator(options = {}) {
3529 const zipReader = this;
3530 let { reader } = zipReader;
3531 const { config } = zipReader;
3532 await initStream(reader);
3533 if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
3534 reader = new BlobReader(await new Response(reader.readable).blob());
3535 await initStream(reader);
3536 }
3537 if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
3538 throw new Error(ERR_BAD_FORMAT);
3539 }
3540 reader.chunkSize = getChunkSize(config);
3541 const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, reader.size, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS * 16);
3542 if (!endOfDirectoryInfo) {
3543 const signatureArray = await readUint8Array(reader, 0, 4);
3544 const signatureView = getDataView$1(signatureArray);
3545 if (getUint32(signatureView) == SPLIT_ZIP_FILE_SIGNATURE) {
3546 throw new Error(ERR_SPLIT_ZIP_FILE);
3547 } else {
3548 throw new Error(ERR_EOCDR_NOT_FOUND);
3549 }
3550 }
3551 const endOfDirectoryView = getDataView$1(endOfDirectoryInfo);
3552 let directoryDataLength = getUint32(endOfDirectoryView, 12);
3553 let directoryDataOffset = getUint32(endOfDirectoryView, 16);
3554 const commentOffset = endOfDirectoryInfo.offset;
3555 const commentLength = getUint16(endOfDirectoryView, 20);
3556 const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
3557 let lastDiskNumber = getUint16(endOfDirectoryView, 4);
3558 const expectedLastDiskNumber = reader.lastDiskNumber || 0;
3559 let diskNumber = getUint16(endOfDirectoryView, 6);
3560 let filesLength = getUint16(endOfDirectoryView, 8);
3561 let prependedDataLength = 0;
3562 let startOffset = 0;
3563 if (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS) {
3564 const endOfDirectoryLocatorArray = await readUint8Array(reader, endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH);
3565 const endOfDirectoryLocatorView = getDataView$1(endOfDirectoryLocatorArray);
3566 if (getUint32(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
3567 directoryDataOffset = getBigUint64(endOfDirectoryLocatorView, 8);
3568 let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH, -1);
3569 let endOfDirectoryView = getDataView$1(endOfDirectoryArray);
3570 const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
3571 if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
3572 const originalDirectoryDataOffset = directoryDataOffset;
3573 directoryDataOffset = expectedDirectoryDataOffset;
3574 if (directoryDataOffset > originalDirectoryDataOffset) {
3575 prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
3576 }
3577 endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH, -1);
3578 endOfDirectoryView = getDataView$1(endOfDirectoryArray);
3579 }
3580 if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
3581 throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
3582 }
3583 if (lastDiskNumber == MAX_16_BITS) {
3584 lastDiskNumber = getUint32(endOfDirectoryView, 16);
3585 }

Callers 2

getEntriesMethod · 0.95
constructorMethod · 0.45

Calls 14

arrayBufferMethod · 0.80
initStreamFunction · 0.70
getChunkSizeFunction · 0.70
seekSignatureFunction · 0.70
readUint8ArrayFunction · 0.70
getDataView$1Function · 0.70
getUint32Function · 0.70
getUint16Function · 0.70
getBigUint64Function · 0.70
getOptionValue$1Function · 0.70
readCommonHeaderFunction · 0.70
decodeTextFunction · 0.70

Tested by

no test coverage detected