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
cd546eb6
Commit
cd546eb6
authored
Jun 17, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update comic reader js
parent
e67d7078
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
311 additions
and
292 deletions
+311
-292
archive.js
cps/static/js/archive/archive.js
+23
-24
rarvm.js
cps/static/js/archive/rarvm.js
+112
-106
unrar.js
cps/static/js/archive/unrar.js
+68
-65
untar.js
cps/static/js/archive/untar.js
+13
-10
unzip.js
cps/static/js/archive/unzip.js
+15
-21
bitstream.js
cps/static/js/io/bitstream.js
+23
-19
bytebuffer.js
cps/static/js/io/bytebuffer.js
+12
-9
bytestream.js
cps/static/js/io/bytestream.js
+12
-8
kthoom.js
cps/static/js/kthoom.js
+33
-30
No files found.
cps/static/js/archive/archive.js
View file @
cd546eb6
...
...
@@ -8,7 +8,7 @@
* Copyright(c) 2011 Google Inc.
*/
/* global bitjs */
/* global bitjs
, Uint8Array
*/
var
bitjs
=
bitjs
||
{};
bitjs
.
archive
=
bitjs
.
archive
||
{};
...
...
@@ -17,7 +17,7 @@ bitjs.archive = bitjs.archive || {};
// ===========================================================================
// Stolen from Closure because it's the best way to do Java-like inheritance.
bitjs
.
base
=
function
(
me
,
opt
_methodName
,
var_a
rgs
)
{
bitjs
.
base
=
function
(
me
,
opt
MethodName
,
varA
rgs
)
{
var
caller
=
arguments
.
callee
.
caller
;
if
(
caller
.
superClass_
)
{
// This is a constructor. Call the superclass constructor.
...
...
@@ -28,10 +28,10 @@ bitjs.archive = bitjs.archive || {};
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
2
);
var
foundCaller
=
false
;
for
(
var
ctor
=
me
.
constructor
;
ctor
;
ctor
=
ctor
.
superClass_
&&
ctor
.
superClass_
.
constructor
)
{
if
(
ctor
.
prototype
[
opt
_m
ethodName
]
===
caller
)
{
if
(
ctor
.
prototype
[
opt
M
ethodName
]
===
caller
)
{
foundCaller
=
true
;
}
else
if
(
foundCaller
)
{
return
ctor
.
prototype
[
opt
_m
ethodName
].
apply
(
me
,
args
);
return
ctor
.
prototype
[
opt
M
ethodName
].
apply
(
me
,
args
);
}
}
...
...
@@ -39,8 +39,8 @@ bitjs.archive = bitjs.archive || {};
// then one of two things happened:
// 1) The caller is an instance method.
// 2) This method was not called by the right caller.
if
(
me
[
opt
_m
ethodName
]
===
caller
)
{
return
me
.
constructor
.
prototype
[
opt
_m
ethodName
].
apply
(
me
,
args
);
if
(
me
[
opt
M
ethodName
]
===
caller
)
{
return
me
.
constructor
.
prototype
[
opt
M
ethodName
].
apply
(
me
,
args
);
}
else
{
throw
Error
(
"goog.base called from a method of one name "
+
...
...
@@ -49,10 +49,10 @@ bitjs.archive = bitjs.archive || {};
};
bitjs
.
inherits
=
function
(
childCtor
,
parentCtor
)
{
/** @constructor */
function
tempCtor
()
{};
t
empCtor
.
prototype
=
parentCtor
.
prototype
;
function
TempCtor
()
{}
T
empCtor
.
prototype
=
parentCtor
.
prototype
;
childCtor
.
superClass_
=
parentCtor
.
prototype
;
childCtor
.
prototype
=
new
t
empCtor
();
childCtor
.
prototype
=
new
T
empCtor
();
childCtor
.
prototype
.
constructor
=
childCtor
;
};
// ===========================================================================
...
...
@@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {};
* Base class for all Unarchivers.
*
* @param {ArrayBuffer} arrayBuffer The Array Buffer.
* @param {string} opt
_p
athToBitJS Optional string for where the BitJS files are located.
* @param {string} opt
P
athToBitJS Optional string for where the BitJS files are located.
* @constructor
*/
bitjs
.
archive
.
Unarchiver
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Unarchiver
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
/**
* The ArrayBuffer object.
* @type {ArrayBuffer}
...
...
@@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {};
* @type {string}
* @private
*/
this
.
pathToBitJS_
=
opt
_p
athToBitJS
||
"/"
;
this
.
pathToBitJS_
=
opt
P
athToBitJS
||
"/"
;
/**
* A map from event type to an array of listeners.
...
...
@@ -319,8 +319,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @constructor
*/
bitjs
.
archive
.
Unzipper
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
archive
.
Unzipper
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
bitjs
.
inherits
(
bitjs
.
archive
.
Unzipper
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Unzipper
.
prototype
.
getScriptFileName
=
function
()
{
...
...
@@ -332,8 +332,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @constructor
*/
bitjs
.
archive
.
Unrarrer
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
archive
.
Unrarrer
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
bitjs
.
inherits
(
bitjs
.
archive
.
Unrarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Unrarrer
.
prototype
.
getScriptFileName
=
function
()
{
...
...
@@ -345,8 +345,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @constructor
*/
bitjs
.
archive
.
Untarrer
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
archive
.
Untarrer
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
bitjs
.
inherits
(
bitjs
.
archive
.
Untarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Untarrer
.
prototype
.
getScriptFileName
=
function
()
{
...
...
@@ -357,20 +357,19 @@ bitjs.archive = bitjs.archive || {};
* Factory method that creates an unarchiver based on the byte signature found
* in the arrayBuffer.
* @param {ArrayBuffer} ab
* @param {string=} opt
_p
athToBitJS Path to the unarchiver script files.
* @param {string=} opt
P
athToBitJS Path to the unarchiver script files.
* @return {bitjs.archive.Unarchiver}
*/
bitjs
.
archive
.
GetUnarchiver
=
function
(
ab
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
GetUnarchiver
=
function
(
ab
,
opt
P
athToBitJS
)
{
var
unarchiver
=
null
;
var
pathToBitJS
=
opt
_pathToBitJS
||
''
;
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!
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)
}
else
if
(
h
[
0
]
==
=
80
&&
h
[
1
]
=
==
75
)
{
// PK (Zip)
unarchiver
=
new
bitjs
.
archive
.
Unzipper
(
ab
,
pathToBitJS
);
}
else
{
// Try with tar
console
.
log
(
'geter'
);
unarchiver
=
new
bitjs
.
archive
.
Untarrer
(
ab
,
pathToBitJS
);
}
return
unarchiver
;
...
...
cps/static/js/archive/rarvm.js
View file @
cd546eb6
...
...
@@ -9,9 +9,12 @@
/**
* CRC Implementation.
*/
/* global Uint8Array, Uint32Array, bitjs, DataView */
/* exported MAXWINMASK, UnpackFilter */
var
CRCTab
=
new
Array
(
256
).
fill
(
0
);
function
I
nitCRC
()
{
function
i
nitCRC
()
{
for
(
var
i
=
0
;
i
<
256
;
++
i
)
{
var
c
=
i
;
for
(
var
j
=
0
;
j
<
8
;
++
j
)
{
...
...
@@ -30,8 +33,8 @@ function InitCRC() {
* @return {number}
*/
function
CRC
(
startCRC
,
arr
)
{
if
(
CRCTab
[
1
]
==
0
)
{
I
nitCRC
();
if
(
CRCTab
[
1
]
==
=
0
)
{
i
nitCRC
();
}
/*
...
...
@@ -84,7 +87,7 @@ var MAXWINMASK = (MAXWINSIZE - 1);
/**
*/
var
V
M_
Commands
=
{
var
V
m
Commands
=
{
VM_MOV
:
0
,
VM_CMP
:
1
,
VM_ADD
:
2
,
...
...
@@ -141,7 +144,7 @@ var VM_Commands = {
/**
*/
var
V
M_
StandardFilters
=
{
var
V
m
StandardFilters
=
{
VMSF_NONE
:
0
,
VMSF_E8
:
1
,
VMSF_E8E9
:
2
,
...
...
@@ -154,7 +157,7 @@ var VM_StandardFilters = {
/**
*/
var
V
M_
Flags
=
{
var
V
m
Flags
=
{
VM_FC
:
1
,
VM_FZ
:
2
,
VM_FS
:
0x80000000
,
...
...
@@ -162,7 +165,7 @@ var VM_Flags = {
/**
*/
var
V
M_
OpType
=
{
var
V
m
OpType
=
{
VM_OPREG
:
0
,
VM_OPINT
:
1
,
VM_OPREGMEM
:
2
,
...
...
@@ -186,15 +189,15 @@ function findKeyForValue(obj, val) {
}
function
getDebugString
(
obj
,
val
)
{
var
s
=
'Unknown.'
;
if
(
obj
===
V
M_
Commands
)
{
s
=
'VM_Commands.'
;
}
else
if
(
obj
===
V
M_
StandardFilters
)
{
s
=
'VM_StandardFilters.'
;
}
else
if
(
obj
===
V
M_
Flags
)
{
s
=
'VM_OpType.'
;
}
else
if
(
obj
===
V
M_
OpType
)
{
s
=
'VM_OpType.'
;
var
s
=
"Unknown."
;
if
(
obj
===
V
m
Commands
)
{
s
=
"VmCommands."
;
}
else
if
(
obj
===
V
m
StandardFilters
)
{
s
=
"VmStandardFilters."
;
}
else
if
(
obj
===
V
m
Flags
)
{
s
=
"VmOpType."
;
}
else
if
(
obj
===
V
m
OpType
)
{
s
=
"VmOpType."
;
}
return
s
+
findKeyForValue
(
obj
,
val
);
...
...
@@ -204,8 +207,8 @@ function getDebugString(obj, val) {
* @struct
* @constructor
*/
var
V
M_
PreparedOperand
=
function
()
{
/** @type {V
M_
OpType} */
var
V
m
PreparedOperand
=
function
()
{
/** @type {V
m
OpType} */
this
.
Type
;
/** @type {number} */
...
...
@@ -220,58 +223,58 @@ var VM_PreparedOperand = function() {
};
/** @return {string} */
V
M_
PreparedOperand
.
prototype
.
toString
=
function
()
{
V
m
PreparedOperand
.
prototype
.
toString
=
function
()
{
if
(
this
.
Type
===
null
)
{
return
'Error: Type was null in VM_PreparedOperand'
;
return
"Error: Type was null in VmPreparedOperand"
;
}
return
'{ '
+
'Type: '
+
getDebugString
(
VM_
OpType
,
this
.
Type
)
+
', Data: '
+
this
.
Data
+
', Base: '
+
this
.
Base
+
' }'
;
return
"{ "
+
"Type: "
+
getDebugString
(
Vm
OpType
,
this
.
Type
)
+
", Data: "
+
this
.
Data
+
", Base: "
+
this
.
Base
+
" }"
;
};
/**
* @struct
* @constructor
*/
var
V
M_
PreparedCommand
=
function
()
{
/** @type {V
M_
Commands} */
var
V
m
PreparedCommand
=
function
()
{
/** @type {V
m
Commands} */
this
.
OpCode
;
/** @type {boolean} */
this
.
ByteMode
=
false
;
/** @type {V
M_
PreparedOperand} */
this
.
Op1
=
new
V
M_
PreparedOperand
();
/** @type {V
m
PreparedOperand} */
this
.
Op1
=
new
V
m
PreparedOperand
();
/** @type {V
M_
PreparedOperand} */
this
.
Op2
=
new
V
M_
PreparedOperand
();
/** @type {V
m
PreparedOperand} */
this
.
Op2
=
new
V
m
PreparedOperand
();
};
/** @return {string} */
V
M_
PreparedCommand
.
prototype
.
toString
=
function
(
indent
)
{
V
m
PreparedCommand
.
prototype
.
toString
=
function
(
indent
)
{
if
(
this
.
OpCode
===
null
)
{
return
'Error: OpCode was null in VM_PreparedCommand'
;
}
indent
=
indent
||
''
;
return
indent
+
'{
\
n'
+
indent
+
' OpCode: '
+
getDebugString
(
VM_Commands
,
this
.
OpCode
)
+
',
\
n'
+
indent
+
' ByteMode: '
+
this
.
ByteMode
+
',
\
n'
+
indent
+
' Op1: '
+
this
.
Op1
.
toString
()
+
',
\
n'
+
indent
+
' Op2: '
+
this
.
Op2
.
toString
()
+
',
\
n'
+
indent
+
'}'
;
return
"Error: OpCode was null in VmPreparedCommand"
;
}
indent
=
indent
||
""
;
return
indent
+
"{
\n
"
+
indent
+
" OpCode: "
+
getDebugString
(
VmCommands
,
this
.
OpCode
)
+
",
\n
"
+
indent
+
" ByteMode: "
+
this
.
ByteMode
+
",
\n
"
+
indent
+
" Op1: "
+
this
.
Op1
.
toString
()
+
",
\n
"
+
indent
+
" Op2: "
+
this
.
Op2
.
toString
()
+
",
\n
"
+
indent
+
"}"
;
};
/**
* @struct
* @constructor
*/
var
V
M_
PreparedProgram
=
function
()
{
/** @type {Array<V
M_
PreparedCommand>} */
var
V
m
PreparedProgram
=
function
()
{
/** @type {Array<V
m
PreparedCommand>} */
this
.
Cmd
=
[];
/** @type {Array<V
M_
PreparedCommand>} */
/** @type {Array<V
m
PreparedCommand>} */
this
.
AltCmd
=
null
;
/** @type {Uint8Array} */
...
...
@@ -291,14 +294,14 @@ var VM_PreparedProgram = function() {
};
/** @return {string} */
V
M_
PreparedProgram
.
prototype
.
toString
=
function
()
{
var
s
=
'{
\
n Cmd: [
\
n'
;
V
m
PreparedProgram
.
prototype
.
toString
=
function
()
{
var
s
=
"{
\n
Cmd: [
\n
"
;
for
(
var
i
=
0
;
i
<
this
.
Cmd
.
length
;
++
i
)
{
s
+=
this
.
Cmd
[
i
].
toString
(
' '
)
+
',
\
n'
;
s
+=
this
.
Cmd
[
i
].
toString
(
" "
)
+
",
\n
"
;
}
s
+=
'],
\
n'
;
s
+=
"],
\n
"
;
// TODO: Dump GlobalData, StaticData, InitR?
s
+=
' }
\
n'
;
s
+=
" }
\n
"
;
return
s
;
};
...
...
@@ -324,8 +327,8 @@ var UnpackFilter = function() {
/** @type {number} */
this
.
ParentFilter
=
null
;
/** @type {V
M_
PreparedProgram} */
this
.
Prg
=
new
V
M_
PreparedProgram
();
/** @type {V
m
PreparedProgram} */
this
.
Prg
=
new
V
m
PreparedProgram
();
};
var
VMCF_OP0
=
0
;
...
...
@@ -338,7 +341,7 @@ var VMCF_PROC = 16;
var
VMCF_USEFLAGS
=
32
;
var
VMCF_CHFLAGS
=
64
;
var
V
M_
CmdFlags
=
[
var
V
m
CmdFlags
=
[
/* VM_MOV */
VMCF_OP2
|
VMCF_BYTEMODE
,
/* VM_CMP */
...
...
@@ -425,7 +428,7 @@ var VM_CmdFlags = [
/**
* @param {number} length
* @param {number} crc
* @param {V
M_
StandardFilters} type
* @param {V
m
StandardFilters} type
* @struct
* @constructor
*/
...
...
@@ -436,7 +439,7 @@ var StandardFilterSignature = function(length, crc, type) {
/** @type {number} */
this
.
CRC
=
crc
;
/** @type {V
M_
StandardFilters} */
/** @type {V
m
StandardFilters} */
this
.
Type
=
type
;
};
...
...
@@ -444,13 +447,13 @@ var StandardFilterSignature = function(length, crc, type) {
* @type {Array<StandardFilterSignature>}
*/
var
StdList
=
[
new
StandardFilterSignature
(
53
,
0xad576887
,
V
M_
StandardFilters
.
VMSF_E8
),
new
StandardFilterSignature
(
57
,
0x3cd7e57e
,
V
M_
StandardFilters
.
VMSF_E8E9
),
new
StandardFilterSignature
(
120
,
0x3769893f
,
V
M_
StandardFilters
.
VMSF_ITANIUM
),
new
StandardFilterSignature
(
29
,
0x0e06077d
,
V
M_
StandardFilters
.
VMSF_DELTA
),
new
StandardFilterSignature
(
149
,
0x1c2c5dc8
,
V
M_
StandardFilters
.
VMSF_RGB
),
new
StandardFilterSignature
(
216
,
0xbc85e701
,
V
M_
StandardFilters
.
VMSF_AUDIO
),
new
StandardFilterSignature
(
40
,
0x46b9c560
,
V
M_
StandardFilters
.
VMSF_UPCASE
),
new
StandardFilterSignature
(
53
,
0xad576887
,
V
m
StandardFilters
.
VMSF_E8
),
new
StandardFilterSignature
(
57
,
0x3cd7e57e
,
V
m
StandardFilters
.
VMSF_E8E9
),
new
StandardFilterSignature
(
120
,
0x3769893f
,
V
m
StandardFilters
.
VMSF_ITANIUM
),
new
StandardFilterSignature
(
29
,
0x0e06077d
,
V
m
StandardFilters
.
VMSF_DELTA
),
new
StandardFilterSignature
(
149
,
0x1c2c5dc8
,
V
m
StandardFilters
.
VMSF_RGB
),
new
StandardFilterSignature
(
216
,
0xbc85e701
,
V
m
StandardFilters
.
VMSF_AUDIO
),
new
StandardFilterSignature
(
40
,
0x46b9c560
,
V
m
StandardFilters
.
VMSF_UPCASE
),
];
/**
...
...
@@ -478,33 +481,34 @@ RarVM.prototype.init = function() {
/**
* @param {Uint8Array} code
* @return {V
M_
StandardFilters}
* @return {V
m
StandardFilters}
*/
RarVM
.
prototype
.
isStandardFilter
=
function
(
code
)
{
var
codeCRC
=
(
CRC
(
0xffffffff
,
code
,
code
.
length
)
^
0xffffffff
)
>>>
0
;
for
(
var
i
=
0
;
i
<
StdList
.
length
;
++
i
)
{
if
(
StdList
[
i
].
CRC
==
codeCRC
&&
StdList
[
i
].
Length
==
code
.
length
)
if
(
StdList
[
i
].
CRC
==
=
codeCRC
&&
StdList
[
i
].
Length
===
code
.
length
)
{
return
StdList
[
i
].
Type
;
}
}
return
V
M_
StandardFilters
.
VMSF_NONE
;
return
V
m
StandardFilters
.
VMSF_NONE
;
};
/**
* @param {V
M_
PreparedOperand} op
* @param {V
m
PreparedOperand} op
* @param {boolean} byteMode
* @param {bitjs.io.BitStream} bstream A rtl bit stream.
*/
RarVM
.
prototype
.
decodeArg
=
function
(
op
,
byteMode
,
bstream
)
{
var
data
=
bstream
.
peekBits
(
16
);
if
(
data
&
0x8000
)
{
op
.
Type
=
V
M_
OpType
.
VM_OPREG
;
// Operand is register (R[0]..R[7])
op
.
Type
=
V
m
OpType
.
VM_OPREG
;
// Operand is register (R[0]..R[7])
bstream
.
readBits
(
1
);
// 1 flag bit and...
op
.
Data
=
bstream
.
readBits
(
3
);
// ... 3 register number bits
op
.
Addr
=
[
this
.
R_
[
op
.
Data
]]
// TODO &R[Op.Data] // Register address
op
.
Addr
=
[
this
.
R_
[
op
.
Data
]]
;
// TODO &R[Op.Data] // Register address
}
else
{
if
((
data
&
0xc000
)
==
0
)
{
op
.
Type
=
V
M_
OpType
.
VM_OPINT
;
// Operand is integer
if
((
data
&
0xc000
)
==
=
0
)
{
op
.
Type
=
V
m
OpType
.
VM_OPINT
;
// Operand is integer
bstream
.
readBits
(
2
);
// 2 flag bits
if
(
byteMode
)
{
op
.
Data
=
bstream
.
readBits
(
8
);
// Byte integer.
...
...
@@ -513,8 +517,8 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) {
}
}
else
{
// Operand is data addressed by register data, base address or both.
op
.
Type
=
V
M_
OpType
.
VM_OPREGMEM
;
if
((
data
&
0x2000
)
==
0
)
{
op
.
Type
=
V
m
OpType
.
VM_OPREGMEM
;
if
((
data
&
0x2000
)
==
=
0
)
{
bstream
.
readBits
(
3
);
// 3 flag bits
// Base address is zero, just use the address from register.
op
.
Data
=
bstream
.
readBits
(
3
);
// (Data>>10)&7
...
...
@@ -522,7 +526,7 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) {
op
.
Base
=
0
;
}
else
{
bstream
.
readBits
(
4
);
// 4 flag bits
if
((
data
&
0x1000
)
==
0
)
{
if
((
data
&
0x1000
)
==
=
0
)
{
// Use both register and base address.
op
.
Data
=
bstream
.
readBits
(
3
);
op
.
Addr
=
[
this
.
R_
[
op
.
Data
]];
// TODO &R[op.Data]
...
...
@@ -537,7 +541,7 @@ RarVM.prototype.decodeArg = function(op, byteMode, bstream) {
};
/**
* @param {V
M_
PreparedProgram} prg
* @param {V
m
PreparedProgram} prg
*/
RarVM
.
prototype
.
execute
=
function
(
prg
)
{
this
.
R_
.
set
(
prg
.
InitR
);
...
...
@@ -558,7 +562,7 @@ RarVM.prototype.execute = function(prg) {
var
preparedCodes
=
prg
.
AltCmd
?
prg
.
AltCmd
:
prg
.
Cmd
;
if
(
prg
.
Cmd
.
length
>
0
&&
!
this
.
executeCode
(
preparedCodes
))
{
// Invalid VM program. Let's replace it with 'return' command.
preparedCode
.
OpCode
=
VM_
Commands
.
VM_RET
;
preparedCode
s
.
OpCode
=
Vm
Commands
.
VM_RET
;
}
var
dataView
=
new
DataView
(
this
.
mem_
.
buffer
,
VM_GLOBALMEMADDR
);
...
...
@@ -573,7 +577,7 @@ RarVM.prototype.execute = function(prg) {
var
dataSize
=
Math
.
min
(
dataView
.
getUint32
(
0x30
),
(
VM_GLOBALMEMSIZE
-
VM_FIXEDGLOBALSIZE
));
if
(
dataSize
!=
0
)
{
if
(
dataSize
!=
=
0
)
{
var
len
=
dataSize
+
VM_FIXEDGLOBALSIZE
;
prg
.
GlobalData
=
new
Uint8Array
(
len
);
prg
.
GlobalData
.
set
(
mem
.
subarray
(
VM_GLOBALMEMADDR
,
VM_GLOBALMEMADDR
+
len
));
...
...
@@ -581,7 +585,7 @@ RarVM.prototype.execute = function(prg) {
};
/**
* @param {Array<V
M_
PreparedCommand>} preparedCodes
* @param {Array<V
m
PreparedCommand>} preparedCodes
* @return {boolean}
*/
RarVM
.
prototype
.
executeCode
=
function
(
preparedCodes
)
{
...
...
@@ -591,7 +595,7 @@ RarVM.prototype.executeCode = function(preparedCodes) {
// when a VM_RET is hit?
while
(
1
)
{
switch
(
cmd
.
OpCode
)
{
case
V
M_
Commands
.
VM_RET
:
case
V
m
Commands
.
VM_RET
:
if
(
this
.
R_
[
7
]
>=
VM_MEMSIZE
)
{
return
true
;
}
...
...
@@ -599,12 +603,12 @@ RarVM.prototype.executeCode = function(preparedCodes) {
this
.
R_
[
7
]
+=
4
;
continue
;
case
V
M_
Commands
.
VM_STANDARD
:
case
V
m
Commands
.
VM_STANDARD
:
this
.
executeStandardFilter
(
cmd
.
Op1
.
Data
);
break
;
default
:
console
.
error
(
'RarVM OpCode not supported: '
+
getDebugString
(
VM_
Commands
,
cmd
.
OpCode
));
console
.
error
(
"RarVM OpCode not supported: "
+
getDebugString
(
Vm
Commands
,
cmd
.
OpCode
));
break
;
}
// switch (cmd.OpCode)
codeIndex
++
;
...
...
@@ -617,7 +621,7 @@ RarVM.prototype.executeCode = function(preparedCodes) {
*/
RarVM
.
prototype
.
executeStandardFilter
=
function
(
filterType
)
{
switch
(
filterType
)
{
case
V
M_
StandardFilters
.
VMSF_DELTA
:
case
V
m
StandardFilters
.
VMSF_DELTA
:
var
dataSize
=
this
.
R_
[
4
];
var
channels
=
this
.
R_
[
0
];
var
srcPos
=
0
;
...
...
@@ -644,17 +648,19 @@ RarVM.prototype.executeStandardFilter = function(filterType) {
break
;
default
:
console
.
error
(
'RarVM Standard Filter not supported: '
+
getDebugString
(
VM_
StandardFilters
,
filterType
));
console
.
error
(
"RarVM Standard Filter not supported: "
+
getDebugString
(
Vm
StandardFilters
,
filterType
));
break
;
}
};
/**
* @param {Uint8Array} code
* @param {V
M_
PreparedProgram} prg
* @param {V
m
PreparedProgram} prg
*/
RarVM
.
prototype
.
prepare
=
function
(
code
,
prg
)
{
var
codeSize
=
code
.
length
;
var
i
;
var
curCmd
;
//InitBitInput();
//memcpy(InBuf,Code,Min(CodeSize,BitInput::MAX_SIZE));
...
...
@@ -662,7 +668,7 @@ RarVM.prototype.prepare = function(code, prg) {
// Calculate the single byte XOR checksum to check validity of VM code.
var
xorSum
=
0
;
for
(
var
i
=
1
;
i
<
codeSize
;
++
i
)
{
for
(
i
=
1
;
i
<
codeSize
;
++
i
)
{
xorSum
^=
code
[
i
];
}
...
...
@@ -671,20 +677,20 @@ RarVM.prototype.prepare = function(code, prg) {
prg
.
Cmd
=
[];
// TODO: Is this right? I don't see it being done in rarvm.cpp.
// VM code is valid if equal.
if
(
xorSum
==
code
[
0
])
{
if
(
xorSum
==
=
code
[
0
])
{
var
filterType
=
this
.
isStandardFilter
(
code
);
if
(
filterType
!=
VM_
StandardFilters
.
VMSF_NONE
)
{
if
(
filterType
!=
=
Vm
StandardFilters
.
VMSF_NONE
)
{
// VM code is found among standard filters.
var
curCmd
=
new
VM_
PreparedCommand
();
curCmd
=
new
Vm
PreparedCommand
();
prg
.
Cmd
.
push
(
curCmd
);
curCmd
.
OpCode
=
V
M_
Commands
.
VM_STANDARD
;
curCmd
.
OpCode
=
V
m
Commands
.
VM_STANDARD
;
curCmd
.
Op1
.
Data
=
filterType
;
// TODO: Addr=&CurCmd->Op1.Data
curCmd
.
Op1
.
Addr
=
[
curCmd
.
Op1
.
Data
];
curCmd
.
Op2
.
Addr
=
[
null
];
// &CurCmd->Op2.Data;
curCmd
.
Op1
.
Type
=
V
M_
OpType
.
VM_OPNONE
;
curCmd
.
Op2
.
Type
=
V
M_
OpType
.
VM_OPNONE
;
curCmd
.
Op1
.
Type
=
V
m
OpType
.
VM_OPNONE
;
curCmd
.
Op2
.
Type
=
V
m
OpType
.
VM_OPNONE
;
codeSize
=
0
;
}
...
...
@@ -696,7 +702,7 @@ RarVM.prototype.prepare = function(code, prg) {
if
(
dataFlag
&
0x8000
)
{
var
dataSize
=
RarVM
.
readData
(
bstream
)
+
1
;
// TODO: This accesses the byte pointer of the bstream directly. Is that ok?
for
(
var
i
=
0
;
i
<
bstream
.
bytePtr
<
codeSize
&&
i
<
dataSize
;
++
i
)
{
for
(
i
=
0
;
i
<
bstream
.
bytePtr
<
codeSize
&&
i
<
dataSize
;
++
i
)
{
// Append a byte to the program's static data.
var
newStaticData
=
new
Uint8Array
(
prg
.
StaticData
.
length
+
1
);
newStaticData
.
set
(
prg
.
StaticData
);
...
...
@@ -706,7 +712,7 @@ RarVM.prototype.prepare = function(code, prg) {
}
while
(
bstream
.
bytePtr
<
codeSize
)
{
var
curCmd
=
new
VM_
PreparedCommand
();
curCmd
=
new
Vm
PreparedCommand
();
prg
.
Cmd
.
push
(
curCmd
);
// Prg->Cmd.Add(1)
var
flag
=
bstream
.
peekBits
(
1
);
if
(
!
flag
)
{
// (Data&0x8000)==0
...
...
@@ -715,22 +721,22 @@ RarVM.prototype.prepare = function(code, prg) {
curCmd
.
OpCode
=
(
bstream
.
readBits
(
6
)
-
24
);
}
if
(
V
M_
CmdFlags
[
curCmd
.
OpCode
]
&
VMCF_BYTEMODE
)
{
curCmd
.
ByteMode
=
(
bstream
.
readBits
(
1
)
!=
0
);
if
(
V
m
CmdFlags
[
curCmd
.
OpCode
]
&
VMCF_BYTEMODE
)
{
curCmd
.
ByteMode
=
(
bstream
.
readBits
(
1
)
!=
=
0
);
}
else
{
curCmd
.
ByteMode
=
0
;
}
curCmd
.
Op1
.
Type
=
V
M_
OpType
.
VM_OPNONE
;
curCmd
.
Op2
.
Type
=
V
M_
OpType
.
VM_OPNONE
;
var
opNum
=
(
V
M_
CmdFlags
[
curCmd
.
OpCode
]
&
VMCF_OPMASK
);
curCmd
.
Op1
.
Type
=
V
m
OpType
.
VM_OPNONE
;
curCmd
.
Op2
.
Type
=
V
m
OpType
.
VM_OPNONE
;
var
opNum
=
(
V
m
CmdFlags
[
curCmd
.
OpCode
]
&
VMCF_OPMASK
);
curCmd
.
Op1
.
Addr
=
null
;
curCmd
.
Op2
.
Addr
=
null
;
if
(
opNum
>
0
)
{
this
.
decodeArg
(
curCmd
.
Op1
,
curCmd
.
ByteMode
,
bstream
);
// reading the first operand
if
(
opNum
==
2
)
{
if
(
opNum
==
=
2
)
{
this
.
decodeArg
(
curCmd
.
Op2
,
curCmd
.
ByteMode
,
bstream
);
// reading the second operand
}
else
{
if
(
curCmd
.
Op1
.
Type
==
VM_OpType
.
VM_OPINT
&&
(
VM_
CmdFlags
[
curCmd
.
OpCode
]
&
(
VMCF_JUMP
|
VMCF_PROC
)))
{
if
(
curCmd
.
Op1
.
Type
==
=
VmOpType
.
VM_OPINT
&&
(
Vm
CmdFlags
[
curCmd
.
OpCode
]
&
(
VMCF_JUMP
|
VMCF_PROC
)))
{
// Calculating jump distance.
var
distance
=
curCmd
.
Op1
.
Data
;
if
(
distance
>=
256
)
{
...
...
@@ -756,26 +762,26 @@ RarVM.prototype.prepare = function(code, prg) {
}
// while ((uint)InAddr<CodeSize)
}
// if (XorSum==Code[0])
var
curCmd
=
new
VM_
PreparedCommand
();
curCmd
=
new
Vm
PreparedCommand
();
prg
.
Cmd
.
push
(
curCmd
);
curCmd
.
OpCode
=
V
M_
Commands
.
VM_RET
;
curCmd
.
OpCode
=
V
m
Commands
.
VM_RET
;
// TODO: Addr=&CurCmd->Op1.Data
curCmd
.
Op1
.
Addr
=
[
curCmd
.
Op1
.
Data
];
curCmd
.
Op2
.
Addr
=
[
curCmd
.
Op2
.
Data
];
curCmd
.
Op1
.
Type
=
V
M_
OpType
.
VM_OPNONE
;
curCmd
.
Op2
.
Type
=
V
M_
OpType
.
VM_OPNONE
;
curCmd
.
Op1
.
Type
=
V
m
OpType
.
VM_OPNONE
;
curCmd
.
Op2
.
Type
=
V
m
OpType
.
VM_OPNONE
;
// If operand 'Addr' field has not been set by DecodeArg calls above,
// let's set it to point to operand 'Data' field. It is necessary for
// VM_OPINT type operands (usual integers) or maybe if something was
// not set properly for other operands. 'Addr' field is required
// for quicker addressing of operand data.
for
(
var
i
=
0
;
i
<
prg
.
Cmd
.
length
;
++
i
)
{
for
(
i
=
0
;
i
<
prg
.
Cmd
.
length
;
++
i
)
{
var
cmd
=
prg
.
Cmd
[
i
];
if
(
cmd
.
Op1
.
Addr
==
null
)
{
if
(
cmd
.
Op1
.
Addr
==
=
null
)
{
cmd
.
Op1
.
Addr
=
[
cmd
.
Op1
.
Data
];
}
if
(
cmd
.
Op2
.
Addr
==
null
)
{
if
(
cmd
.
Op2
.
Addr
==
=
null
)
{
cmd
.
Op2
.
Addr
=
[
cmd
.
Op2
.
Data
];
}
}
...
...
@@ -833,7 +839,7 @@ RarVM.readData = function(bstream) {
case
1
:
// 0x4000
// 0x3c00 => 0011 1100 0000 0000
if
(
bstream
.
peekBits
(
4
)
==
0
)
{
// (Data&0x3c00)==0
if
(
bstream
.
peekBits
(
4
)
==
=
0
)
{
// (Data&0x3c00)==0
// Skip the 4 zero bits.
bstream
.
readBits
(
4
);
// Read in the next 8 and pad with 1s to 32 bits.
...
...
cps/static/js/archive/unrar.js
View file @
cd546eb6
...
...
@@ -10,13 +10,14 @@
*
* http://kthoom.googlecode.com/hg/docs/unrar.html
*/
/* global bitjs, importScripts */
/* global bitjs, importScripts, RarVM, Uint8Array, UnpackFilter */
/* global VM_FIXEDGLOBALSIZE, VM_GLOBALMEMSIZE, MAXWINMASK, VM_GLOBALMEMADDR, MAXWINSIZE */
// This file expects to be invoked as a Worker (see onmessage below).
importScripts
(
'../io/bitstream.js'
);
importScripts
(
'../io/bytebuffer.js'
);
importScripts
(
'archive.js'
);
importScripts
(
'rarvm.js'
);
importScripts
(
"../io/bitstream.js"
);
importScripts
(
"../io/bytebuffer.js"
);
importScripts
(
"archive.js"
);
importScripts
(
"rarvm.js"
);
// Progress variables.
var
currentFilename
=
""
;
...
...
@@ -296,6 +297,12 @@ var rBuffer;
*/
var
wBuffer
;
var
lowDistRepCount
=
0
;
var
prevLowDist
=
0
;
var
rOldDist
=
[
0
,
0
,
0
,
0
];
var
lastDist
;
var
lastLength
;
/**
* In unpack.cpp, UnpPtr keeps track of what bytes have been unpacked
...
...
@@ -449,7 +456,7 @@ function rarMakeDecodeTables(BitLength, offset, dec, size) {
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
;
}
}
...
...
@@ -524,7 +531,7 @@ function unpack20(bstream) { //, Solid) {
if
(
Distance
>=
0x101
)
{
Length
++
;
if
(
Distance
>=
0x2000
)
{
Length
++
Length
++
;
if
(
Distance
>=
0x40000
)
{
Length
++
;
}
...
...
@@ -611,13 +618,6 @@ function rarReadTables20(bstream) {
}
}
var
lowDistRepCount
=
0
;
var
prevLowDist
=
0
;
var
rOldDist
=
[
0
,
0
,
0
,
0
];
var
lastDist
;
var
lastLength
;
// ============================================================================================== //
// Unpack code specific to RarVM
...
...
@@ -644,7 +644,7 @@ var OldFilterLengths = [];
var
LastFilter
=
0
;
function
I
nitFilters
()
{
function
i
nitFilters
()
{
OldFilterLengths
=
[];
LastFilter
=
0
;
Filters
=
[];
...
...
@@ -658,13 +658,14 @@ function InitFilters() {
*/
function
rarAddVMCode
(
firstByte
,
vmCode
)
{
VM
.
init
();
var
i
;
var
bstream
=
new
bitjs
.
io
.
BitStream
(
vmCode
.
buffer
,
true
/* rtl */
);
var
filtPos
;
if
(
firstByte
&
0x80
)
{
filtPos
=
RarVM
.
readData
(
bstream
);
if
(
filtPos
==
0
)
{
I
nitFilters
();
if
(
filtPos
==
=
0
)
{
i
nitFilters
();
}
else
{
filtPos
--
;
}
...
...
@@ -677,7 +678,7 @@ function rarAddVMCode(firstByte, vmCode) {
}
LastFilter
=
filtPos
;
var
newFilter
=
(
filtPos
==
Filters
.
length
);
var
newFilter
=
(
filtPos
==
=
Filters
.
length
);
// new filter for PrgStack
var
stackFilter
=
new
UnpackFilter
();
...
...
@@ -701,10 +702,10 @@ function rarAddVMCode(firstByte, vmCode) {
}
var
emptyCount
=
0
;
for
(
var
i
=
0
;
i
<
PrgStack
.
length
;
++
i
)
{
for
(
i
=
0
;
i
<
PrgStack
.
length
;
++
i
)
{
PrgStack
[
i
-
emptyCount
]
=
PrgStack
[
i
];
if
(
PrgStack
[
i
]
==
null
)
{
if
(
PrgStack
[
i
]
==
=
null
)
{
emptyCount
++
;
}
if
(
emptyCount
>
0
)
{
...
...
@@ -712,7 +713,7 @@ function rarAddVMCode(firstByte, vmCode) {
}
}
if
(
emptyCount
==
0
)
{
if
(
emptyCount
==
=
0
)
{
PrgStack
.
push
(
null
);
//PrgStack.Add(1);
emptyCount
=
1
;
}
...
...
@@ -734,12 +735,12 @@ function rarAddVMCode(firstByte, vmCode) {
OldFilterLengths
[
filtPos
]
:
0
;
}
stackFilter
.
NextWindow
=
(
wBuffer
.
ptr
!=
rBuffer
.
ptr
)
&&
stackFilter
.
NextWindow
=
(
wBuffer
.
ptr
!=
=
rBuffer
.
ptr
)
&&
(((
wBuffer
.
ptr
-
rBuffer
.
ptr
)
&
MAXWINMASK
)
<=
blockStart
);
OldFilterLengths
[
filtPos
]
=
stackFilter
.
BlockLength
;
for
(
var
i
=
0
;
i
<
7
;
++
i
)
{
for
(
i
=
0
;
i
<
7
;
++
i
)
{
stackFilter
.
Prg
.
InitR
[
i
]
=
0
;
}
stackFilter
.
Prg
.
InitR
[
3
]
=
VM_GLOBALMEMADDR
;
...
...
@@ -749,7 +750,7 @@ function rarAddVMCode(firstByte, vmCode) {
// set registers to optional parameters if any
if
(
firstByte
&
0x10
)
{
var
initMask
=
bstream
.
readBits
(
7
);
for
(
var
i
=
0
;
i
<
7
;
++
i
)
{
for
(
i
=
0
;
i
<
7
;
++
i
)
{
if
(
initMask
&
(
1
<<
i
))
{
stackFilter
.
Prg
.
InitR
[
i
]
=
RarVM
.
readData
(
bstream
);
}
...
...
@@ -758,11 +759,11 @@ function rarAddVMCode(firstByte, vmCode) {
if
(
newFilter
)
{
var
vmCodeSize
=
RarVM
.
readData
(
bstream
);
if
(
vmCodeSize
>=
0x10000
||
vmCodeSize
==
0
)
{
if
(
vmCodeSize
>=
0x10000
||
vmCodeSize
==
=
0
)
{
return
false
;
}
v
ar
v
mCode
=
new
Uint8Array
(
vmCodeSize
);
for
(
var
i
=
0
;
i
<
vmCodeSize
;
++
i
)
{
vmCode
=
new
Uint8Array
(
vmCodeSize
);
for
(
i
=
0
;
i
<
vmCodeSize
;
++
i
)
{
//if (Inp.Overflow(3))
// return(false);
vmCode
[
i
]
=
bstream
.
readBits
(
8
);
...
...
@@ -775,7 +776,7 @@ function rarAddVMCode(firstByte, vmCode) {
var
staticDataSize
=
filter
.
Prg
.
StaticData
.
length
;
if
(
staticDataSize
>
0
&&
staticDataSize
<
VM_GLOBALMEMSIZE
)
{
// read statically defined data contained in DB commands
for
(
var
i
=
0
;
i
<
staticDataSize
;
++
i
)
{
for
(
i
=
0
;
i
<
staticDataSize
;
++
i
)
{
stackFilter
.
Prg
.
StaticData
[
i
]
=
filter
.
Prg
.
StaticData
[
i
];
}
}
...
...
@@ -785,14 +786,14 @@ function rarAddVMCode(firstByte, vmCode) {
}
var
globalData
=
stackFilter
.
Prg
.
GlobalData
;
for
(
var
i
=
0
;
i
<
7
;
++
i
)
{
for
(
i
=
0
;
i
<
7
;
++
i
)
{
VM
.
setLowEndianValue
(
globalData
,
stackFilter
.
Prg
.
InitR
[
i
],
i
*
4
);
}
VM
.
setLowEndianValue
(
globalData
,
stackFilter
.
BlockLength
,
0x1c
);
VM
.
setLowEndianValue
(
globalData
,
0
,
0x20
);
VM
.
setLowEndianValue
(
globalData
,
stackFilter
.
ExecCount
,
0x2c
);
for
(
var
i
=
0
;
i
<
16
;
++
i
)
{
for
(
i
=
0
;
i
<
16
;
++
i
)
{
globalData
[
0x30
+
i
]
=
0
;
}
...
...
@@ -816,7 +817,7 @@ function rarAddVMCode(firstByte, vmCode) {
globalData
=
newGlobalData
;
}
//byte *GlobalData=&StackFilter->Prg.GlobalData[VM_FIXEDGLOBALSIZE];
for
(
var
i
=
0
;
i
<
dataSize
;
++
i
)
{
for
(
i
=
0
;
i
<
dataSize
;
++
i
)
{
//if (Inp.Overflow(3))
// return(false);
globalData
[
VM_FIXEDGLOBALSIZE
+
i
]
=
bstream
.
readBits
(
8
);
...
...
@@ -833,9 +834,9 @@ function rarAddVMCode(firstByte, vmCode) {
function
rarReadVMCode
(
bstream
)
{
var
firstByte
=
bstream
.
readBits
(
8
);
var
length
=
(
firstByte
&
7
)
+
1
;
if
(
length
==
7
)
{
if
(
length
==
=
7
)
{
length
=
bstream
.
readBits
(
8
)
+
7
;
}
else
if
(
length
==
8
)
{
}
else
if
(
length
==
=
8
)
{
length
=
bstream
.
readBits
(
16
);
}
...
...
@@ -845,7 +846,7 @@ function rarReadVMCode(bstream) {
// Do something here with checking readbuf.
vmCode
[
i
]
=
bstream
.
readBits
(
8
);
}
return
R
arAddVMCode
(
firstByte
,
vmCode
);
return
r
arAddVMCode
(
firstByte
,
vmCode
);
}
/**
...
...
@@ -946,7 +947,7 @@ function unpack29(bstream) {
continue
;
}
if
(
num
===
258
)
{
if
(
lastLength
!=
0
)
{
if
(
lastLength
!=
=
0
)
{
rarCopyString
(
lastLength
,
lastDist
);
}
continue
;
...
...
@@ -955,8 +956,8 @@ function unpack29(bstream) {
var
DistNum
=
num
-
259
;
Distance
=
rOldDist
[
DistNum
];
for
(
var
I
=
DistNum
;
I
>
0
;
I
--
)
{
rOldDist
[
I
]
=
rOldDist
[
I
-
1
];
for
(
var
I
2
=
DistNum
;
I2
>
0
;
I2
--
)
{
rOldDist
[
I
2
]
=
rOldDist
[
I2
-
1
];
}
rOldDist
[
0
]
=
Distance
;
...
...
@@ -990,10 +991,11 @@ function unpack29(bstream) {
*/
function
rarWriteBuf
()
{
var
writeSize
=
(
rBuffer
.
ptr
&
MAXWINMASK
);
var
j
;
var
flt
;
for
(
var
i
=
0
;
i
<
PrgStack
.
length
;
++
i
)
{
var
flt
=
PrgStack
[
i
];
if
(
flt
==
null
)
{
flt
=
PrgStack
[
i
];
if
(
flt
==
=
null
)
{
continue
;
}
...
...
@@ -1004,17 +1006,18 @@ function rarWriteBuf() {
var
blockStart
=
flt
.
BlockStart
;
var
blockLength
=
flt
.
BlockLength
;
var
parentPrg
;
// WrittenBorder = wBuffer.ptr
if
(((
blockStart
-
wBuffer
.
ptr
)
&
MAXWINMASK
)
<
writeSize
)
{
if
(
wBuffer
.
ptr
!=
blockStart
)
{
if
(
wBuffer
.
ptr
!=
=
blockStart
)
{
// Copy blockStart bytes from rBuffer into wBuffer.
rarWriteArea
(
wBuffer
.
ptr
,
blockStart
);
writeSize
=
(
rBuffer
.
ptr
-
wBuffer
.
ptr
)
&
MAXWINMASK
;
}
if
(
blockLength
<=
writeSize
)
{
var
blockEnd
=
(
blockStart
+
blockLength
)
&
MAXWINMASK
;
if
(
blockStart
<
blockEnd
||
blockEnd
==
0
)
{
if
(
blockStart
<
blockEnd
||
blockEnd
==
=
0
)
{
VM
.
setMemory
(
0
,
rBuffer
.
data
.
subarray
(
blockStart
,
blockStart
+
blockLength
),
blockLength
);
}
else
{
var
firstPartLength
=
MAXWINSIZE
-
blockStart
;
...
...
@@ -1022,7 +1025,7 @@ function rarWriteBuf() {
VM
.
setMemory
(
firstPartLength
,
rBuffer
.
data
,
blockEnd
);
}
var
parentPrg
=
Filters
[
flt
.
ParentFilter
].
Prg
;
parentPrg
=
Filters
[
flt
.
ParentFilter
].
Prg
;
var
prg
=
flt
.
Prg
;
if
(
parentPrg
.
GlobalData
.
length
>
VM_FIXEDGLOBALSIZE
)
{
...
...
@@ -1031,10 +1034,11 @@ function rarWriteBuf() {
}
rarExecuteCode
(
prg
);
var
globalDataLen
;
if
(
prg
.
GlobalData
.
length
>
VM_FIXEDGLOBALSIZE
)
{
// Save global data for next script execution.
var
globalDataLen
=
prg
.
GlobalData
.
length
;
globalDataLen
=
prg
.
GlobalData
.
length
;
if
(
parentPrg
.
GlobalData
.
length
<
globalDataLen
)
{
parentPrg
.
GlobalData
=
new
Uint8Array
(
globalDataLen
);
}
...
...
@@ -1050,8 +1054,8 @@ function rarWriteBuf() {
PrgStack
[
i
]
=
null
;
while
(
i
+
1
<
PrgStack
.
length
)
{
var
nextFilter
=
PrgStack
[
i
+
1
];
if
(
nextFilter
==
null
||
nextFilter
.
BlockStart
!
=
blockStart
||
nextFilter
.
BlockLength
!=
filteredData
.
length
||
nextFilter
.
NextWindow
)
{
if
(
nextFilter
==
=
null
||
nextFilter
.
BlockStart
!=
=
blockStart
||
nextFilter
.
BlockLength
!=
=
filteredData
.
length
||
nextFilter
.
NextWindow
)
{
break
;
}
...
...
@@ -1059,10 +1063,10 @@ function rarWriteBuf() {
VM
.
setMemory
(
0
,
filteredData
,
filteredData
.
length
);
var
parentPrg
=
Filters
[
nextFilter
.
ParentFilter
].
Prg
;
parentPrg
=
Filters
[
nextFilter
.
ParentFilter
].
Prg
;
var
nextPrg
=
nextFilter
.
Prg
;
var
globalDataLen
=
parentPrg
.
GlobalData
.
length
;
globalDataLen
=
parentPrg
.
GlobalData
.
length
;
if
(
globalDataLen
>
VM_FIXEDGLOBALSIZE
)
{
// Copy global data from previous script execution if any.
nextPrg
.
GlobalData
=
new
Uint8Array
(
globalDataLen
);
...
...
@@ -1073,7 +1077,7 @@ function rarWriteBuf() {
if
(
nextPrg
.
GlobalData
.
length
>
VM_GLOBALMEMSIZE
)
{
// Save global data for next script execution.
var
globalDataLen
=
nextPrg
.
GlobalData
.
length
;
globalDataLen
=
nextPrg
.
GlobalData
.
length
;
if
(
parentPrg
.
GlobalData
.
length
<
globalDataLen
)
{
parentPrg
.
GlobalData
=
new
Uint8Array
(
globalDataLen
);
}
...
...
@@ -1089,15 +1093,14 @@ function rarWriteBuf() {
PrgStack
[
i
]
=
null
;
}
// while (i + 1 < PrgStack.length)
for
(
var
j
=
0
;
j
<
filteredData
.
length
;
++
j
)
{
for
(
j
=
0
;
j
<
filteredData
.
length
;
++
j
)
{
wBuffer
.
insertByte
(
filteredData
[
j
]);
}
writeSize
=
(
rBuffer
.
ptr
-
wBuffer
.
ptr
)
&
MAXWINMASK
;
}
// if (blockLength <= writeSize)
else
{
for
(
var
j
=
i
;
j
<
PrgStack
.
length
;
++
j
)
{
var
flt
=
PrgStack
[
j
];
if
(
flt
!=
null
&&
flt
.
NextWindow
)
{
}
else
{
// if (blockLength <= writeSize)
for
(
j
=
i
;
j
<
PrgStack
.
length
;
++
j
)
{
flt
=
PrgStack
[
j
];
if
(
flt
!==
null
&&
flt
.
NextWindow
)
{
flt
.
NextWindow
=
false
;
}
}
...
...
@@ -1121,7 +1124,7 @@ function rarWriteBuf() {
*/
function
rarWriteArea
(
startPtr
,
endPtr
)
{
if
(
endPtr
<
startPtr
)
{
console
.
error
(
'endPtr < startPtr, endPtr='
+
endPtr
+
', startPtr='
+
startPtr
);
console
.
error
(
"endPtr < startPtr, endPtr="
+
endPtr
+
", startPtr="
+
startPtr
);
// rarWriteData(startPtr, -(int)StartPtr & MAXWINMASK);
// RarWriteData(0, endPtr);
return
;
...
...
@@ -1173,7 +1176,7 @@ function rarReadEndOfBlock(bstream) {
NewTable
=
!!
bstream
.
readBits
(
1
);
}
//tablesRead = !NewTable;
return
!
(
NewFile
||
NewTable
&&
!
rarReadTables
(
bstream
));
return
!
(
NewFile
||
(
NewTable
&&
!
rarReadTables
(
bstream
)
));
}
function
rarInsertLastMatch
(
length
,
distance
)
{
...
...
@@ -1220,8 +1223,8 @@ function rarCopyString(length, distance) {
function
unpack
(
v
)
{
// TODO: implement what happens when unpVer is < 15
var
Ver
=
v
.
header
.
unpVer
<=
15
?
15
:
v
.
header
.
unpVer
;
var
Solid
=
v
.
header
.
LHD_SOLID
;
var
bstream
=
new
bitjs
.
io
.
BitStream
(
v
.
fileData
.
buffer
,
true
/* rtl */
,
v
.
fileData
.
byteOffset
,
v
.
fileData
.
byteLength
);
//
var Solid = v.header.LHD_SOLID;
var
bstream
=
new
bitjs
.
io
.
BitStream
(
v
.
fileData
.
buffer
,
true
/* rtl */
,
v
.
fileData
.
byteOffset
,
v
.
fileData
.
byteLength
);
rBuffer
=
new
bitjs
.
io
.
ByteBuffer
(
v
.
header
.
unpackedSize
);
...
...
@@ -1252,7 +1255,7 @@ 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
)
{
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 "
);
}
else
{
...
...
@@ -1306,7 +1309,7 @@ var unrar = function(arrayBuffer) {
info
(
"Found RAR signature"
);
var
mhead
=
new
RarVolumeHeader
(
bstream
);
if
(
mhead
.
headType
!=
MAIN_HEAD
)
{
if
(
mhead
.
headType
!=
=
MAIN_HEAD
)
{
info
(
"Error! RAR did not include a MAIN_HEAD header"
);
}
else
{
var
localFiles
=
[];
...
...
cps/static/js/archive/untar.js
View file @
cd546eb6
...
...
@@ -10,9 +10,11 @@
* TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html
*/
/* global bitjs, importScripts, Uint8Array */
// This file expects to be invoked as a Worker (see onmessage below).
importScripts
(
'../io/bytestream.js'
);
importScripts
(
'archive.js'
);
importScripts
(
"../io/bytestream.js"
);
importScripts
(
"archive.js"
);
// Progress variables.
var
currentFilename
=
""
;
...
...
@@ -21,6 +23,7 @@ var currentBytesUnarchivedInFile = 0;
var
currentBytesUnarchived
=
0
;
var
totalUncompressedBytesInArchive
=
0
;
var
totalFilesInArchive
=
0
;
var
allLocalFiles
=
[];
// Helper functions.
var
info
=
function
(
str
)
{
...
...
@@ -44,7 +47,7 @@ var postProgress = function() {
currentBytesUnarchivedInFile
,
currentBytesUnarchived
,
totalUncompressedBytesInArchive
,
totalFilesInArchive
,
totalFilesInArchive
));
};
...
...
@@ -66,7 +69,7 @@ var TarLocalFile = function(bstream) {
this
.
linkname
=
readCleanString
(
bstream
,
100
);
this
.
maybeMagic
=
readCleanString
(
bstream
,
6
);
if
(
this
.
maybeMagic
==
"ustar"
)
{
if
(
this
.
maybeMagic
==
=
"ustar"
)
{
this
.
version
=
readCleanString
(
bstream
,
2
);
this
.
uname
=
readCleanString
(
bstream
,
32
);
this
.
gname
=
readCleanString
(
bstream
,
32
);
...
...
@@ -103,14 +106,14 @@ var TarLocalFile = function(bstream) {
}
// Round up to 512-byte blocks.
var
remaining
=
512
-
bytesRead
%
512
;
var
remaining
=
512
-
(
bytesRead
%
512
)
;
if
(
remaining
>
0
&&
remaining
<
512
)
{
bstream
.
readBytes
(
remaining
);
}
}
else
if
(
this
.
typeflag
==
5
)
{
info
(
" This is a directory."
);
}
}
}
;
var
untar
=
function
(
arrayBuffer
)
{
postMessage
(
new
bitjs
.
archive
.
UnarchiveStartEvent
());
...
...
@@ -125,7 +128,7 @@ var untar = function(arrayBuffer) {
var
bstream
=
new
bitjs
.
io
.
ByteStream
(
arrayBuffer
);
postProgress
();
// While we don't encounter an empty block, keep making TarLocalFiles.
while
(
bstream
.
peekNumber
(
4
)
!=
0
)
{
while
(
bstream
.
peekNumber
(
4
)
!=
=
0
)
{
var
oneLocalFile
=
new
TarLocalFile
(
bstream
);
if
(
oneLocalFile
&&
oneLocalFile
.
isValid
)
{
// If we make it to this point and haven't thrown an error, we have successfully
...
...
@@ -159,8 +162,8 @@ onmessage = function(event) {
// Overrun the buffer.
// unarchiveState = UnarchiveState.WAITING;
}
else
{
console
.
erro
r
(
"Found an error while untarring"
);
console
.
log
(
e
);
er
r
(
"Found an error while untarring"
);
err
(
e
);
throw
e
;
}
}
...
...
cps/static/js/archive/unzip.js
View file @
cd546eb6
...
...
@@ -14,10 +14,10 @@
/* global bitjs, importScripts, Uint8Array*/
// This file expects to be invoked as a Worker (see onmessage below).
importScripts
(
'../io/bitstream.js'
);
importScripts
(
'../io/bytebuffer.js'
);
importScripts
(
'../io/bytestream.js'
);
importScripts
(
'archive.js'
);
importScripts
(
"../io/bitstream.js"
);
importScripts
(
"../io/bytebuffer.js"
);
importScripts
(
"../io/bytestream.js"
);
importScripts
(
"archive.js"
);
// Progress variables.
var
currentFilename
=
""
;
...
...
@@ -118,13 +118,11 @@ ZipLocalFile.prototype.unzip = function() {
currentBytesUnarchivedInFile
=
this
.
compressedSize
;
currentBytesUnarchived
+=
this
.
compressedSize
;
this
.
fileData
=
zeroCompression
(
this
.
fileData
,
this
.
uncompressedSize
);
}
}
else
if
(
this
.
compressionMethod
===
8
)
{
// version == 20, compression method == 8 (DEFLATE)
else
if
(
this
.
compressionMethod
===
8
)
{
info
(
"ZIP v2.0, DEFLATE: "
+
this
.
filename
+
" ("
+
this
.
compressedSize
+
" bytes)"
);
this
.
fileData
=
inflate
(
this
.
fileData
,
this
.
uncompressedSize
);
}
else
{
}
else
{
err
(
"UNSUPPORTED VERSION/FORMAT: ZIP v"
+
this
.
version
+
", compression method="
+
this
.
compressionMethod
+
": "
+
this
.
filename
+
" ("
+
this
.
compressedSize
+
" bytes)"
);
this
.
fileData
=
null
;
}
...
...
@@ -497,13 +495,11 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
// copy literal byte to output
buffer
.
insertByte
(
symbol
);
blockSize
++
;
}
else
{
}
else
{
// end of block reached
if
(
symbol
===
256
)
{
break
;
}
else
{
}
else
{
var
lengthLookup
=
LengthLookupTable
[
symbol
-
257
],
length
=
lengthLookup
[
1
]
+
bstream
.
readBits
(
lengthLookup
[
0
]),
distLookup
=
DistLookupTable
[
decodeSymbol
(
bstream
,
hcDistanceTable
)],
...
...
@@ -566,7 +562,7 @@ function inflate(compressedData, numDecompressedBytes) {
blockSize
=
0
;
// ++numBlocks;
// no compression
if
(
bType
==
0
)
{
if
(
bType
==
=
0
)
{
// skip remaining bits in this byte
while
(
bstream
.
bitPtr
!==
0
)
bstream
.
readBits
(
1
);
var
len
=
bstream
.
readBits
(
16
);
...
...
@@ -575,13 +571,11 @@ function inflate(compressedData, numDecompressedBytes) {
if
(
len
>
0
)
buffer
.
insertBytes
(
bstream
.
readBytes
(
len
));
blockSize
=
len
;
}
}
else
if
(
bType
===
1
)
{
// fixed Huffman codes
else
if
(
bType
===
1
)
{
blockSize
=
inflateBlockData
(
bstream
,
getFixedLiteralTable
(),
getFixedDistanceTable
(),
buffer
);
}
}
else
if
(
bType
===
2
)
{
// dynamic Huffman codes
else
if
(
bType
===
2
)
{
var
numLiteralLengthCodes
=
bstream
.
readBits
(
5
)
+
257
;
var
numDistanceCodes
=
bstream
.
readBits
(
5
)
+
1
,
numCodeLengthCodes
=
bstream
.
readBits
(
4
)
+
4
;
...
...
cps/static/js/io/bitstream.js
100644 → 100755
View file @
cd546eb6
...
...
@@ -8,6 +8,9 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
*/
/* global bitjs, Uint8Array */
var
bitjs
=
bitjs
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
...
...
@@ -30,20 +33,20 @@ bitjs.io = bitjs.io || {};
* @param {ArrayBuffer} ab An ArrayBuffer object or a Uint8Array.
* @param {boolean} rtl Whether the stream reads bits from the byte starting
* from bit 7 to 0 (true) or bit 0 to 7 (false).
* @param {Number} opt
_o
ffset The offset into the ArrayBuffer
* @param {Number} opt
_l
ength The length of this BitStream
* @param {Number} opt
O
ffset The offset into the ArrayBuffer
* @param {Number} opt
L
ength The length of this BitStream
*/
bitjs
.
io
.
BitStream
=
function
(
ab
,
rtl
,
opt
_offset
,
opt_l
ength
)
{
bitjs
.
io
.
BitStream
=
function
(
ab
,
rtl
,
opt
Offset
,
optL
ength
)
{
if
(
!
ab
||
!
ab
.
toString
||
ab
.
toString
()
!==
"[object ArrayBuffer]"
)
{
throw
"Error! BitArray constructed with an invalid ArrayBuffer object"
;
}
var
offset
=
opt
_o
ffset
||
0
;
var
length
=
opt
_l
ength
||
ab
.
byteLength
;
var
offset
=
opt
O
ffset
||
0
;
var
length
=
opt
L
ength
||
ab
.
byteLength
;
this
.
bytes
=
new
Uint8Array
(
ab
,
offset
,
length
);
this
.
bytePtr
=
0
;
// tracks which byte we are on
this
.
bitPtr
=
0
;
// tracks which bit we are on (can have values 0 through 7)
this
.
peekBits
=
rtl
?
this
.
peekBits
_rtl
:
this
.
peekBits_l
tr
;
this
.
peekBits
=
rtl
?
this
.
peekBits
Rtl
:
this
.
peekBitsL
tr
;
};
...
...
@@ -57,8 +60,8 @@ bitjs.io = bitjs.io || {};
* @param {boolean=} movePointers Whether to move the pointer, defaults false.
* @return {number} The peeked bits, as an unsigned number.
*/
bitjs
.
io
.
BitStream
.
prototype
.
peekBits
_l
tr
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
bitjs
.
io
.
BitStream
.
prototype
.
peekBits
L
tr
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
0
;
}
...
...
@@ -77,12 +80,13 @@ bitjs.io = bitjs.io || {};
if
(
bytePtr
>=
bytes
.
length
)
{
throw
"Error! Overflowed the bit stream! n="
+
n
+
", bytePtr="
+
bytePtr
+
", bytes.length="
+
bytes
.
length
+
", bitPtr="
+
bitPtr
;
return
-
1
;
//
return -1;
}
var
numBitsLeftInThisByte
=
(
8
-
bitPtr
);
var
mask
;
if
(
n
>=
numBitsLeftInThisByte
)
{
var
mask
=
(
BITMASK
[
numBitsLeftInThisByte
]
<<
bitPtr
);
mask
=
(
BITMASK
[
numBitsLeftInThisByte
]
<<
bitPtr
);
result
|=
(((
bytes
[
bytePtr
]
&
mask
)
>>
bitPtr
)
<<
bitsIn
);
bytePtr
++
;
...
...
@@ -90,7 +94,7 @@ bitjs.io = bitjs.io || {};
bitsIn
+=
numBitsLeftInThisByte
;
n
-=
numBitsLeftInThisByte
;
}
else
{
var
mask
=
(
BITMASK
[
n
]
<<
bitPtr
);
mask
=
(
BITMASK
[
n
]
<<
bitPtr
);
result
|=
(((
bytes
[
bytePtr
]
&
mask
)
>>
bitPtr
)
<<
bitsIn
);
bitPtr
+=
n
;
...
...
@@ -118,8 +122,8 @@ bitjs.io = bitjs.io || {};
* @param {boolean=} movePointers Whether to move the pointer, defaults false.
* @return {number} The peeked bits, as an unsigned number.
*/
bitjs
.
io
.
BitStream
.
prototype
.
peekBits
_r
tl
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
bitjs
.
io
.
BitStream
.
prototype
.
peekBits
R
tl
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
0
;
}
...
...
@@ -138,7 +142,7 @@ bitjs.io = bitjs.io || {};
if
(
bytePtr
>=
bytes
.
length
)
{
throw
"Error! Overflowed the bit stream! n="
+
n
+
", bytePtr="
+
bytePtr
+
", bytes.length="
+
bytes
.
length
+
", bitPtr="
+
bitPtr
;
return
-
1
;
//
return -1;
}
var
numBitsLeftInThisByte
=
(
8
-
bitPtr
);
...
...
@@ -198,19 +202,19 @@ bitjs.io = bitjs.io || {};
* @return {Uint8Array} The subarray.
*/
bitjs
.
io
.
BitStream
.
prototype
.
peekBytes
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
0
;
}
// from http://tools.ietf.org/html/rfc1951#page-11
// "Any bits of input up to the next byte boundary are ignored."
while
(
this
.
bitPtr
!=
0
)
{
while
(
this
.
bitPtr
!=
=
0
)
{
this
.
readBits
(
1
);
}
var
movePointers
=
movePointers
||
false
;
var
bytePtr
=
this
.
bytePtr
,
bitPtr
=
this
.
bitPtr
;
var
bytePtr
=
this
.
bytePtr
;
//
bitPtr = this.bitPtr;
var
result
=
this
.
bytes
.
subarray
(
bytePtr
,
bytePtr
+
n
);
...
...
cps/static/js/io/bytebuffer.js
View file @
cd546eb6
...
...
@@ -8,6 +8,9 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
*/
/* global bitjs, Uint8Array */
var
bitjs
=
bitjs
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
...
...
@@ -20,7 +23,7 @@ bitjs.io = bitjs.io || {};
* @constructor
*/
bitjs
.
io
.
ByteBuffer
=
function
(
numBytes
)
{
if
(
typeof
numBytes
!=
typeof
1
||
numBytes
<=
0
)
{
if
(
typeof
numBytes
!=
=
typeof
1
||
numBytes
<=
0
)
{
throw
"Error! ByteBuffer initialized with '"
+
numBytes
+
"'"
;
}
this
.
data
=
new
Uint8Array
(
numBytes
);
...
...
@@ -55,14 +58,14 @@ bitjs.io = bitjs.io || {};
*/
bitjs
.
io
.
ByteBuffer
.
prototype
.
writeNumber
=
function
(
num
,
numBytes
)
{
if
(
numBytes
<
1
)
{
throw
'Trying to write into too few bytes: '
+
numBytes
;
throw
"Trying to write into too few bytes: "
+
numBytes
;
}
if
(
num
<
0
)
{
throw
'Trying to write a negative number ('
+
num
+
') as an unsigned number to an ArrayBuffer'
;
throw
"Trying to write a negative number ("
+
num
+
") as an unsigned number to an ArrayBuffer"
;
}
if
(
num
>
(
Math
.
pow
(
2
,
numBytes
*
8
)
-
1
))
{
throw
'Trying to write '
+
num
+
' into only '
+
numBytes
+
' bytes'
;
throw
"Trying to write "
+
num
+
" into only "
+
numBytes
+
" bytes"
;
}
// Roll 8-bits at a time into an array of bytes.
...
...
@@ -85,12 +88,12 @@ bitjs.io = bitjs.io || {};
*/
bitjs
.
io
.
ByteBuffer
.
prototype
.
writeSignedNumber
=
function
(
num
,
numBytes
)
{
if
(
numBytes
<
1
)
{
throw
'Trying to write into too few bytes: '
+
numBytes
;
throw
"Trying to write into too few bytes: "
+
numBytes
;
}
var
HALF
=
Math
.
pow
(
2
,
(
numBytes
*
8
)
-
1
);
if
(
num
>=
HALF
||
num
<
-
HALF
)
{
throw
'Trying to write '
+
num
+
' into only '
+
numBytes
+
' bytes'
;
throw
"Trying to write "
+
num
+
" into only "
+
numBytes
+
" bytes"
;
}
// Roll 8-bits at a time into an array of bytes.
...
...
@@ -112,7 +115,7 @@ bitjs.io = bitjs.io || {};
for
(
var
i
=
0
;
i
<
str
.
length
;
++
i
)
{
var
curByte
=
str
.
charCodeAt
(
i
);
if
(
curByte
<
0
||
curByte
>
255
)
{
throw
'Trying to write a non-ASCII string!'
;
throw
"Trying to write a non-ASCII string!"
;
}
this
.
insertByte
(
curByte
);
}
...
...
cps/static/js/io/bytestream.js
View file @
cd546eb6
...
...
@@ -8,6 +8,9 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
*/
/* global bitjs, Uint8Array */
var
bitjs
=
bitjs
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
...
...
@@ -19,13 +22,13 @@ bitjs.io = bitjs.io || {};
* out of an ArrayBuffer. In this buffer, everything must be byte-aligned.
*
* @param {ArrayBuffer} ab The ArrayBuffer object.
* @param {number=} opt
_o
ffset The offset into the ArrayBuffer
* @param {number=} opt
_l
ength The length of this BitStream
* @param {number=} opt
O
ffset The offset into the ArrayBuffer
* @param {number=} opt
L
ength The length of this BitStream
* @constructor
*/
bitjs
.
io
.
ByteStream
=
function
(
ab
,
opt
_offset
,
opt_l
ength
)
{
var
offset
=
opt
_o
ffset
||
0
;
var
length
=
opt
_l
ength
||
ab
.
byteLength
;
bitjs
.
io
.
ByteStream
=
function
(
ab
,
opt
Offset
,
optL
ength
)
{
var
offset
=
opt
O
ffset
||
0
;
var
length
=
opt
L
ength
||
ab
.
byteLength
;
this
.
bytes
=
new
Uint8Array
(
ab
,
offset
,
length
);
this
.
ptr
=
0
;
};
...
...
@@ -40,8 +43,9 @@ bitjs.io = bitjs.io || {};
*/
bitjs
.
io
.
ByteStream
.
prototype
.
peekNumber
=
function
(
n
)
{
// TODO: return error if n would go past the end of the stream?
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
-
1
;
}
var
result
=
0
;
// read from last byte to first byte and roll them in
...
...
@@ -105,7 +109,7 @@ bitjs.io = bitjs.io || {};
* @return {Uint8Array} The subarray.
*/
bitjs
.
io
.
ByteStream
.
prototype
.
peekBytes
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
null
;
}
...
...
@@ -135,7 +139,7 @@ bitjs.io = bitjs.io || {};
* @return {string} The next n bytes as a string.
*/
bitjs
.
io
.
ByteStream
.
prototype
.
peekString
=
function
(
n
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
""
;
}
...
...
cps/static/js/kthoom.js
View file @
cd546eb6
...
...
@@ -15,7 +15,10 @@
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
*/
/* global screenfull, bitjs */
/* global screenfull, bitjs, Uint8Array, opera */
/* exported init, event */
if
(
window
.
opera
)
{
window
.
console
.
log
=
function
(
str
)
{
opera
.
postError
(
str
);
...
...
@@ -101,12 +104,12 @@ kthoom.setSettings = function() {
var
createURLFromArray
=
function
(
array
,
mimeType
)
{
var
offset
=
array
.
byteOffset
;
var
len
=
array
.
byteLength
;
var
url
;
//
var url;
var
blob
;
if
(
mimeType
===
'image/xml+svg'
)
{
const
xmlStr
=
new
TextDecoder
(
'utf-8'
).
decode
(
array
);
return
'data:image/svg+xml;UTF-8,'
+
encodeURIComponent
(
xmlStr
);
if
(
mimeType
===
"image/xml+svg"
)
{
var
xmlStr
=
new
TextDecoder
(
"utf-8"
).
decode
(
array
);
return
"data:image/svg+xml;UTF-8,"
+
encodeURIComponent
(
xmlStr
);
}
// TODO: Move all this browser support testing to a common place
...
...
@@ -140,7 +143,7 @@ kthoom.ImageFile = function(file) {
var
fileExtension
=
file
.
filename
.
split
(
"."
).
pop
().
toLowerCase
();
this
.
mimeType
=
fileExtension
===
"png"
?
"image/png"
:
(
fileExtension
===
"jpg"
||
fileExtension
===
"jpeg"
)
?
"image/jpeg"
:
fileExtension
===
"gif"
?
"image/gif"
:
fileExtension
==
'svg'
?
'image/xml+svg'
:
undefined
;
fileExtension
===
"gif"
?
"image/gif"
:
fileExtension
==
=
"svg"
?
"image/xml+svg"
:
undefined
;
if
(
this
.
mimeType
!==
undefined
)
{
this
.
dataURI
=
createURLFromArray
(
file
.
fileData
,
this
.
mimeType
);
this
.
data
=
file
;
...
...
@@ -154,17 +157,18 @@ function initProgressClick() {
currentImage
=
page
;
updatePage
();
});
}
;
}
function
loadFromArrayBuffer
(
ab
)
{
var
start
=
(
new
Date
).
getTime
();
var
h
=
new
Uint8Array
(
ab
,
0
,
10
);
var
pathToBitJS
=
"../../static/js/archive/"
;
var
lastCompletion
=
0
;
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
if
(
h
[
0
]
==
255
&&
h
[
1
]
==
216
)
{
// JPEG
}
else
if
(
h
[
0
]
==
=
255
&&
h
[
1
]
=
==
216
)
{
// JPEG
// ToDo: check
updateProgress
(
100
);
lastCompletion
=
100
;
...
...
@@ -180,12 +184,12 @@ function loadFromArrayBuffer(ab) {
if
(
totalImages
===
0
)
{
totalImages
=
e
.
totalFilesInArchive
;
}
updateProgress
(
percentage
*
100
);
updateProgress
(
percentage
*
100
);
lastCompletion
=
percentage
*
100
;
});
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
INFO
,
function
(
e
)
{
// console.log(e.msg);
77
Enable debug output here
// console.log(e.msg);
//
Enable debug output here
});
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
EXTRACT
,
function
(
e
)
{
...
...
@@ -211,8 +215,7 @@ function loadFromArrayBuffer(ab) {
if
(
imageFiles
.
length
===
currentImage
+
1
)
{
updatePage
(
lastCompletion
);
}
}
else
{
}
else
{
totalImages
--
;
}
}
...
...
@@ -231,22 +234,22 @@ function loadFromArrayBuffer(ab) {
function
scrollTocToActive
()
{
// Scroll to the thumbnail in the TOC on page change
$
(
'#tocView'
).
stop
().
animate
({
scrollTop
:
$
(
'#tocView a.active'
).
position
().
top
$
(
"#tocView"
).
stop
().
animate
({
scrollTop
:
$
(
"#tocView a.active"
).
position
().
top
},
200
);
}
function
updatePage
()
{
$
(
'.page'
).
text
((
currentImage
+
1
)
+
"/"
+
totalImages
);
$
(
".page"
).
text
((
currentImage
+
1
)
+
"/"
+
totalImages
);
// Mark the current page in the TOC
$
(
'#tocView a[data-page]'
)
$
(
"#tocView a[data-page]"
)
// Remove the currently active thumbnail
.
removeClass
(
'active'
)
.
removeClass
(
"active"
)
// Find the new one
.
filter
(
'[data-page='
+
(
currentImage
+
1
)
+
']'
)
.
filter
(
"[data-page="
+
(
currentImage
+
1
)
+
"]"
)
// Set it to active
.
addClass
(
'active'
);
.
addClass
(
"active"
);
scrollTocToActive
();
updateProgress
();
...
...
@@ -270,8 +273,8 @@ function updateProgress(loadPercentage) {
if
(
loadPercentage
===
100
)
{
$
(
"#progress"
)
.
removeClass
(
'loading'
)
.
find
(
".load"
).
text
(
''
);
.
removeClass
(
"loading"
)
.
find
(
".load"
).
text
(
""
);
}
}
...
...
@@ -326,7 +329,7 @@ function setImage(url) {
xhr
.
onload
=
function
()
{
$
(
"#mainText"
).
css
(
"display"
,
""
);
$
(
"#mainText"
).
innerHTML
(
"<iframe style=
\"
width:100%;height:700px;border:0
\"
src=
\"
data:text/html,"
+
escape
(
xhr
.
responseText
)
+
"
\"
></iframe>"
);
}
}
;
xhr
.
send
(
null
);
}
else
if
(
!
/
(
jpg|jpeg|png|gif
)
$/
.
test
(
imageFiles
[
currentImage
].
filename
)
&&
imageFiles
[
currentImage
].
data
.
uncompressedSize
<
10
*
1024
)
{
xhr
.
open
(
"GET"
,
url
,
true
);
...
...
@@ -378,17 +381,17 @@ function setImage(url) {
function
showLeftPage
()
{
if
(
settings
.
direction
===
0
)
{
showPrevPage
()
showPrevPage
()
;
}
else
{
showNextPage
()
showNextPage
()
;
}
}
function
showRightPage
()
{
if
(
settings
.
direction
===
0
)
{
showNextPage
()
showNextPage
()
;
}
else
{
showPrevPage
()
showPrevPage
()
;
}
}
...
...
@@ -504,7 +507,7 @@ function keyHandler(evt) {
updateScale
(
false
);
break
;
case
kthoom
.
Key
.
SPACE
:
var
container
=
$
(
'#mainContent'
);
var
container
=
$
(
"#mainContent"
);
var
atTop
=
container
.
scrollTop
()
===
0
;
var
atBottom
=
container
.
scrollTop
()
>=
container
[
0
].
scrollHeight
-
container
.
height
();
...
...
@@ -577,9 +580,9 @@ function init(filename) {
$
(
this
).
toggleClass
(
"icon-menu icon-right"
);
// We need this in a timeout because if we call it during the CSS transition, IE11 shakes the page ¯\_(ツ)_/¯
setTimeout
(
function
(){
setTimeout
(
function
()
{
// Focus on the TOC or the main content area, depending on which is open
$
(
'#main:not(.closed) #mainContent, #sidebar.open #tocView'
).
focus
();
$
(
"#main:not(.closed) #mainContent, #sidebar.open #tocView"
).
focus
();
scrollTocToActive
();
},
500
);
});
...
...
@@ -630,7 +633,7 @@ function init(filename) {
}
// Focus the scrollable area so that keyboard scrolling work as expected
$
(
'#mainContent'
).
focus
();
$
(
"#mainContent"
).
focus
();
$
(
"#mainImage"
).
click
(
function
(
evt
)
{
// Firefox does not support offsetX/Y so we have to manually calculate
...
...
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