Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
7dac87fa
Commit
7dac87fa
authored
Aug 18, 2018
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cosmetics unrar
parent
d2ea10e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
53 deletions
+57
-53
unrar.js
cps/static/js/unrar.js
+56
-52
unzip.js
cps/static/js/unzip.js
+1
-1
No files found.
cps/static/js/unrar.js
View file @
7dac87fa
...
...
@@ -160,7 +160,7 @@ var RarVolumeHeader = function(bstream) {
// read in filename
this
.
filename
=
bstream
.
readBytes
(
this
.
nameSize
);
var
_s
=
""
var
_s
=
""
;
for
(
var
_i
=
0
;
_i
<
this
.
filename
.
length
;
_i
++
)
{
_s
+=
String
.
fromCharCode
(
this
.
filename
[
_i
]);
}
...
...
@@ -313,7 +313,7 @@ function RarReadTables(bstream) {
//console.log(DecodeLen, DecodePos, DecodeNum);
for
(
i
=
0
;
i
<
TableSize
;)
{
var
N
;
var
num
=
R
arDecodeNumber
(
bstream
,
BD
);
var
num
=
r
arDecodeNumber
(
bstream
,
BD
);
if
(
num
<
16
)
{
Table
[
i
]
=
(
num
+
UnpOldTable
[
i
])
&
0xf
;
i
++
;
...
...
@@ -345,7 +345,7 @@ function RarReadTables(bstream) {
}
function
R
arDecodeNumber
(
bstream
,
dec
)
{
function
r
arDecodeNumber
(
bstream
,
dec
)
{
var
DecodeLen
=
dec
.
DecodeLen
,
DecodePos
=
dec
.
DecodePos
,
DecodeNum
=
dec
.
DecodeNum
;
var
bitField
=
bstream
.
getBits
()
&
0xfffe
;
//some sort of rolled out binary search
...
...
@@ -365,7 +365,7 @@ function RarDecodeNumber(bstream, dec) {
((
bitField
<
DecodeLen
[
13
])
?
13
:
14
)
:
15
));
bstream
.
readBits
(
bits
);
var
N
=
DecodePos
[
bits
]
+
((
bitField
-
DecodeLen
[
bits
-
1
])
>>>
(
16
-
bits
));
var
N
=
DecodePos
[
bits
]
+
((
bitField
-
DecodeLen
[
bits
-
1
])
>>>
(
16
-
bits
));
return
DecodeNum
[
N
];
}
...
...
@@ -373,46 +373,56 @@ function RarDecodeNumber(bstream, dec) {
function
rarMakeDecodeTables
(
BitLength
,
offset
,
dec
,
size
)
{
var
DecodeLen
=
dec
.
DecodeLen
,
DecodePos
=
dec
.
DecodePos
,
DecodeNum
=
dec
.
DecodeNum
;
var
LenCount
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
TmpPos
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
var
LenCount
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
TmpPos
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
N
=
0
,
M
=
0
;
for
(
var
i
=
DecodeNum
.
length
;
i
--
;)
DecodeNum
[
i
]
=
0
;
for
(
var
i
=
0
;
i
<
size
;
i
++
)
{
var
i
;
for
(
i
=
DecodeNum
.
length
;
i
--
;)
DecodeNum
[
i
]
=
0
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
LenCount
[
BitLength
[
i
+
offset
]
&
0xF
]
++
;
}
LenCount
[
0
]
=
0
;
TmpPos
[
0
]
=
0
;
DecodePos
[
0
]
=
0
;
DecodeLen
[
0
]
=
0
;
for
(
var
I
=
1
;
I
<
16
;
++
I
)
{
var
I
;
for
(
I
=
1
;
I
<
16
;
++
I
)
{
N
=
2
*
(
N
+
LenCount
[
I
]);
M
=
(
N
<<
(
15
-
I
));
if
(
M
>
0xFFFF
)
M
=
(
N
<<
(
15
-
I
));
if
(
M
>
0xFFFF
)
{
M
=
0xFFFF
;
}
DecodeLen
[
I
]
=
M
;
DecodePos
[
I
]
=
DecodePos
[
I
-
1
]
+
LenCount
[
I
-
1
];
DecodePos
[
I
]
=
DecodePos
[
I
-
1
]
+
LenCount
[
I
-
1
];
TmpPos
[
I
]
=
DecodePos
[
I
];
}
for
(
I
=
0
;
I
<
size
;
++
I
)
{
if
(
BitLength
[
I
+
offset
]
!=
0
)
{
if
(
BitLength
[
I
+
offset
]
!=
=
0
)
{
DecodeNum
[
TmpPos
[
BitLength
[
offset
+
I
]
&
0xF
]
++
]
=
I
;
}
}
}
// TODO: implement
function
Unpack15
(
bstream
,
Solid
)
{
function
Unpack15
(
)
{
//
bstream, Solid) {
info
(
"ERROR! RAR 1.5 compression not supported"
);
}
function
Unpack20
(
bstream
,
Solid
)
{
var
lowDistRepCount
=
0
,
prevLowDist
=
0
;
var
rOldDist
=
[
0
,
0
,
0
,
0
];
var
lastDist
=
0
;
var
lastLength
=
0
;
function
Unpack20
(
bstream
)
{
//, Solid) {
var
destUnpSize
=
rBuffer
.
data
.
length
;
var
oldDistPtr
=
0
;
RarReadTables20
(
bstream
);
rarReadTables20
(
bstream
);
while
(
destUnpSize
>
rBuffer
.
ptr
)
{
var
num
=
RarDecodeNumber
(
bstream
,
LD
);
var
num
=
rarDecodeNumber
(
bstream
,
LD
);
var
Bits
;
if
(
num
<
256
)
{
rBuffer
.
insertByte
(
num
);
continue
;
...
...
@@ -422,35 +432,35 @@ function Unpack20(bstream, Solid) {
if
((
Bits
=
rLBits
[
num
])
>
0
)
{
Length
+=
bstream
.
readBits
(
Bits
);
}
var
DistNumber
=
R
arDecodeNumber
(
bstream
,
DD
);
var
DistNumber
=
r
arDecodeNumber
(
bstream
,
DD
);
var
Distance
=
rDDecode
[
DistNumber
]
+
1
;
if
((
Bits
=
rDBits
[
DistNumber
])
>
0
)
{
Distance
+=
bstream
.
readBits
(
Bits
);
}
if
(
Distance
>=
0x2000
)
{
Length
++
;
if
(
Distance
>=
0x40000
)
Length
++
;
if
(
Distance
>=
0x40000
)
Length
++
;
}
lastLength
=
Length
;
lastDist
=
rOldDist
[
oldDistPtr
++
&
3
]
=
Distance
;
R
arCopyString
(
Length
,
Distance
);
r
arCopyString
(
Length
,
Distance
);
continue
;
}
if
(
num
===
269
)
{
R
arReadTables20
(
bstream
);
r
arReadTables20
(
bstream
);
RarUpdateProgress
()
rarUpdateProgress
();
continue
;
}
if
(
num
===
256
)
{
lastDist
=
rOldDist
[
oldDistPtr
++
&
3
]
=
lastDist
;
R
arCopyString
(
lastLength
,
lastDist
);
r
arCopyString
(
lastLength
,
lastDist
);
continue
;
}
if
(
num
<
261
)
{
var
Distance
=
rOldDist
[(
oldDistPtr
-
(
num
-
256
))
&
3
];
var
LengthNumber
=
R
arDecodeNumber
(
bstream
,
RD
);
var
LengthNumber
=
r
arDecodeNumber
(
bstream
,
RD
);
var
Length
=
rLDecode
[
LengthNumber
]
+
2
;
if
((
Bits
=
rLBits
[
LengthNumber
])
>
0
)
{
Length
+=
bstream
.
readBits
(
Bits
);
...
...
@@ -464,7 +474,7 @@ function Unpack20(bstream, Solid) {
}
lastLength
=
Length
;
lastDist
=
rOldDist
[
oldDistPtr
++
&
3
]
=
Distance
;
R
arCopyString
(
Length
,
Distance
);
r
arCopyString
(
Length
,
Distance
);
continue
;
}
if
(
num
<
270
)
{
...
...
@@ -474,14 +484,14 @@ function Unpack20(bstream, Solid) {
}
lastLength
=
2
;
lastDist
=
rOldDist
[
oldDistPtr
++
&
3
]
=
Distance
;
R
arCopyString
(
2
,
Distance
);
r
arCopyString
(
2
,
Distance
);
continue
;
}
}
R
arUpdateProgress
()
r
arUpdateProgress
()
}
function
R
arUpdateProgress
()
{
function
r
arUpdateProgress
()
{
var
change
=
rBuffer
.
ptr
-
currentBytesUnarchivedInFile
;
currentBytesUnarchivedInFile
=
rBuffer
.
ptr
;
currentBytesUnarchived
+=
change
;
...
...
@@ -497,7 +507,7 @@ var rNC20 = 298,
var
UnpOldTable20
=
new
Array
(
rMC20
*
4
);
function
R
arReadTables20
(
bstream
)
{
function
r
arReadTables20
(
bstream
)
{
var
BitLength
=
new
Array
(
rBC20
);
var
Table
=
new
Array
(
rMC20
*
4
);
var
TableSize
,
N
,
I
;
...
...
@@ -510,7 +520,7 @@ function RarReadTables20(bstream) {
rarMakeDecodeTables
(
BitLength
,
0
,
BD
,
rBC20
);
I
=
0
;
while
(
I
<
TableSize
)
{
var
num
=
R
arDecodeNumber
(
bstream
,
BD
);
var
num
=
r
arDecodeNumber
(
bstream
,
BD
);
if
(
num
<
16
)
{
Table
[
I
]
=
num
+
UnpOldTable20
[
I
]
&
0xf
;
I
++
;
...
...
@@ -537,12 +547,6 @@ function RarReadTables20(bstream) {
for
(
var
i
=
UnpOldTable20
.
length
;
i
--
;)
UnpOldTable20
[
i
]
=
Table
[
i
];
}
var
lowDistRepCount
=
0
,
prevLowDist
=
0
;
var
rOldDist
=
[
0
,
0
,
0
,
0
];
var
lastDist
;
var
lastLength
;
function
Unpack29
(
bstream
,
Solid
)
{
// lazy initialize rDDecode and rDBits
...
...
@@ -562,7 +566,7 @@ function Unpack29(bstream, Solid) {
var
Bits
;
//tablesRead = false;
rOldDist
=
[
0
,
0
,
0
,
0
]
rOldDist
=
[
0
,
0
,
0
,
0
]
lastDist
=
0
;
lastLength
=
0
;
...
...
@@ -573,7 +577,7 @@ function Unpack29(bstream, Solid) {
RarReadTables
(
bstream
);
while
(
true
)
{
var
num
=
R
arDecodeNumber
(
bstream
,
LD
);
var
num
=
r
arDecodeNumber
(
bstream
,
LD
);
if
(
num
<
256
)
{
rBuffer
.
insertByte
(
num
);
...
...
@@ -584,7 +588,7 @@ function Unpack29(bstream, Solid) {
if
((
Bits
=
rLBits
[
num
])
>
0
)
{
Length
+=
bstream
.
readBits
(
Bits
);
}
var
DistNumber
=
R
arDecodeNumber
(
bstream
,
DD
);
var
DistNumber
=
r
arDecodeNumber
(
bstream
,
DD
);
var
Distance
=
DDecode
[
DistNumber
]
+
1
;
if
((
Bits
=
DBits
[
DistNumber
])
>
0
)
{
if
(
DistNumber
>
9
)
{
...
...
@@ -597,7 +601,7 @@ function Unpack29(bstream, Solid) {
lowDistRepCount
--
;
Distance
+=
prevLowDist
;
}
else
{
var
LowDist
=
R
arDecodeNumber
(
bstream
,
LDD
);
var
LowDist
=
r
arDecodeNumber
(
bstream
,
LDD
);
if
(
LowDist
===
16
)
{
lowDistRepCount
=
rLowDistRepCount
-
1
;
Distance
+=
prevLowDist
;
...
...
@@ -618,7 +622,7 @@ function Unpack29(bstream, Solid) {
}
RarInsertOldDist
(
Distance
);
RarInsertLastMatch
(
Length
,
Distance
);
R
arCopyString
(
Length
,
Distance
);
r
arCopyString
(
Length
,
Distance
);
continue
;
}
if
(
num
===
256
)
{
...
...
@@ -632,7 +636,7 @@ function Unpack29(bstream, Solid) {
}
if
(
num
===
258
)
{
if
(
lastLength
!=
0
)
{
R
arCopyString
(
lastLength
,
lastDist
);
r
arCopyString
(
lastLength
,
lastDist
);
}
continue
;
}
...
...
@@ -645,13 +649,13 @@ function Unpack29(bstream, Solid) {
}
rOldDist
[
0
]
=
Distance
;
var
LengthNumber
=
R
arDecodeNumber
(
bstream
,
RD
);
var
LengthNumber
=
r
arDecodeNumber
(
bstream
,
RD
);
var
Length
=
rLDecode
[
LengthNumber
]
+
2
;
if
((
Bits
=
rLBits
[
LengthNumber
])
>
0
)
{
Length
+=
bstream
.
readBits
(
Bits
);
}
RarInsertLastMatch
(
Length
,
Distance
);
R
arCopyString
(
Length
,
Distance
);
r
arCopyString
(
Length
,
Distance
);
continue
;
}
if
(
num
<
272
)
{
...
...
@@ -661,16 +665,16 @@ function Unpack29(bstream, Solid) {
}
RarInsertOldDist
(
Distance
);
RarInsertLastMatch
(
2
,
Distance
);
R
arCopyString
(
2
,
Distance
);
r
arCopyString
(
2
,
Distance
);
continue
;
}
}
R
arUpdateProgress
()
r
arUpdateProgress
()
}
function
RarReadEndOfBlock
(
bstream
)
{
R
arUpdateProgress
()
r
arUpdateProgress
()
var
NewTable
=
false
,
NewFile
=
false
;
if
(
bstream
.
readBits
(
1
))
{
...
...
@@ -719,7 +723,7 @@ function RarInsertOldDist(distance) {
}
//this is the real function, the other one is for debugging
function
R
arCopyString
(
length
,
distance
)
{
function
r
arCopyString
(
length
,
distance
)
{
var
destPtr
=
rBuffer
.
ptr
-
distance
;
if
(
destPtr
<
0
){
var
l
=
rOldBuffers
.
length
;
...
...
@@ -751,11 +755,11 @@ function unpack(v) {
switch
(
Ver
)
{
case
15
:
// rar 1.5 compression
Unpack15
(
bstream
,
Solid
);
Unpack15
(
);
//(
bstream, Solid);
break
;
case
20
:
// rar 2.x compression
case
26
:
// files larger than 2GB
Unpack20
(
bstream
,
Solid
);
Unpack20
(
bstream
);
//
, Solid);
break
;
case
29
:
// rar 3.x compression
case
36
:
// alternative hash
...
...
cps/static/js/unzip.js
View file @
7dac87fa
...
...
@@ -520,7 +520,7 @@ function inflate(compressedData, numDecompressedBytes) {
if
(
bType
===
0
)
{
// skip remaining bits in this byte
while
(
bstream
.
bitPtr
!==
0
)
bstream
.
readBits
(
1
);
var
len
=
bstream
.
readBits
(
16
)
,
var
len
=
bstream
.
readBits
(
16
)
;
// nlen = bstream.readBits(16);
// TODO: check if nlen is the ones-complement of len?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment