@ -79,7 +79,7 @@ var RarVolumeHeader = function(bstream) {
// bytes 4,5
this . flags = { } ;
this . flags . value = bstream . peekBits ( 16 ) ;
info ( " flags=" + twoByteValueToHexString ( this . flags . value ) ) ;
switch ( this . headType ) {
case MAIN _HEAD :
@ -115,7 +115,7 @@ var RarVolumeHeader = function(bstream) {
default :
bstream . readBits ( 16 ) ;
}
// byte 6,7
this . headSize = bstream . readBits ( 16 ) ;
info ( " headSize=" + this . headSize ) ;
@ -212,12 +212,12 @@ var RarVolumeHeader = function(bstream) {
//var BLOCK_LZ = 0;
var rLDecode = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 10 , 12 , 14 , 16 , 20 , 24 , 28 , 32 , 40 , 48 , 56 , 64 , 80 , 96 , 112 , 128 , 160 , 192 , 224 ] ,
var rLDecode = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 10 , 12 , 14 , 16 , 20 , 24 , 28 , 32 , 40 , 48 , 56 , 64 , 80 , 96 , 112 , 128 , 160 , 192 , 224 ] ,
rLBits = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 , 5 , 5 , 5 , 5 ] ,
rDBitLengthCounts = [ 4 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 14 , 0 , 12 ] ,
rSDDecode = [ 0 , 4 , 8 , 16 , 32 , 64 , 128 , 192 ] ,
rSDBits = [ 2 , 2 , 3 , 4 , 5 , 6 , 6 , 6 ] ;
var rDDecode = [ 0 , 1 , 2 , 3 , 4 , 6 , 8 , 12 , 16 , 24 , 32 ,
48 , 64 , 96 , 128 , 192 , 256 , 384 , 512 , 768 , 1024 , 1536 , 2048 , 3072 ,
4096 , 6144 , 8192 , 12288 , 16384 , 24576 , 32768 , 49152 , 65536 , 98304 ,
@ -275,12 +275,12 @@ function rarReadTables(bstream) {
var i ;
// before we start anything we need to get byte-aligned
bstream . readBits ( ( 8 - bstream . bitPtr ) & 0x7 ) ;
if ( bstream . readBits ( 1 ) ) {
info ( "Error! PPM not implemented yet" ) ;
return ;
}
if ( ! bstream . readBits ( 1 ) ) { //discard old table
for ( i = UnpOldTable . length ; i -- ; ) UnpOldTable [ i ] = 0 ;
}
@ -308,7 +308,7 @@ function rarReadTables(bstream) {
// now all 20 bit lengths are obtained, we construct the Huffman Table:
rarMakeDecodeTables ( BitLength , 0 , BD , rBC ) ;
var TableSize = rHuffTableSize ;
//console.log(DecodeLen, DecodePos, DecodeNum);
for ( i = 0 ; i < TableSize ; ) {
@ -332,12 +332,12 @@ function rarReadTables(bstream) {
}
}
}
rarMakeDecodeTables ( Table , 0 , LD , rNC ) ;
rarMakeDecodeTables ( Table , rNC , DD , rDC ) ;
rarMakeDecodeTables ( Table , rNC + rDC , LDD , rLDC ) ;
rarMakeDecodeTables ( Table , rNC + rDC + rLDC , RD , rRC ) ;
for ( i = UnpOldTable . length ; i -- ; ) {
UnpOldTable [ i ] = Table [ i ] ;
}
@ -366,7 +366,7 @@ function rarDecodeNumber(bstream, dec) {
: 15 ) ) ;
bstream . readBits ( bits ) ;
var N = DecodePos [ bits ] + ( ( bitField - DecodeLen [ bits - 1 ] ) >>> ( 16 - bits ) ) ;
return DecodeNum [ N ] ;
}
@ -568,7 +568,7 @@ function Unpack29(bstream) {
DBits [ Slot ] = BitLength ;
}
}
var Bits ;
//tablesRead = false;
@ -578,13 +578,13 @@ function Unpack29(bstream) {
lastLength = 0 ;
var i ;
for ( i = UnpOldTable . length ; i -- ; ) UnpOldTable [ i ] = 0 ;
// read in Huffman tables
rarReadTables ( bstream ) ;
while ( true ) {
var num = rarDecodeNumber ( bstream , LD ) ;
if ( num < 256 ) {
rBuffer . insertByte ( num ) ;
continue ;
@ -675,11 +675,11 @@ function Unpack29(bstream) {
continue ;
}
}
rarUpdateProgress ( )
rarUpdateProgress ( ) ;
}
function rarReadEndOfBlock ( bstream ) {
rarUpdateProgress ( ) ;
var NewTable = false , NewFile = false ;
@ -703,7 +703,7 @@ function rarReadVMCode(bstream) {
Length = bstream . readBits ( 16 ) ;
}
var vmCode = [ ] ;
for ( var I = 0 ; I < Length ; I ++ ) {
for ( var I = 0 ; I < Length ; I ++ ) {
//do something here with cheking readbuf
vmCode . push ( bstream . readBits ( 8 ) ) ;
}
@ -724,8 +724,8 @@ function rarInsertLastMatch(length, distance) {
}
function rarInsertOldDist ( distance ) {
rOldDist . splice ( 3 , 1 ) ;
rOldDist . splice ( 0 , 0 , distance ) ;
rOldDist . splice ( 3 , 1 ) ;
rOldDist . splice ( 0 , 0 , distance ) ;
}
//this is the real function, the other one is for debugging
@ -737,28 +737,28 @@ function rarCopyString(length, distance) {
destPtr = rOldBuffers [ -- l ] . data . length + destPtr ;
}
//TODO: lets hope that it never needs to read beyond file boundaries
while ( length -- ) rBuffer . insertByte ( rOldBuffers [ l ] . data [ destPtr ++ ] ) ;
while ( length -- ) rBuffer . insertByte ( rOldBuffers [ l ] . data [ destPtr ++ ] ) ;
}
if ( length > distance ) {
while ( length -- ) rBuffer . insertByte ( rBuffer . data [ destPtr ++ ] ) ;
while ( length -- ) rBuffer . insertByte ( rBuffer . data [ destPtr ++ ] ) ;
} else {
rBuffer . insertBytes ( rBuffer . data . subarray ( destPtr , destPtr + length ) ) ;
}
}
var rOldBuffers = [ ]
var rOldBuffers = [ ] ;
// v must be a valid RarVolume
function unpack ( v ) {
// TODO: implement what happens when unpVer is < 15
// TODO: implement what happens when unpVer is < 15
var Ver = v . header . unpVer <= 15 ? 15 : v . header . unpVer ,
Solid = v . header . LHD _SOLID ,
bstream = new bitjs . io . BitStream ( v . fileData . buffer , true /* rtl */ , v . fileData . byteOffset , v . fileData . byteLength ) ;
rBuffer = new bitjs . io . ByteBuffer ( v . header . unpackedSize ) ;
info ( "Unpacking " + v . filename + " RAR v" + Ver ) ;
info ( "Unpacking " + v . filename + " RAR v" + Ver ) ;
switch ( Ver ) {
case 15 : // rar 1.5 compression
Unpack15 ( ) ; //(bstream, Solid);
@ -772,7 +772,7 @@ function unpack(v) {
Unpack29 ( bstream ) ;
break ;
} // switch(method)
rOldBuffers . push ( rBuffer ) ;
//TODO: clear these old buffers when there's over 4MB of history
return rBuffer . data ;
@ -780,10 +780,10 @@ function unpack(v) {
// bstream is a bit stream
var RarLocalFile = function ( bstream ) {
this . header = new RarVolumeHeader ( bstream ) ;
this . filename = this . header . filename ;
if ( this . header . headType != FILE _HEAD && this . header . headType != ENDARC _HEAD ) {
this . isValid = false ;
info ( "Error! RAR Volume did not include a FILE_HEAD header " ) ;
@ -804,7 +804,7 @@ RarLocalFile.prototype.unrar = function() {
if ( this . header . method === 0x30 ) {
info ( "Unstore " + this . filename ) ;
this . isValid = true ;
currentBytesUnarchivedInFile += this . fileData . length ;
currentBytesUnarchived += this . fileData . length ;
@ -818,7 +818,7 @@ RarLocalFile.prototype.unrar = function() {
this . fileData = unpack ( this ) ;
}
}
}
} ;
var unrar = function ( arrayBuffer ) {
currentFilename = "" ;
@ -835,16 +835,16 @@ var unrar = function(arrayBuffer) {
if ( header . crc === 0x6152 &&
header . headType === 0x72 &&
header . flags . value === 0x1A21 &&
header . headSize === 7 )
{
header . headSize === 7 ) {
info ( "Found RAR signature" ) ;
var mhead = new RarVolumeHeader ( bstream ) ;
if ( mhead . headType != MAIN _HEAD ) {
info ( "Error! RAR did not include a MAIN_HEAD header" ) ;
} else {
var localFiles = [ ] ,
localFile = null ;
var localFiles = [ ] ;
var localFile = null ;
do {
try {
localFile = new RarLocalFile ( bstream ) ;
@ -853,24 +853,24 @@ var unrar = function(arrayBuffer) {
totalUncompressedBytesInArchive += localFile . header . unpackedSize ;
localFiles . push ( localFile ) ;
} else if ( localFile . header . packSize === 0 && localFile . header . unpackedSize === 0 ) {
localFile . isValid = true ;
localFile . isValid = true ;
}
} catch ( err ) {
} catch ( err ) {
break ;
}
//info("bstream" + bstream.bytePtr+"/"+bstream.bytes.length);
} while ( localFile . isValid ) ;
} while ( localFile . isValid ) ;
totalFilesInArchive = localFiles . length ;
// now we have all information but things are unpacked
// TODO: unpack
localFiles = localFiles . sort ( function ( a , b ) {
localFiles = localFiles . sort ( function ( a , b ) {
var aname = a . filename . toLowerCase ( ) ;
var bname = b . filename . toLowerCase ( ) ;
return aname > bname ? 1 : - 1 ;
} ) ;
info ( localFiles . map ( function ( a ) { return a . filename }) . join ( ', ' ) ) ;
info ( localFiles . map ( function ( a ) { return a . filename ;} ) . join ( ", " ) ) ;
for ( var i = 0 ; i < localFiles . length ; ++ i ) {
var localfile = localFiles [ i ] ;