3.2.0 • Published 5 months ago

@openzim/libzim v3.2.0

Weekly downloads
158
License
GPL-3.0
Repository
github
Last release
5 months ago

node-libzim

This is the Node.js binding to the libzim. Read and write ZIM files easily in Javascript.

npm Build Status codecov CodeFactor License: GPL v3

Dependencies

This package relies on node-addon-api / n-api.

On GNU/Linux & macOS, the package will download a libzim binary. On other OSes you will need to install libzim separately (see here).

Usage

npm i @openzim/libzim

Writing a ZIM file

// write.js
import { Creator, StringItem } from "@openzim/libzim";

(async () => {
    console.info('Starting');
    const outFile = "./test.zim";
    const creator = new Creator()
        .configNbWorkers(1)
        .configIndexing(true, "en")
        .configClusterSize(2048)
        .startZimCreation(outFile);

    for (let i = 0; i < 100; i++) {
        const item = new StringItem(
            `file${i}`,                       // path url
            "text/plain",                     // content-type
            `Title ${i}`,                     // title
            {FRONT_ARTICLE: 1, COMPRESS: 1},  // hint option flags
            `<h1>Content / Data ${i}</h1>`    // content
        );
        await creator.addItem(item);
    }

    creator.setMainPath("file0");
    await creator.finishZimCreation();

    console.log('Done Writing');
})();

Reading a ZIM file

// read.js
import { Archive, SuggestionSearcher, Searcher } from "@openzim/libzim";

(async () => {
    const outFile = "./test.zim";
    const archive = new Archive(outFile);
    console.log(`Archive opened: main entry path - ${archive.mainEntry.path}`);

    for (const entry of archive.iterByPath()) {
        console.log(`entry: ${entry.path} - ${entry.title}`);
    }

    const suggestionSearcher = new SuggestionSearcher(archive);
    const suggestion = suggestionSearcher.suggest('laborum');
    let results = suggestion.getResults(0, 10);
    console.log("Suggestion results:");
    for(const entry of results) {
        console.log(`\t- ${entry.path} - ${entry.title}`);
    }

    const searcher = new Searcher(archive);
    const search = searcher.search(new Query('rem'));
    results = search.getResults(0, 10);
    console.log("Search results:");
    for(const entry of results) {
        console.log(`\t- ${entry.path} - ${entry.title}`);
    }


    const entry = await archive.getEntryByPath("A/laborum");
    const item = entry.item;
    const blob = item.data;
    console.info(`Entry by url (laborum):`, blob.data);
    delete archive;
})();

License

GPLv3 or later, see LICENSE for more details.

3.2.0

5 months ago

3.1.0

5 months ago

3.0.0

11 months ago

2.4.4

3 years ago

2.4.3

3 years ago

2.4.2

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.3.0

4 years ago

2.2.5

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

5 years ago

2.0.21

5 years ago

2.0.20

5 years ago

2.0.19

5 years ago

2.0.19-rc

5 years ago

2.0.18

5 years ago

2.0.17

5 years ago

2.0.16

5 years ago

2.0.15

5 years ago

2.0.14

5 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago