Skip to content

Commit

Permalink
Add hasDRM() and update typings (#44)
Browse files Browse the repository at this point in the history
* add drm detector and update types

* fix declaration file

* fix declaration again
  • Loading branch information
xavdid authored and julien-c committed Nov 4, 2019
1 parent d117153 commit 9571357
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 34 deletions.
94 changes: 60 additions & 34 deletions epub.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Definitions by: Julien Chaumond <https://github.com/julien-c>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference path="../node/node.d.ts" />
/// <reference types="node" />

/**
* new EPub(fname[, imageroot][, linkroot])
Expand All @@ -30,37 +30,63 @@
*
* /images/logo_img/OPT/logo.jpg
**/
declare module "epub" {

import {EventEmitter} from "events";

interface TocElement {
level: number;
order: number;
title: string;
id: string;
href?: string;
}

class EPub extends EventEmitter {
constructor(epubfile: string, imagewebroot?: string, chapterwebroot?: string);

metadata: Object;
manifest: Object;
spine: Object;
flow: Array<Object>;
toc: Array<TocElement>;

parse(): void;

getChapter(chapterId: string, callback: (error: Error, text: string) => void): void;

getChapterRaw(chapterId: string, callback: (error: Error, text: string) => void): void;

getImage(id: string, callback: (error: Error, data: Buffer, mimeType: string) => void): void;

getFile(id: string, callback: (error: Error, data: Buffer, mimeType: string) => void): void;
}

export = EPub;
import { EventEmitter } from 'events'

declare class EPub extends EventEmitter {
constructor(epubfile: string, imagewebroot?: string, chapterwebroot?: string)

metadata: EPub.Metadata
manifest: Object
spine: {
toc: { href: string; id: string }
contents: Array<EPub.TocElement>
}
flow: Array<EPub.TocElement>
toc: Array<EPub.TocElement>

parse(): void

getChapter(
chapterId: string,
callback: (error: Error, text: string) => void
): void

getChapterRaw(
chapterId: string,
callback: (error: Error, text: string) => void
): void

getImage(
id: string,
callback: (error: Error, data: Buffer, mimeType: string) => void
): void

getFile(
id: string,
callback: (error: Error, data: Buffer, mimeType: string) => void
): void

hasDRM(): boolean
}

export = EPub

declare namespace EPub {
export interface TocElement {
level: number
order: number
title: string
id: string
href: string
}

export interface Metadata {
creator: string
creatorFileAs: string
title: string
language: string
subject: string
date: string
description: string
}
}
10 changes: 10 additions & 0 deletions epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,16 @@ class EPub extends EventEmitter {
}
};

/**
* EPub#hasDRM() -> boolean
*
* Parses the tree to see if there's an ecnryption file, signifying the presence of DRM
* see: https://stackoverflow.com/questions/14442968/how-to-check-if-an-epub-file-is-drm-protected
**/
hasDRM () {
const drmFile = 'META-INF/encryption.xml';
return this.zip.names.includes(drmFile);
};
}

// Expose to the world
Expand Down

0 comments on commit 9571357

Please sign in to comment.