booqs-epub
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

booqs-epub

This is a simple epub parser. It is somewhat incomplete, though should cover most cases. This package intentionally doesn't take any dependencies on zip libraries. Instead user should provide simple FileProvider as an input to the API. For example, you can create a FileProvider using popular jszip lib and use it like this:

import JSZip from 'jszip'
import fs from 'fs'
import { openEpub, FileProvider } from 'booqs-epub'

function createZipFileProvider(fileContent: Promise<Buffer>): FileProvider {
    let zip = JSZip.loadAsync(fileContent)
    return {
        async readText(path, diags) {
            try {
                const file = (await zip).file(path)
                if (!file) {
                    return undefined
                }
                return file.async('text')
            } catch (e) {
                diags.push({
                    message: `Error reading text ${path}: ${e}`,
                })
                return undefined
            }
        },
        async readBinary(path, diags) {
            try {
                const file = (await zip).file(path)
                if (!file) {
                    return undefined
                }
                return file.async('nodebuffer')
            } catch (e) {
                diags.push({
                    message: `Error reading binary ${path}: ${e}`,
                })
                return undefined
            }
        }
    }
}

export function openEpubAtPath(epubFilePath: string) {
    const fileProvider = createZipFileProvider(fs.promises.readFile(epubFilePath))
    return openEpub(fileProvider)
}

Readme

Keywords

none

Package Sidebar

Install

npm i booqs-epub

Weekly Downloads

0

Version

0.2.0

License

ISC

Unpacked Size

214 kB

Total Files

62

Last publish

Collaborators

  • ashakirzianov