forked from edsilv/epub.js
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontainer.js
50 lines (41 loc) · 1.06 KB
/
container.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import path from "path-webpack";
import {qs} from "./utils/core";
/**
* Handles Parsing and Accessing an Epub Container
* @class
* @param {document} [containerDocument] xml document
*/
class Container {
constructor(containerDocument) {
this.packagePath = '';
this.directory = '';
this.encoding = '';
if (containerDocument) {
this.parse(containerDocument);
}
}
/**
* Parse the Container XML
* @param {document} containerDocument
*/
parse(containerDocument){
//-- <rootfile full-path="OPS/package.opf" media-type="application/oebps-package+xml"/>
var rootfile;
if(!containerDocument) {
throw new Error("Container File Not Found");
}
rootfile = qs(containerDocument, "rootfile");
if(!rootfile) {
throw new Error("No RootFile Found");
}
this.packagePath = rootfile.getAttribute("full-path");
this.directory = path.dirname(this.packagePath);
this.encoding = containerDocument.xmlEncoding;
}
destroy() {
this.packagePath = undefined;
this.directory = undefined;
this.encoding = undefined;
}
}
export default Container;