Coder Social home page Coder Social logo

kelvinhammond / node-libzim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openzim/node-libzim

0.0 1.0 0.0 924 KB

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

Python 1.72% JavaScript 3.01% C++ 82.06% TypeScript 12.08% Shell 1.14%

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
const { ZimArticle, ZimCreator } = require("@openzim/libzim");

(async () => {

    console.info('Starting');
    const creator = new ZimCreator({ fileName: 'test.zim' }, { welcome: 'index.html' });

    for (let i = 100; i > 0; i--) {
        const a = new ZimArticle({ url: `file${i}`, data: `Content ${i}` });
        await creator.addArticle(a);
    }

    const welcome = new ZimArticle({ url: `index.html`, data: `<h1>Welcome!</h1>` });
    await creator.addArticle(welcome);

    await creator.finalise();

    console.log('Done Writing');

})();

Reading a Zim file

// read.js

const { ZimArticle, ZimReader } = require("@openzim/libzim");

(async () => {

    const zimFile = new ZimReader(path.join(__dirname, '../test.zim'));

    const suggestResults = await zimFile.suggest('laborum');
    console.info(`Suggest Results:`, suggestResults);

    const searchResults = await zimFile.search('rem');
    console.info(`Search Results:`, searchResults);

    const readArticleContent = await zimFile.getArticleByUrl('A/laborum');
    console.info(`Article by url (laborum):`, readArticleContent);

    await zimFile.destroy();

})();

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 bakshiutkarsha avatar mananjethwani avatar miniland1333 avatar rgaudin avatar snyk-bot avatar

Watchers

James Cloos 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.