Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated README with additional instructions for loading ZIM files and articles #60

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,68 @@ Library for accessing [libkiwix](https://github.com/kiwix/libkiwix) and [libzim]

AAR file will be generated in directory `lib/build/outputs/aar`

### Load zim file

To load a ZIM file you need to create an `Archive` object.

```kotlin
val archive = Archive("your-file-path")
```

### Load main page

The `mainPage` property is used to retrieve the path of the main entry page for a Kiwix content archive.
If the main entry is a redirect, it will fetch the path of the redirected item;
otherwise, it will return the path of the main entry itself.
If the main entry is not found, the archive will throw an `EntryNotFoundException`.

```kotlin
val mainPage: String?
get() =
try {
archive.mainEntry.getItem(true).path
} catch (entryNotFoundException: EntryNotFoundException) {
// Return `null` if the main entry is not present in the archive.
null
} catch (exception: Exception) {
MohitMaliFtechiz marked this conversation as resolved.
Show resolved Hide resolved
// Other exception will thrown here e.g. the file is corrupted or any other error happened.
null
}
```

### Load an article via title

```kotlin
try {
// If the article with the specified title exists in the archive,
// retrieve its path using the `getEntryByTitle` method.
archive.getEntryByTitle(title).path
} catch (entryNotFoundException: EntryNotFoundException) {
// If the article with the specified title does not exist in the archive,
// return `null`.
null
}
```

### Load an Article via Path

Ensure that the URL path is properly decode before passing it to `hasEntryByPath`,
as `Libzim` does not support encoded URLs.

```kotlin
val decodedPath = URLDecoder.decode(actualpath, "UTF-8")
try {
// If the article with the specified URL exists in the archive,
// retrieve its actual path using the `getEntryByPath` method.
archive.getEntryByPath(decodedPath)
.getItem(true)
.path
} catch (entryNotFoundException: EntryNotFoundException) {
// If the article with the specified URL does not exist in the archive,
// return `null`.
null
}
```

# License

Expand Down
Loading