mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-23 04:28:30 -04:00
It happens that bzip2 decompression fails with "No magic number found". It's known bug, not yet solved. When this happens, we should not ask the user to report it, but instead invite him to see the corresponding issue on Github. Fixes #77
+ slightly improve the way we report other decompression errors to the user
This commit is contained in:
parent
4cb3486cd7
commit
75c7c8a218
@ -499,6 +499,7 @@ define(function(require) {
|
|||||||
/**
|
/**
|
||||||
* Display the the given HTML article in the web page,
|
* Display the the given HTML article in the web page,
|
||||||
* and convert links to javascript calls
|
* and convert links to javascript calls
|
||||||
|
* NB : in some error cases, the given title can be null, and the htmlArticle contains the error message
|
||||||
* @param {type} title
|
* @param {type} title
|
||||||
* @param {type} htmlArticle
|
* @param {type} htmlArticle
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -473,54 +473,53 @@ define(function(require) {
|
|||||||
alert('Data file read cancelled');
|
alert('Data file read cancelled');
|
||||||
};
|
};
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
try {
|
var compressedArticles = e.target.result;
|
||||||
var compressedArticles = e.target.result;
|
webworkerBzip2.onerror = function(event){
|
||||||
webworkerBzip2.onerror = function(event){
|
// TODO can probably be replaced by some error handler at window level
|
||||||
// TODO can probably be replaced by some error handler at window level
|
callbackFunction(null, "An unexpected error occured during bzip2 decompression. Please report it to us by email or through Github (see About section), with the names of the archive and article, and the following info : message="
|
||||||
alert("An unexpected error occured during bzip2 decompression. Please report it to us by email or through Github (see About section), with the names of the archive and article, and the following info : message="
|
+ event.message + " filename=" + event.filename + " line number=" + event.lineno);
|
||||||
+ event.message + " filename=" + event.filename + " line number=" + event.lineno );
|
};
|
||||||
throw new Error("Error during bzip2 decompression : " + event.message + " (" + event.filename + ":" + event.lineno + ")");
|
webworkerBzip2.onmessage = function(event){
|
||||||
};
|
switch (event.data.cmd){
|
||||||
webworkerBzip2.onmessage = function(event){
|
case "result":
|
||||||
switch (event.data.cmd){
|
var htmlArticles = event.data.msg;
|
||||||
case "result":
|
// Start reading at offset, and keep length characters
|
||||||
var htmlArticles = event.data.msg;
|
var htmlArticle = htmlArticles.substring(title._blockOffset,
|
||||||
// Start reading at offset, and keep length characters
|
title._blockOffset + title._articleLength);
|
||||||
var htmlArticle = htmlArticles.substring(title._blockOffset,
|
if (htmlArticle.length >= title._articleLength) {
|
||||||
title._blockOffset + title._articleLength);
|
// Keep only length characters
|
||||||
if (htmlArticle.length >= title._articleLength) {
|
htmlArticle = htmlArticle.substring(0, title._articleLength);
|
||||||
// Keep only length characters
|
// Decode UTF-8 encoding
|
||||||
htmlArticle = htmlArticle.substring(0, title._articleLength);
|
htmlArticle = decodeURIComponent(escape(htmlArticle));
|
||||||
// Decode UTF-8 encoding
|
callbackFunction(title, htmlArticle);
|
||||||
htmlArticle = decodeURIComponent(escape(htmlArticle));
|
} else {
|
||||||
callbackFunction(title, htmlArticle);
|
// TODO : throw exception if we reach the end of the file
|
||||||
} else {
|
currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE,
|
||||||
// TODO : throw exception if we reach the end of the file
|
callbackFunction);
|
||||||
currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE,
|
}
|
||||||
callbackFunction);
|
break;
|
||||||
}
|
case "recurse":
|
||||||
break;
|
currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, callbackFunction);
|
||||||
case "recurse":
|
break;
|
||||||
currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, callbackFunction);
|
case "debug":
|
||||||
break;
|
console.log(event.data.msg);
|
||||||
case "debug":
|
break;
|
||||||
console.log(event.data.msg);
|
case "error":
|
||||||
break;
|
// TODO can probably be replaced by some error handler at window level
|
||||||
case "error":
|
if (event.data.msg === "No magic number found") {
|
||||||
// TODO can probably be replaced by some error handler at window level
|
// See https://github.com/mossroy/evopedia-html5/issues/77
|
||||||
alert("An unexpected error occured during bzip2 decompression. Please report it to us by email or through Github (see About section), with the names of the archive and article, and the following info : message="
|
// It's a temporary workaround until https://github.com/mossroy/evopedia-html5/issues/6 is fixed
|
||||||
+ event.data.msg );
|
callbackFunction(null, "Oops : this article can not be displayed for now. It's a known bug that is not solved yet. See <a href='https://github.com/mossroy/evopedia-html5/issues/6' target='_blank'>issue #6 on Github</a> for more info");
|
||||||
throw new Error("Error during bzip2 decompression : " + event.data.msg);
|
}
|
||||||
break;
|
else {
|
||||||
}
|
callbackFunction(null, "An unexpected error occured during bzip2 decompression. Please report it to us by email or through Github (see About section), with the names of the archive and article, and the following info : message="
|
||||||
};
|
+ event.data.msg);
|
||||||
webworkerBzip2.postMessage({cmd : 'uncompress', msg :
|
}
|
||||||
new Uint8Array(compressedArticles)});
|
break;
|
||||||
|
}
|
||||||
}
|
};
|
||||||
catch (e) {
|
webworkerBzip2.postMessage({cmd : 'uncompress', msg :
|
||||||
callbackFunction("Error : " + e);
|
new Uint8Array(compressedArticles)});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
var blob = dataFile.slice(title._blockStart, title._blockStart
|
var blob = dataFile.slice(title._blockStart, title._blockStart
|
||||||
+ readLength);
|
+ readLength);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user