GithubHelp home page GithubHelp logo

rishabhg71 / node-libzim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openzim/node-libzim

0.0 0.0 0.0 1.07 MB

Binding to libzim, read/write ZIM files in Javascript

Home Page: https://www.npmjs.com/package/@openzim/libzim

License: GNU General Public License v3.0

Shell 1.02% JavaScript 3.98% C++ 80.74% Python 1.68% TypeScript 12.59%

node-libzim's Introduction

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.

node-libzim's People

Contributors

isnit0 avatar kelson42 avatar kelvinhammond avatar cscott avatar midik avatar dependabot[bot] avatar rishabhg71 avatar bakshiutkarsha avatar fledgexu avatar mananjethwani avatar miniland1333 avatar rgaudin avatar snyk-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.