1
0
Fork 0
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:
Fred Chasen 2016-12-07 22:14:29 +01:00
parent ba3eec0885
commit c99bfd07b7
7 changed files with 47 additions and 29 deletions

View file

@ -3,7 +3,8 @@
"version": "0.3.1", "version": "0.3.1",
"description": "Parse and Render Epubs", "description": "Parse and Render Epubs",
"main": "lib/index.js", "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", "repository": "https://github.com/futurepress/epub.js",
"directories": { "directories": {
"test": "test" "test": "test"
@ -11,6 +12,7 @@
"scripts": { "scripts": {
"test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS", "test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS",
"documentation": "./node_modules/.bin/gulp docs", "documentation": "./node_modules/.bin/gulp docs",
"lint": "./node_modules/.bin/eslint -c .eslintrc.js src; exit 0",
"start": "webpack-dev-server --inline --d", "start": "webpack-dev-server --inline --d",
"build": "webpack --progress", "build": "webpack --progress",
"minify": "NODE_ENV=production webpack --progress", "minify": "NODE_ENV=production webpack --progress",
@ -31,6 +33,7 @@
"babili-webpack-plugin": "0.0.7", "babili-webpack-plugin": "0.0.7",
"colors": "^1.1.2", "colors": "^1.1.2",
"connect": "^3.0.1", "connect": "^3.0.1",
"eslint": "^3.11.1",
"express": "^4.5.1", "express": "^4.5.1",
"gulp": "^3.9.0", "gulp": "^3.9.0",
"gulp-concat": "^2.3.4", "gulp-concat": "^2.3.4",

View file

@ -8,6 +8,7 @@ import Path from './utils/path';
* @class * @class
*/ */
class Archive { class Archive {
constructor() { constructor() {
this.zip = undefined; this.zip = undefined;
this.checkRequirements(); this.checkRequirements();
@ -22,7 +23,7 @@ class Archive {
checkRequirements(){ checkRequirements(){
try { try {
if (typeof JSZip === 'undefined') { if (typeof JSZip === 'undefined') {
JSZip = require('jszip'); let JSZip = require('jszip');
} }
this.zip = new JSZip(); this.zip = new JSZip();
} catch (e) { } catch (e) {

View file

@ -165,6 +165,10 @@ class Book {
this.archived = true; this.archived = true;
this.url = new Url("/", ""); this.url = new Url("/", "");
opening = this.openEpub(input); opening = this.openEpub(input);
} else if (type === "base64") {
this.archived = true;
this.url = new Url("/", "");
opening = this.openEpub(input, type);
} else if (type === "epub") { } else if (type === "epub") {
this.archived = true; this.archived = true;
this.url = new Url("/", ""); this.url = new Url("/", "");
@ -282,7 +286,11 @@ class Book {
var path; var path;
var extension; var extension;
if (typeof(input) != "string") { if (this.settings.encoding === "base64") {
return "base64";
}
if(typeof(input) != "string") {
return "binary"; return "binary";
} }

View file

@ -105,11 +105,14 @@ class Section {
this.load(_request). this.load(_request).
then(function(contents){ then(function(contents){
var serializer; var serializer;
var Serializer;
if (typeof XMLSerializer === "undefined") { 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); this.output = serializer.serializeToString(contents);
return this.output; return this.output;
}.bind(this)). }.bind(this)).

View file

@ -295,13 +295,16 @@ export function type(obj){
export function parse(markup, mime, forceXMLDom) { export function parse(markup, mime, forceXMLDom) {
var doc; var doc;
var Parser;
if (typeof DOMParser === "undefined" || forceXMLDom) { 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; return doc;
} }
@ -446,10 +449,10 @@ export function defer() {
/* A newly created Pomise object. /* A newly created Pomise object.
* Initially in pending state. * Initially in pending state.
*/ */
this.promise = new Promise(function(resolve, reject) { this.promise = new Promise((resolve, reject) => {
this.resolve = resolve; this.resolve = resolve;
this.reject = reject; this.reject = reject;
}.bind(this)); });
Object.freeze(this); Object.freeze(this);
} }

View file

@ -1,11 +1,11 @@
import path from 'path-webpack'; import path from "path-webpack";
class Path { class Path {
constructor(pathString) { constructor(pathString) {
var protocol; var protocol;
var parsed; var parsed;
protocol = pathString.indexOf('://'); protocol = pathString.indexOf("://");
if (protocol > -1) { if (protocol > -1) {
pathString = new URL(pathString).pathname; pathString = new URL(pathString).pathname;
} }
@ -27,31 +27,31 @@ class Path {
parse (what) { parse (what) {
return path.parse(what); return path.parse(what);
}; }
isAbsolute (what) { isAbsolute (what) {
return path.isAbsolute(what || this.path); return path.isAbsolute(what || this.path);
}; }
isDirectory (what) { isDirectory (what) {
return (what.charAt(what.length-1) === '/'); return (what.charAt(what.length-1) === "/");
}; }
resolve (what) { resolve (what) {
return path.resolve(this.directory, what); return path.resolve(this.directory, what);
}; }
relative (what) { relative (what) {
return path.relative(this.directory, what); return path.relative(this.directory, what);
}; }
splitPath(filename) { splitPath(filename) {
return this.splitPathRe.exec(filename).slice(1); return this.splitPathRe.exec(filename).slice(1);
}; }
toString () { toString () {
return this.path; return this.path;
}; }
} }
export default Path export default Path;

View file

@ -1,5 +1,5 @@
import Path from './path' import Path from "./path"
import path from 'path-webpack'; import path from "path-webpack";
/** /**
* creates a uri object * creates a uri object
@ -11,7 +11,7 @@ import path from 'path-webpack';
class Url { class Url {
constructor(urlString, baseString) { constructor(urlString, baseString) {
var absolute = (urlString.indexOf('://') > -1); var absolute = (urlString.indexOf("://") > -1);
var pathname = urlString; var pathname = urlString;
this.Url = undefined; this.Url = undefined;
@ -57,10 +57,10 @@ class Url {
path () { path () {
return this.Path; return this.Path;
}; }
resolve (what) { resolve (what) {
var isAbsolute = (what.indexOf('://') > -1); var isAbsolute = (what.indexOf("://") > -1);
var fullpath; var fullpath;
if (isAbsolute) { if (isAbsolute) {
@ -69,15 +69,15 @@ class Url {
fullpath = path.resolve(this.directory, what); fullpath = path.resolve(this.directory, what);
return this.origin + fullpath; return this.origin + fullpath;
}; }
relative (what) { relative (what) {
return path.relative(what, this.directory); return path.relative(what, this.directory);
}; }
toString () { toString () {
return this.href; return this.href;
}; }
} }
export default Url export default Url;