mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-02 14:49:16 +02:00
Update open to handle base64
This commit is contained in:
parent
ba3eec0885
commit
c99bfd07b7
7 changed files with 47 additions and 29 deletions
|
@ -3,7 +3,8 @@
|
|||
"version": "0.3.1",
|
||||
"description": "Parse and Render Epubs",
|
||||
"main": "lib/index.js",
|
||||
"jsnext:main" : "src/index.js",
|
||||
"jsnext:main": "src/index.js",
|
||||
"module": "src/index.js",
|
||||
"repository": "https://github.com/futurepress/epub.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
|
@ -11,6 +12,7 @@
|
|||
"scripts": {
|
||||
"test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS",
|
||||
"documentation": "./node_modules/.bin/gulp docs",
|
||||
"lint": "./node_modules/.bin/eslint -c .eslintrc.js src; exit 0",
|
||||
"start": "webpack-dev-server --inline --d",
|
||||
"build": "webpack --progress",
|
||||
"minify": "NODE_ENV=production webpack --progress",
|
||||
|
@ -31,6 +33,7 @@
|
|||
"babili-webpack-plugin": "0.0.7",
|
||||
"colors": "^1.1.2",
|
||||
"connect": "^3.0.1",
|
||||
"eslint": "^3.11.1",
|
||||
"express": "^4.5.1",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-concat": "^2.3.4",
|
||||
|
|
|
@ -8,6 +8,7 @@ import Path from './utils/path';
|
|||
* @class
|
||||
*/
|
||||
class Archive {
|
||||
|
||||
constructor() {
|
||||
this.zip = undefined;
|
||||
this.checkRequirements();
|
||||
|
@ -22,7 +23,7 @@ class Archive {
|
|||
checkRequirements(){
|
||||
try {
|
||||
if (typeof JSZip === 'undefined') {
|
||||
JSZip = require('jszip');
|
||||
let JSZip = require('jszip');
|
||||
}
|
||||
this.zip = new JSZip();
|
||||
} catch (e) {
|
||||
|
|
10
src/book.js
10
src/book.js
|
@ -165,6 +165,10 @@ class Book {
|
|||
this.archived = true;
|
||||
this.url = new Url("/", "");
|
||||
opening = this.openEpub(input);
|
||||
} else if (type === "base64") {
|
||||
this.archived = true;
|
||||
this.url = new Url("/", "");
|
||||
opening = this.openEpub(input, type);
|
||||
} else if (type === "epub") {
|
||||
this.archived = true;
|
||||
this.url = new Url("/", "");
|
||||
|
@ -282,7 +286,11 @@ class Book {
|
|||
var path;
|
||||
var extension;
|
||||
|
||||
if (typeof(input) != "string") {
|
||||
if (this.settings.encoding === "base64") {
|
||||
return "base64";
|
||||
}
|
||||
|
||||
if(typeof(input) != "string") {
|
||||
return "binary";
|
||||
}
|
||||
|
||||
|
|
|
@ -105,11 +105,14 @@ class Section {
|
|||
this.load(_request).
|
||||
then(function(contents){
|
||||
var serializer;
|
||||
var Serializer;
|
||||
|
||||
if (typeof XMLSerializer === "undefined") {
|
||||
XMLSerializer = require('xmldom').XMLSerializer;
|
||||
Serializer = require('xmldom').XMLSerializer;
|
||||
} else {
|
||||
Serializer = XMLSerializer;
|
||||
}
|
||||
serializer = new XMLSerializer();
|
||||
serializer = new Serializer();
|
||||
this.output = serializer.serializeToString(contents);
|
||||
return this.output;
|
||||
}.bind(this)).
|
||||
|
|
|
@ -295,13 +295,16 @@ export function type(obj){
|
|||
|
||||
export function parse(markup, mime, forceXMLDom) {
|
||||
var doc;
|
||||
var Parser;
|
||||
|
||||
if (typeof DOMParser === "undefined" || forceXMLDom) {
|
||||
DOMParser = require('xmldom').DOMParser;
|
||||
Parser = require('xmldom').DOMParser;
|
||||
} else {
|
||||
Parser = DOMParser;
|
||||
}
|
||||
|
||||
|
||||
doc = new DOMParser().parseFromString(markup, mime);
|
||||
doc = new Parser().parseFromString(markup, mime);
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
@ -446,10 +449,10 @@ export function defer() {
|
|||
/* A newly created Pomise object.
|
||||
* Initially in pending state.
|
||||
*/
|
||||
this.promise = new Promise(function(resolve, reject) {
|
||||
this.promise = new Promise((resolve, reject) => {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
}.bind(this));
|
||||
});
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import path from 'path-webpack';
|
||||
import path from "path-webpack";
|
||||
|
||||
class Path {
|
||||
constructor(pathString) {
|
||||
var protocol;
|
||||
var parsed;
|
||||
|
||||
protocol = pathString.indexOf('://');
|
||||
protocol = pathString.indexOf("://");
|
||||
if (protocol > -1) {
|
||||
pathString = new URL(pathString).pathname;
|
||||
}
|
||||
|
@ -27,31 +27,31 @@ class Path {
|
|||
|
||||
parse (what) {
|
||||
return path.parse(what);
|
||||
};
|
||||
}
|
||||
|
||||
isAbsolute (what) {
|
||||
return path.isAbsolute(what || this.path);
|
||||
};
|
||||
}
|
||||
|
||||
isDirectory (what) {
|
||||
return (what.charAt(what.length-1) === '/');
|
||||
};
|
||||
return (what.charAt(what.length-1) === "/");
|
||||
}
|
||||
|
||||
resolve (what) {
|
||||
return path.resolve(this.directory, what);
|
||||
};
|
||||
}
|
||||
|
||||
relative (what) {
|
||||
return path.relative(this.directory, what);
|
||||
};
|
||||
}
|
||||
|
||||
splitPath(filename) {
|
||||
return this.splitPathRe.exec(filename).slice(1);
|
||||
};
|
||||
}
|
||||
|
||||
toString () {
|
||||
return this.path;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default Path
|
||||
export default Path;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Path from './path'
|
||||
import path from 'path-webpack';
|
||||
import Path from "./path"
|
||||
import path from "path-webpack";
|
||||
|
||||
/**
|
||||
* creates a uri object
|
||||
|
@ -11,7 +11,7 @@ import path from 'path-webpack';
|
|||
|
||||
class Url {
|
||||
constructor(urlString, baseString) {
|
||||
var absolute = (urlString.indexOf('://') > -1);
|
||||
var absolute = (urlString.indexOf("://") > -1);
|
||||
var pathname = urlString;
|
||||
|
||||
this.Url = undefined;
|
||||
|
@ -57,10 +57,10 @@ class Url {
|
|||
|
||||
path () {
|
||||
return this.Path;
|
||||
};
|
||||
}
|
||||
|
||||
resolve (what) {
|
||||
var isAbsolute = (what.indexOf('://') > -1);
|
||||
var isAbsolute = (what.indexOf("://") > -1);
|
||||
var fullpath;
|
||||
|
||||
if (isAbsolute) {
|
||||
|
@ -69,15 +69,15 @@ class Url {
|
|||
|
||||
fullpath = path.resolve(this.directory, what);
|
||||
return this.origin + fullpath;
|
||||
};
|
||||
}
|
||||
|
||||
relative (what) {
|
||||
return path.relative(what, this.directory);
|
||||
};
|
||||
}
|
||||
|
||||
toString () {
|
||||
return this.href;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default Url
|
||||
export default Url;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue