-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-source-string.html
76 lines (73 loc) · 1.49 KB
/
file-source-string.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="file-source-string" constructor="fileSourceString">
<script>Polymer((function static(){
const ACCESSORS = {
source:{
set:function(data){
this.str = data.split("");
},
get:function(){
return this.str.join("");
}
}
};
const METHODS={
read:{
value:function(length) {
return this.str.splice(0,length).join("");
}
},
readInt32:{
value:function() {
return (
(this.str.shift().charCodeAt() << 3*8) +
(this.str.shift().charCodeAt() << 2*8) +
(this.str.shift().charCodeAt() << 1*8) +
(this.str.shift().charCodeAt() << 0*8)
);
}
},
readInt16:{
value:function() {
return (
(this.str.shift().charCodeAt() << 1*8) +
(this.str.shift().charCodeAt() << 0*8)
);
}
},
readInt8:{
value:function(signed) {
var result = this.str.shift().charCodeAt();
if(signed&&result>127)result-=256;
return result;
}
},
eof:{
value:function() {
return this.str.length <= 0;
}
},
readVarInt:{
value:function() {
var result = 0;
while (true) {
var b = this.readInt8();
if (b & 0x80) {
result += (b & 0x7f);
result <<= 7;
} else {
/* b is the last byte */
return result + b;
}
}
}
},
};
const PROTOTYPE={
};
Object.defineProperties(PROTOTYPE,ACCESSORS);
Object.defineProperties(PROTOTYPE,METHODS);
return PROTOTYPE;
})())/*
*/</script>
</polymer-element>