@openzim/libzim 3.2.3 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env CHANGED
@@ -1 +1 @@
1
- LIBZIM_VERSION=9.2.1
1
+ LIBZIM_VERSION=9.3.0
package/Changelog CHANGED
@@ -1,3 +1,12 @@
1
+ 3.4.0
2
+ * NEW: Add new libzim 9.3.0 APIs around cache management
3
+
4
+ 3.3.0
5
+ * NEW: Use libzim 9.3.0
6
+ * UPDATE: Upgrade many dependencies versions
7
+ * UPDATE: drop macOS12, add macOS15 in the CI
8
+ * UPDATE: drop ubuntu-20.04, add ubuntu-24.04 in the CI
9
+
1
10
  3.2.3
2
11
  * FIX: Module (finally) properly in ESM format
3
12
 
package/README.md CHANGED
@@ -6,10 +6,11 @@ This is the Node.js binding to the
6
6
  [ZIM](https://openzim.org) files easily in Javascript.
7
7
 
8
8
  [![npm](https://img.shields.io/npm/v/@openzim/libzim.svg)](https://www.npmjs.com/package/@openzim/libzim)
9
- [![Build Status](https://github.com/openzim/node-libzim/workflows/CI/badge.svg?branch=main)](https://github.com/openzim/node-libzim/actions?query=branch%3Amain)
9
+ [![Build Status](https://github.com/openzim/node-libzim/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/openzim/node-libzim/actions/workflows/ci.yml?query=branch%3Amain)
10
10
  [![codecov](https://codecov.io/gh/openzim/node-libzim/branch/main/graph/badge.svg)](https://codecov.io/gh/openzim/node-libzim)
11
11
  [![CodeFactor](https://www.codefactor.io/repository/github/openzim/node-libzim/badge)](https://www.codefactor.io/repository/github/openzim/node-libzim)
12
12
  [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
13
+ [![Join Slack](https://img.shields.io/badge/Join%20us%20on%20Slack%20%23mwoffliner-2EB67D)](https://slack.kiwix.org)
13
14
 
14
15
  ## Dependencies
15
16
 
package/bundle-libzim.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dotenv from "dotenv";
2
2
  dotenv.config();
3
- import mkdirp from "mkdirp";
3
+ import { mkdirp } from "mkdirp";
4
4
  import exec from "exec-then";
5
5
  import os from "os";
6
6
 
@@ -11,14 +11,14 @@ const isLinux = os.type() === "Linux";
11
11
 
12
12
  if (!isMacOS && !isLinux) {
13
13
  console.warn(
14
- "\x1b[41m\n================================ README \n\nlibzim bundle with prebuilt binaries only available for macOS and Linux:\n\n\thttps://github.com/openzim/libzim/\n\n================================\x1b[0m\n"
14
+ "\x1b[41m\n================================ README \n\nlibzim bundle with prebuilt binaries only available for macOS and Linux:\n\n\thttps://github.com/openzim/libzim/\n\n================================\x1b[0m\n",
15
15
  );
16
16
  }
17
17
 
18
18
  if (isLinux) {
19
19
  console.info("Copying libzim.so.9 to build folder");
20
20
  exec(
21
- "cp download/lib/x86_64-linux-gnu/libzim.so.9 build/Release/libzim.so.9"
21
+ "cp download/lib/x86_64-linux-gnu/libzim.so.9 build/Release/libzim.so.9",
22
22
  );
23
23
  exec("ln -sf build/Release/libzim.so.9 build/Release/libzim.so"); // convienience only, not required
24
24
  }
@@ -28,6 +28,6 @@ if (isMacOS) {
28
28
  exec("ln -sf build/Release/libzim.9.dylib build/Release/libzim.dylib"); // convienience only, not required
29
29
  console.info("Fixing rpath");
30
30
  exec(
31
- "install_name_tool -change libzim.9.dylib @loader_path/libzim.9.dylib build/Release/zim_binding.node"
31
+ "install_name_tool -change libzim.9.dylib @loader_path/libzim.9.dylib build/Release/zim_binding.node",
32
32
  );
33
33
  }
package/dist/index.d.ts CHANGED
@@ -66,7 +66,7 @@ export class StringItem {
66
66
  mimeType: string,
67
67
  title: string,
68
68
  hint: Hint,
69
- content: ArrayBuffer | Buffer | string
69
+ content: ArrayBuffer | Buffer | string,
70
70
  );
71
71
  readonly path: string;
72
72
  readonly title: string;
@@ -81,7 +81,7 @@ export class FileItem {
81
81
  mimeType: string,
82
82
  title: string,
83
83
  hints: Hint,
84
- filePath: string
84
+ filePath: string,
85
85
  );
86
86
  readonly path: string;
87
87
  readonly title: string;
@@ -102,14 +102,14 @@ export class Creator {
102
102
  addMetadata(
103
103
  name: string,
104
104
  content: string | ContentProvider,
105
- mimetype?: string
105
+ mimetype?: string,
106
106
  ): void;
107
107
  addIllustration(size: number, content: string | ContentProvider): void;
108
108
  addRedirection(
109
109
  path: string,
110
110
  title: string,
111
111
  targetPath: string,
112
- hints?: Hint
112
+ hints?: Hint,
113
113
  ): void;
114
114
  setMainPath(mainPath: string): void;
115
115
  setUuid(uuid: string): void;
@@ -182,6 +182,14 @@ export class Archive {
182
182
  checkIntegrity(checkType: symbol): boolean; // one of IntegrityCheck
183
183
  get isMultiPart(): boolean;
184
184
  get hasNewNamespaceScheme(): boolean;
185
+ getClusterCacheMaxSize(): number;
186
+ getClusterCacheCurrentSize(): number;
187
+ setClusterCacheMaxSize(nbClusters: number): void;
188
+ getDirentCacheMaxSize(): number;
189
+ getDirentCacheCurrentSize(): number;
190
+ setDirentCacheMaxSize(nbDirents: number): void;
191
+ getDirentLookupCacheMaxSize(): number;
192
+ setDirentLookupCacheMaxSize(nbRanges: number): void;
185
193
 
186
194
  static validate(zimPath: string, checksToRun: symbol[]): boolean; // list of IntegrityCheck
187
195
  }
@@ -1,7 +1,7 @@
1
1
  import dotenv from "dotenv";
2
2
  dotenv.config();
3
3
  import axios from "axios";
4
- import mkdirp from "mkdirp";
4
+ import { mkdirp } from "mkdirp";
5
5
  import exec from "exec-then";
6
6
  import os from "os";
7
7
  import fs from "fs";
@@ -20,21 +20,21 @@ const isAvailableArch =
20
20
 
21
21
  if (!isMacOS && !isLinux) {
22
22
  console.warn(
23
- `\x1b[41m\n================================ README \n\nPre-built binaries only available on Linux and MacOS for now...\nPlease ensure you have libzim installed globally on this machine:\n\n\thttps://github.com/openzim/libzim/\n\n================================\x1b[0m\n`
23
+ `\x1b[41m\n================================ README \n\nPre-built binaries only available on Linux and MacOS for now...\nPlease ensure you have libzim installed globally on this machine:\n\n\thttps://github.com/openzim/libzim/\n\n================================\x1b[0m\n`,
24
24
  );
25
25
  }
26
26
  if (!isAvailableArch) {
27
27
  console.warn(
28
- `\x1b[41m\n================================ README \n\nPre-built binaries only available on x86_64, arm and arm64 for now...\nPlease ensure you have libzim installed globally on this machine:\n\n\thttps://github.com/openzim/libzim/\n\n================================\x1b[0m\n`
28
+ `\x1b[41m\n================================ README \n\nPre-built binaries only available on x86_64, arm and arm64 for now...\nPlease ensure you have libzim installed globally on this machine:\n\n\thttps://github.com/openzim/libzim/\n\n================================\x1b[0m\n`,
29
29
  );
30
30
  }
31
31
 
32
32
  let osPrefix = isMacOS ? "macos" : "linux";
33
- let osArch = isLinux ? "x86_64-bionic" : "x86_64";
33
+ let osArch = isLinux ? "x86_64" : "x86_64";
34
34
 
35
35
  if (rawArch !== "x64") {
36
36
  if (isLinux) {
37
- osArch = rawArch === "arm64" ? "aarch64-bionic" : "armhf";
37
+ osArch = rawArch === "arm64" ? "aarch64-manylinux" : "armhf";
38
38
  } else {
39
39
  osArch = rawArch;
40
40
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@openzim/libzim",
3
3
  "main": "dist/index.js",
4
4
  "types": "dist/index.d.js",
5
- "version": "3.2.3",
5
+ "version": "3.4.0",
6
6
  "description": "Libzim bindings for NodeJS",
7
7
  "type": "module",
8
8
  "scripts": {
@@ -42,31 +42,30 @@
42
42
  "gypfile": true,
43
43
  "dependencies": {
44
44
  "@types/bindings": "^1.5.1",
45
- "@types/jest": "^28.1.6",
45
+ "@types/jest": "^29.5.12",
46
46
  "@types/node": "^18.0.6",
47
47
  "axios": "^1.6.0",
48
48
  "bindings": "^1.5.0",
49
49
  "dotenv": "^16.0.1",
50
50
  "exec-then": "^1.3.1",
51
- "mkdirp": "^1.0.4",
52
- "node-addon-api": "^5.0.0",
51
+ "mkdirp": "^3.0.1",
52
+ "node-addon-api": "^8.0.0",
53
53
  "node-gyp": "^10.1.0",
54
54
  "tqdm": "^2.0.3",
55
55
  "ts-node": "^10.9.1",
56
56
  "tsconfig-paths": "^4.0.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@faker-js/faker": "^7.6.0",
59
+ "@faker-js/faker": "^8.4.1",
60
60
  "@typescript-eslint/eslint-plugin": "^5.59.2",
61
61
  "@typescript-eslint/parser": "^5.59.2",
62
- "eslint": "^8.39.0",
63
- "eslint-config-prettier": "^8.8.0",
64
- "eslint-plugin-prettier": "^4.2.1",
65
- "jest": "^28.1.3",
66
- "nyc": "^15.1.0",
67
- "prettier": "^2.8.8",
68
- "ts-jest": "^28.0.7",
69
- "typescript": "^4.7.4"
62
+ "eslint": "^8.57.0",
63
+ "eslint-config-prettier": "^8.10.0",
64
+ "eslint-plugin-prettier": "^5.1.3",
65
+ "nyc": "^17.0.0",
66
+ "prettier": "^3.3.2",
67
+ "ts-jest": "^29.1.5",
68
+ "typescript": "^5.1.6"
70
69
  },
71
70
  "jest": {
72
71
  "preset": "ts-jest/presets/js-with-ts"
package/src/archive.h CHANGED
@@ -411,6 +411,85 @@ class Archive : public Napi::ObjectWrap<Archive> {
411
411
  }
412
412
  }
413
413
 
414
+ Napi::Value getClusterCacheMaxSize(const Napi::CallbackInfo &info) {
415
+ try {
416
+ return Napi::Value::From(info.Env(), archive_->getClusterCacheMaxSize());
417
+ } catch (const std::exception &err) {
418
+ throw Napi::Error::New(info.Env(), err.what());
419
+ }
420
+ }
421
+
422
+ Napi::Value getClusterCacheCurrentSize(const Napi::CallbackInfo &info) {
423
+ try {
424
+ return Napi::Value::From(info.Env(),
425
+ archive_->getClusterCacheCurrentSize());
426
+ } catch (const std::exception &err) {
427
+ throw Napi::Error::New(info.Env(), err.what());
428
+ }
429
+ }
430
+
431
+ void setClusterCacheMaxSize(const Napi::CallbackInfo &info) {
432
+ try {
433
+ if (!info[0].IsNumber()) {
434
+ throw Napi::Error::New(info.Env(), "Expected a number");
435
+ }
436
+ auto nbClusters = info[0].As<Napi::Number>().Uint32Value();
437
+ archive_->setClusterCacheMaxSize(nbClusters);
438
+ } catch (const std::exception &err) {
439
+ throw Napi::Error::New(info.Env(), err.what());
440
+ }
441
+ }
442
+
443
+ Napi::Value getDirentCacheMaxSize(const Napi::CallbackInfo &info) {
444
+ try {
445
+ return Napi::Value::From(info.Env(), archive_->getDirentCacheMaxSize());
446
+ } catch (const std::exception &err) {
447
+ throw Napi::Error::New(info.Env(), err.what());
448
+ }
449
+ }
450
+
451
+ Napi::Value getDirentCacheCurrentSize(const Napi::CallbackInfo &info) {
452
+ try {
453
+ return Napi::Value::From(info.Env(),
454
+ archive_->getDirentCacheCurrentSize());
455
+ } catch (const std::exception &err) {
456
+ throw Napi::Error::New(info.Env(), err.what());
457
+ }
458
+ }
459
+
460
+ void setDirentCacheMaxSize(const Napi::CallbackInfo &info) {
461
+ try {
462
+ if (!info[0].IsNumber()) {
463
+ throw Napi::Error::New(info.Env(), "Expected a number");
464
+ }
465
+ auto nbDirents = info[0].As<Napi::Number>().Uint32Value();
466
+ archive_->setDirentCacheMaxSize(nbDirents);
467
+ } catch (const std::exception &err) {
468
+ throw Napi::Error::New(info.Env(), err.what());
469
+ }
470
+ }
471
+
472
+ Napi::Value getDirentLookupCacheMaxSize(const Napi::CallbackInfo &info) {
473
+ try {
474
+ return Napi::Value::From(info.Env(),
475
+ archive_->getDirentLookupCacheMaxSize());
476
+ } catch (const std::exception &err) {
477
+ throw Napi::Error::New(info.Env(), err.what());
478
+ }
479
+ }
480
+
481
+ void setDirentLookupCacheMaxSize(const Napi::CallbackInfo &info) {
482
+ try {
483
+ if (!info[0].IsNumber()) {
484
+ throw Napi::Error::New(info.Env(), "Expected a number");
485
+ }
486
+ auto nbRanges = info[0].As<Napi::Number>().Uint32Value();
487
+ archive_->setDirentLookupCacheMaxSize(nbRanges);
488
+ } catch (const std::exception &err) {
489
+ throw Napi::Error::New(info.Env(), err.what());
490
+ }
491
+ }
492
+
414
493
  static Napi::Value validate(const Napi::CallbackInfo &info) {
415
494
  Napi::Env env = info.Env();
416
495
  Napi::HandleScope scope(env);
@@ -485,6 +564,22 @@ class Archive : public Napi::ObjectWrap<Archive> {
485
564
  InstanceAccessor<&Archive::getChecksum>("checksum"),
486
565
  InstanceMethod<&Archive::check>("check"),
487
566
  InstanceMethod<&Archive::checkIntegrity>("checkIntegrity"),
567
+ InstanceMethod<&Archive::getClusterCacheMaxSize>(
568
+ "getClusterCacheMaxSize"),
569
+ InstanceMethod<&Archive::getClusterCacheCurrentSize>(
570
+ "getClusterCacheCurrentSize"),
571
+ InstanceMethod<&Archive::setClusterCacheMaxSize>(
572
+ "setClusterCacheMaxSize"),
573
+ InstanceMethod<&Archive::getDirentCacheMaxSize>(
574
+ "getDirentCacheMaxSize"),
575
+ InstanceMethod<&Archive::getDirentCacheCurrentSize>(
576
+ "getDirentCacheCurrentSize"),
577
+ InstanceMethod<&Archive::setDirentCacheMaxSize>(
578
+ "setDirentCacheMaxSize"),
579
+ InstanceMethod<&Archive::getDirentLookupCacheMaxSize>(
580
+ "getDirentLookupCacheMaxSize"),
581
+ InstanceMethod<&Archive::setDirentLookupCacheMaxSize>(
582
+ "setDirentLookupCacheMaxSize"),
488
583
  InstanceAccessor<&Archive::isMultiPart>("isMultiPart"),
489
584
  InstanceAccessor<&Archive::hasNewNamespaceScheme>(
490
585
  "hasNewNamespaceScheme"),
package/src/index.d.ts CHANGED
@@ -66,7 +66,7 @@ export class StringItem {
66
66
  mimeType: string,
67
67
  title: string,
68
68
  hint: Hint,
69
- content: ArrayBuffer | Buffer | string
69
+ content: ArrayBuffer | Buffer | string,
70
70
  );
71
71
  readonly path: string;
72
72
  readonly title: string;
@@ -81,7 +81,7 @@ export class FileItem {
81
81
  mimeType: string,
82
82
  title: string,
83
83
  hints: Hint,
84
- filePath: string
84
+ filePath: string,
85
85
  );
86
86
  readonly path: string;
87
87
  readonly title: string;
@@ -102,14 +102,14 @@ export class Creator {
102
102
  addMetadata(
103
103
  name: string,
104
104
  content: string | ContentProvider,
105
- mimetype?: string
105
+ mimetype?: string,
106
106
  ): void;
107
107
  addIllustration(size: number, content: string | ContentProvider): void;
108
108
  addRedirection(
109
109
  path: string,
110
110
  title: string,
111
111
  targetPath: string,
112
- hints?: Hint
112
+ hints?: Hint,
113
113
  ): void;
114
114
  setMainPath(mainPath: string): void;
115
115
  setUuid(uuid: string): void;
@@ -182,6 +182,14 @@ export class Archive {
182
182
  checkIntegrity(checkType: symbol): boolean; // one of IntegrityCheck
183
183
  get isMultiPart(): boolean;
184
184
  get hasNewNamespaceScheme(): boolean;
185
+ getClusterCacheMaxSize(): number;
186
+ getClusterCacheCurrentSize(): number;
187
+ setClusterCacheMaxSize(nbClusters: number): void;
188
+ getDirentCacheMaxSize(): number;
189
+ getDirentCacheCurrentSize(): number;
190
+ setDirentCacheMaxSize(nbDirents: number): void;
191
+ getDirentLookupCacheMaxSize(): number;
192
+ setDirentLookupCacheMaxSize(nbRanges: number): void;
185
193
 
186
194
  static validate(zimPath: string, checksToRun: symbol[]): boolean; // list of IntegrityCheck
187
195
  }