1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

replaced zip.js with JSZip

This commit is contained in:
Fred Chasen 2014-12-05 16:11:58 -05:00
parent eca5ffbeff
commit cdbe2758bc
35 changed files with 9166 additions and 8257 deletions

File diff suppressed because one or more lines are too long

71
reader/js/epub.min.js vendored
View file

@ -3838,6 +3838,10 @@ EPUBJS.core.request = function(url, type, withCredentials) {
if(type == 'xml') {
xhr.overrideMimeType('text/xml');
}
if(type == "binary") {
xhr.responseType = "arraybuffer";
}
xhr.send();
@ -7329,43 +7333,26 @@ EPUBJS.replace.cssUrls = function(_store, base, text){
return deferred.promise;
};
EPUBJS.Unarchiver = function(url){
this.libPath = EPUBJS.filePath;
this.zipUrl = url;
this.loadLib();
this.urlCache = {};
this.zipFs = new zip.fs.FS();
return this.promise;
};
//-- Load the zip lib and set the workerScriptsPath
EPUBJS.Unarchiver.prototype.loadLib = function(callback){
if(typeof(zip) == "undefined") console.error("Zip lib not loaded");
/*
//-- load script
EPUBJS.core.loadScript(this.libPath+"zip.js", function(){
//-- Tell zip where it is located
zip.workerScriptsPath = this.libPath;
callback();
}.bind(this));
*/
// console.log(this.libPath)
zip.workerScriptsPath = this.libPath;
if(typeof(JSZip) == "undefined") console.error("JSZip lib not loaded");
};
EPUBJS.Unarchiver.prototype.openZip = function(zipUrl, callback){
var deferred = new RSVP.defer();
var zipFs = this.zipFs;
zipFs.importHttpContent(zipUrl, false, function() {
deferred.resolve(zipFs);
}, this.failed);
return deferred.promise;
return EPUBJS.core.request(zipUrl, "binary").then(function(data){
this.zip = new JSZip(data);
}.bind(this));
};
EPUBJS.Unarchiver.prototype.getXml = function(url, encoding){
@ -7382,9 +7369,10 @@ EPUBJS.Unarchiver.prototype.getUrl = function(url, mime){
var unarchiver = this;
var deferred = new RSVP.defer();
var decodededUrl = window.decodeURIComponent(url);
var entry = this.zipFs.find(decodededUrl);
var entry = this.zip.file(decodededUrl);
var _URL = window.URL || window.webkitURL || window.mozURL;
var tempUrl;
if(!entry) {
deferred.reject({
message : "File not found in the epub: " + url,
@ -7398,11 +7386,11 @@ EPUBJS.Unarchiver.prototype.getUrl = function(url, mime){
return deferred.promise;
}
entry.getBlob(mime || zip.getMimeType(entry.name), function(blob){
var tempUrl = _URL.createObjectURL(blob);
deferred.resolve(tempUrl);
unarchiver.urlCache[url] = tempUrl;
});
blob = new Blob([entry.asUint8Array()], {type : mime || this.zip.getMimeType(entry.name)});
tempUrl = _URL.createObjectURL(blob);
deferred.resolve(tempUrl);
unarchiver.urlCache[url] = tempUrl;
return deferred.promise;
};
@ -7411,7 +7399,7 @@ EPUBJS.Unarchiver.prototype.getText = function(url, encoding){
var unarchiver = this;
var deferred = new RSVP.defer();
var decodededUrl = window.decodeURIComponent(url);
var entry = this.zipFs.find(decodededUrl);
var entry = this.zip.file(decodededUrl);
var _URL = window.URL || window.webkitURL || window.mozURL;
if(!entry) {
@ -7419,9 +7407,8 @@ EPUBJS.Unarchiver.prototype.getText = function(url, encoding){
return deferred.promise;
}
entry.getText(function(text){
deferred.resolve(text);
}, null, null, encoding || 'UTF-8');
text = entry.asText();
deferred.resolve(text);
return deferred.promise;
};
@ -7465,11 +7452,11 @@ EPUBJS.Unarchiver.prototype.toStorage = function(entries){
//entries.forEach(this.saveEntryFileToStorage.bind(this));
};
EPUBJS.Unarchiver.prototype.saveEntryFileToStorage = function(entry, callback){
var that = this;
entry.getData(new zip.BlobWriter(), function(blob) {
EPUBJS.storage.save(entry.filename, blob, callback);
});
};
// EPUBJS.Unarchiver.prototype.saveEntryFileToStorage = function(entry, callback){
// var that = this;
// entry.getData(new zip.BlobWriter(), function(blob) {
// EPUBJS.storage.save(entry.filename, blob, callback);
// });
// };
//# sourceMappingURL=epub.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long