summaryrefslogtreecommitdiff
path: root/lib/epub.js/src/container.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/epub.js/src/container.js')
-rw-r--r--lib/epub.js/src/container.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/epub.js/src/container.js b/lib/epub.js/src/container.js
new file mode 100644
index 0000000..f3a214f
--- /dev/null
+++ b/lib/epub.js/src/container.js
@@ -0,0 +1,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;