mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 09:39:16 +02:00
Add factory method to archive.js that returns an Unrarrer/Unzipper/Untarrer
This commit is contained in:
parent
e23674f5e2
commit
9305f4e11b
1 changed files with 21 additions and 0 deletions
21
archive.js
21
archive.js
|
@ -350,4 +350,25 @@ bitjs.archive.Untarrer = function(arrayBuffer, opt_pathToBitJS) {
|
|||
bitjs.inherits(bitjs.archive.Untarrer, bitjs.archive.Unarchiver);
|
||||
bitjs.archive.Untarrer.prototype.getScriptFileName = function() { return 'untar.js' };
|
||||
|
||||
/**
|
||||
* Factory method that creates an unarchiver based on the byte signature found
|
||||
* in the arrayBuffer.
|
||||
* @param {ArrayBuffer} ab
|
||||
* @param {string=} opt_pathToBitJS Path to the unarchiver script files.
|
||||
* @return {bitjs.archive.Unarchiver}
|
||||
*/
|
||||
bitjs.archive.GetUnarchiver = function(ab, opt_pathToBitJS) {
|
||||
var unarchiver = null;
|
||||
var pathToBitJS = opt_pathToBitJS || '';
|
||||
var h = new Uint8Array(ab, 0, 10);
|
||||
if (h[0] == 0x52 && h[1] == 0x61 && h[2] == 0x72 && h[3] == 0x21) { //Rar!
|
||||
unarchiver = new bitjs.archive.Unrarrer(ab, pathToBitJS);
|
||||
} else if (h[0] == 80 && h[1] == 75) { // PK (Zip)
|
||||
unarchiver = new bitjs.archive.Unzipper(ab, pathToBitJS);
|
||||
} else { // Try with tar
|
||||
unarchiver = new bitjs.archive.Untarrer(ab, pathToBitJS);
|
||||
}
|
||||
return unarchiver;
|
||||
};
|
||||
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue