https://github.com/openzim/node-libzim
Libzim binding for Node.js: read/write ZIM files in Javascript
https://github.com/openzim/node-libzim
binding cpp library nodejs offline openzim webscraping zim
Last synced: 10 months ago
JSON representation
Libzim binding for Node.js: read/write ZIM files in Javascript
- Host: GitHub
- URL: https://github.com/openzim/node-libzim
- Owner: openzim
- License: gpl-3.0
- Created: 2016-06-21T08:36:02.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-22T17:44:10.000Z (about 1 year ago)
- Last Synced: 2025-04-04T16:50:30.449Z (10 months ago)
- Topics: binding, cpp, library, nodejs, offline, openzim, webscraping, zim
- Language: C++
- Homepage: https://www.npmjs.com/package/@openzim/libzim
- Size: 1020 KB
- Stars: 27
- Watchers: 7
- Forks: 11
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
node-libzim
===========
This is the Node.js binding to the
[libzim](https://github.com/openzim/libzim/). Read and write
[ZIM](https://openzim.org) files easily in Javascript.
[](https://www.npmjs.com/package/@openzim/libzim)
[](https://github.com/openzim/node-libzim/actions/workflows/ci.yml?query=branch%3Amain)
[](https://codecov.io/gh/openzim/node-libzim)
[](https://www.codefactor.io/repository/github/openzim/node-libzim)
[](https://www.gnu.org/licenses/gpl-3.0)
[](https://slack.kiwix.org)
## Dependencies
This package relies on [node-addon-api](https://github.com/nodejs/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](https://github.com/openzim/libzim/)).
## Usage
```bash
npm i @openzim/libzim
```
### Writing a ZIM file
```javascript
// 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
`
Content / Data ${i}
` // content
);
await creator.addItem(item);
}
creator.setMainPath("file0");
await creator.finishZimCreation();
console.log('Done Writing');
})();
```
### Reading a ZIM file
```javascript
// 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](https://www.gnu.org/licenses/gpl-3.0) or later, see
[LICENSE](LICENSE) for more details.