Skip to content

Commit

Permalink
add allowAdditionalCentralDirectoryEntries option
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Dec 10, 2024
1 parent f0ce35e commit 29e91ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ await archive.init();
The ReadArchive constructor optionally accepts an [ReadArchiveOptions](src/Options/ReadArchiveOptions.js) object with
the following properties:

| Name | Type | Description |
|----------------------------------|---------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `centralDirectoryBufferSize` | number | Buffer size used when reading central directory contents.<br/>Larger buffer sizes may improve performance, but also increase RAM usage. |
| `createEntryIndex` | boolean | Whether an index of all central directory entries should be created the first time they are read.<br/>Massively increases performance when using `findEntry` multiple times. |
| `entryOptions` | [EntryOptions](src/Options/EntryOptions.js) | Options passed to each created Entry object. |
| `ignoreMultiDiskErrors` | boolean | Simply ignore information about multiple disks instead of throwing an error when encountering a multi disk archive |
| `allowTruncatedCentralDirectory` | boolean | Do not throw an error if the central directory does not contain the expected number of entries |
| Name | Type | Description |
|------------------------------------------|---------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `centralDirectoryBufferSize` | number | Buffer size used when reading central directory contents.<br/>Larger buffer sizes may improve performance, but also increase RAM usage. |
| `createEntryIndex` | boolean | Whether an index of all central directory entries should be created the first time they are read.<br/>Massively increases performance when using `findEntry` multiple times. |
| `entryOptions` | [EntryOptions](src/Options/EntryOptions.js) | Options passed to each created Entry object. |
| `ignoreMultiDiskErrors` | boolean | Simply ignore information about multiple disks instead of throwing an error when encountering a multi disk archive |
| `allowTruncatedCentralDirectory` | boolean | Do not throw an error if the central directory does not contain the expected number of entries |
| `allowAdditionalCentralDirectoryEntries` | boolean | Continue reading central directory entries even after the expected number of entries was reached |

[EntryOptions](src/Options/EntryOptions.js) can have the following properties:

Expand Down
4 changes: 3 additions & 1 deletion src/Archive/Entry/EntryIterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default class EntryIterator {
*/
async next() {
if (this.currentEntry >= this.entryCount) {
return null;
if (!this.archive.options.allowAdditionalCentralDirectoryEntries || this.io.offset >= BigInt(this.startOffset) + this.size) {
return null;
}
}
if (this.io.offset >= BigInt(this.startOffset) + this.size) {
if (!this.archive.options.allowTruncatedCentralDirectory) {
Expand Down
2 changes: 2 additions & 0 deletions src/Options/ReadArchiveOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Constants from '../Constants.js';
* @property {EntryOptions|EntryOptionsObject} [entryOptions]
* @property {boolean} [ignoreMultiDiskErrors]
* @property {boolean} [allowTruncatedCentralDirectory]
* @property {boolean} [allowAdditionalCentralDirectoryEntries]
*/


Expand All @@ -17,5 +18,6 @@ export default class ReadArchiveOptions extends Options {
/** @type {EntryOptions|EntryOptionsObject} */ entryOptions = {};
/** @type {boolean} */ ignoreMultiDiskErrors = false;
/** @type {boolean} */ allowTruncatedCentralDirectory = false;
/** @type {boolean} */ allowAdditionalCentralDirectoryEntries = false;
}

0 comments on commit 29e91ce

Please sign in to comment.