0.2.0 • Published 9 months ago

booqs-epub v0.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

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)
}
0.2.0

9 months ago

0.1.0

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago