generated from ztimson/template
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96ddcbe67a | |||
| d10ee1d686 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/zim-utils",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.3",
|
||||
"description": "Native, dependency-light ZIM archive reader/searcher and Kiwix catalog downloader for Node.js",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -160,16 +160,6 @@ export class ZimManager {
|
||||
|
||||
/** Opens a fresh `ZimReader` for a local ZIM, resolved by file path or catalog `name`. Caller must `.close()` it. */
|
||||
async open(fileOrName) {
|
||||
await this.#ensureDir();
|
||||
const file = await this.#resolveFile(fileOrName);
|
||||
return new ZimReader(file, {clusterTTL: this.#clusterTTL}).open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cached, persistently-open `ZimReader` for serving requests — avoids
|
||||
* re-opening the file per request. Idle-evicted after `readerTTL` ms of no use.
|
||||
*/
|
||||
async getCached(fileOrName) {
|
||||
await this.#ensureDir();
|
||||
const file = await this.#resolveFile(fileOrName);
|
||||
let entry = this.#readers.get(file);
|
||||
@@ -179,8 +169,12 @@ export class ZimManager {
|
||||
pending = new ZimReader(file, {clusterTTL: this.#clusterTTL}).open();
|
||||
this.#opening.set(file, pending);
|
||||
}
|
||||
const reader = await pending;
|
||||
let reader;
|
||||
try {
|
||||
reader = await pending;
|
||||
} finally {
|
||||
this.#opening.delete(file);
|
||||
}
|
||||
entry = this.#readers.get(file) ?? {reader};
|
||||
this.#readers.set(file, entry);
|
||||
}
|
||||
|
||||
@@ -294,8 +294,14 @@ export class ZimReader {
|
||||
/** Opens the archive and parses its header + mimetype list. */
|
||||
async open() {
|
||||
this.#fd = await fs.promises.open(this.path, 'r');
|
||||
try {
|
||||
await this.#readHeader();
|
||||
await this.#readMimeTypes();
|
||||
} catch (e) {
|
||||
await this.#fd.close();
|
||||
this.#fd = null;
|
||||
throw e;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user