mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
added loading from zipped epub file
This commit is contained in:
parent
2ddae3a024
commit
1e592badd1
13 changed files with 288 additions and 57 deletions
77
fpjs/render/unarchiver.js
Normal file
77
fpjs/render/unarchiver.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
FP.Unarchiver = function(url, callback){
|
||||
this.libPath = "fpjs/libs/";
|
||||
this.zipUrl = url;
|
||||
this.callback = callback;
|
||||
this.loadLib(function(){
|
||||
this.getZip(this.zipUrl);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
FP.Unarchiver.prototype.loadLib = function(callback){
|
||||
if(typeof(zip) != "undefined") callback();
|
||||
//-- load script
|
||||
FP.core.loadScript(this.libPath+"zip.js", function(){
|
||||
//-- Tell zip where it is located
|
||||
zip.workerScriptsPath = this.libPath;
|
||||
callback();
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
FP.Unarchiver.prototype.getZip = function(zipUrl){
|
||||
var xhr = new FP.core.loadFile(zipUrl);
|
||||
|
||||
xhr.succeeded = function(file) {
|
||||
this.getEntries(file, this.toStorage.bind(this));
|
||||
}.bind(this);
|
||||
|
||||
xhr.failed = this.failed;
|
||||
|
||||
xhr.start();
|
||||
|
||||
}
|
||||
|
||||
FP.Unarchiver.prototype.getEntries = function(file, callback){
|
||||
zip.createReader(new zip.BlobReader(file), function(zipReader) {
|
||||
zipReader.getEntries(callback);
|
||||
}, this.failed);
|
||||
}
|
||||
|
||||
FP.Unarchiver.prototype.failed = function(error){
|
||||
console.log("Error:", error);
|
||||
}
|
||||
|
||||
FP.Unarchiver.prototype.afterSaved = function(error){
|
||||
this.callback();
|
||||
}
|
||||
|
||||
FP.Unarchiver.prototype.toStorage = function(entries){
|
||||
var timeout = 0,
|
||||
delay = 20,
|
||||
that = this,
|
||||
count = entries.length;
|
||||
|
||||
function callback(){
|
||||
count--;
|
||||
if(count == 0) that.afterSaved();
|
||||
}
|
||||
|
||||
entries.forEach(function(entry){
|
||||
|
||||
setTimeout(function(entry){
|
||||
that.saveEntryFileToStorage(entry, callback);
|
||||
}, timeout, entry);
|
||||
|
||||
timeout += delay;
|
||||
});
|
||||
|
||||
console.log("time", timeout);
|
||||
|
||||
//entries.forEach(this.saveEntryFileToStorage.bind(this));
|
||||
}
|
||||
|
||||
FP.Unarchiver.prototype.saveEntryFileToStorage = function(entry, callback){
|
||||
var that = this;
|
||||
entry.getData(new zip.BlobWriter(), function(blob) {
|
||||
FP.storage.save(entry.filename, blob, callback);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue