genoverse 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/.eslintrc.js +197 -0
  2. package/.github/workflows/test.yml +24 -0
  3. package/LICENSE.TXT +24 -0
  4. package/README.md +11 -0
  5. package/css/controlPanel.css +200 -0
  6. package/css/fileDrop.css +22 -0
  7. package/css/font-awesome.css +3 -0
  8. package/css/fullscreen.css +19 -0
  9. package/css/genoverse.css +466 -0
  10. package/css/karyotype.css +85 -0
  11. package/css/resizer.css +36 -0
  12. package/css/tooltips.css +26 -0
  13. package/css/trackControls.css +111 -0
  14. package/expanded.html +120 -0
  15. package/fontawesome/css/fontawesome.min.css +5 -0
  16. package/fontawesome/css/regular.min.css +5 -0
  17. package/fontawesome/css/solid.min.css +5 -0
  18. package/fontawesome/webfonts/fa-brands-400.ttf +0 -0
  19. package/fontawesome/webfonts/fa-brands-400.woff +0 -0
  20. package/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
  21. package/fontawesome/webfonts/fa-regular-400.ttf +0 -0
  22. package/fontawesome/webfonts/fa-regular-400.woff +0 -0
  23. package/fontawesome/webfonts/fa-regular-400.woff2 +0 -0
  24. package/fontawesome/webfonts/fa-solid-900.ttf +0 -0
  25. package/fontawesome/webfonts/fa-solid-900.woff +0 -0
  26. package/fontawesome/webfonts/fa-solid-900.woff2 +0 -0
  27. package/help.pdf +0 -0
  28. package/i/sort_handle.png +0 -0
  29. package/index.html +68 -0
  30. package/index.js +83 -0
  31. package/jest.config.js +4 -0
  32. package/js/Genoverse.js +1681 -0
  33. package/js/Track/Controller/Sequence.js +17 -0
  34. package/js/Track/Controller/Stranded.js +73 -0
  35. package/js/Track/Controller.js +620 -0
  36. package/js/Track/Model/File/BAM.js +44 -0
  37. package/js/Track/Model/File/BED.js +116 -0
  38. package/js/Track/Model/File/GFF.js +40 -0
  39. package/js/Track/Model/File/VCF.js +101 -0
  40. package/js/Track/Model/File/WIG.js +67 -0
  41. package/js/Track/Model/File.js +36 -0
  42. package/js/Track/Model/Gene/Ensembl.js +22 -0
  43. package/js/Track/Model/Gene.js +5 -0
  44. package/js/Track/Model/Sequence/Ensembl.js +4 -0
  45. package/js/Track/Model/Sequence/Fasta.js +60 -0
  46. package/js/Track/Model/Sequence.js +50 -0
  47. package/js/Track/Model/SequenceVariation.js +41 -0
  48. package/js/Track/Model/Stranded.js +28 -0
  49. package/js/Track/Model/Transcript/Ensembl.js +67 -0
  50. package/js/Track/Model/Transcript.js +5 -0
  51. package/js/Track/Model.js +303 -0
  52. package/js/Track/View/Gene/Ensembl.js +46 -0
  53. package/js/Track/View/Gene.js +6 -0
  54. package/js/Track/View/Sequence/Variation.js +115 -0
  55. package/js/Track/View/Sequence.js +63 -0
  56. package/js/Track/View/Transcript/Ensembl.js +12 -0
  57. package/js/Track/View/Transcript.js +28 -0
  58. package/js/Track/View.js +566 -0
  59. package/js/Track/library/Chromosome.js +145 -0
  60. package/js/Track/library/File/BAM.js +30 -0
  61. package/js/Track/library/File/BED.js +24 -0
  62. package/js/Track/library/File/BIGBED.js +47 -0
  63. package/js/Track/library/File/BIGWIG.js +52 -0
  64. package/js/Track/library/File/GFF.js +9 -0
  65. package/js/Track/library/File/VCF.js +71 -0
  66. package/js/Track/library/File/WIG.js +5 -0
  67. package/js/Track/library/File.js +10 -0
  68. package/js/Track/library/Gene.js +37 -0
  69. package/js/Track/library/Graph/Bar.js +235 -0
  70. package/js/Track/library/Graph/Line.js +296 -0
  71. package/js/Track/library/Graph.js +355 -0
  72. package/js/Track/library/HighlightRegion.js +292 -0
  73. package/js/Track/library/Legend.js +224 -0
  74. package/js/Track/library/Scalebar.js +227 -0
  75. package/js/Track/library/Scaleline.js +91 -0
  76. package/js/Track/library/Static.js +78 -0
  77. package/js/Track/library/dbSNP.js +142 -0
  78. package/js/Track.js +632 -0
  79. package/js/genomes/grch37.js +990 -0
  80. package/js/genomes/grch38.js +990 -0
  81. package/js/genoverse.min.js +2 -0
  82. package/js/genoverse.min.js.map +1 -0
  83. package/js/lib/BWReader.js +578 -0
  84. package/js/lib/Base.js +145 -0
  85. package/js/lib/VCFReader.js +286 -0
  86. package/js/lib/dalliance/js/bam.js +494 -0
  87. package/js/lib/dalliance/js/bin.js +185 -0
  88. package/js/lib/dalliance/js/das.js +749 -0
  89. package/js/lib/dalliance/js/utils.js +370 -0
  90. package/js/lib/dalliance-lib.js +3594 -0
  91. package/js/lib/dalliance-lib.min.js +68 -0
  92. package/js/lib/jDataView.js +2 -0
  93. package/js/lib/jParser.js +192 -0
  94. package/js/lib/jquery-ui.js +8 -0
  95. package/js/lib/jquery.js +2 -0
  96. package/js/lib/jquery.mousehold.js +53 -0
  97. package/js/lib/jquery.mousewheel.js +84 -0
  98. package/js/lib/jquery.tipsy.js +258 -0
  99. package/js/lib/rtree.js +1 -0
  100. package/js/plugins/controlPanel.js +395 -0
  101. package/js/plugins/fileDrop.js +62 -0
  102. package/js/plugins/focusRegion.js +12 -0
  103. package/js/plugins/fullscreen.js +77 -0
  104. package/js/plugins/karyotype.js +210 -0
  105. package/js/plugins/resizer.js +45 -0
  106. package/js/plugins/tooltips.js +94 -0
  107. package/js/plugins/trackControls.js +143 -0
  108. package/package.json +43 -0
  109. package/test/View/__snapshots__/render-bar-graph.test.js.snap +111 -0
  110. package/test/View/__snapshots__/render-blocks.test.js.snap +105 -0
  111. package/test/View/__snapshots__/render-chromosome.test.js.snap +5 -0
  112. package/test/View/__snapshots__/render-highlights.test.js.snap +73 -0
  113. package/test/View/__snapshots__/render-insert-variants.test.js.snap +9 -0
  114. package/test/View/__snapshots__/render-labels.test.js.snap +241 -0
  115. package/test/View/__snapshots__/render-legends.test.js.snap +13 -0
  116. package/test/View/__snapshots__/render-line-graph.test.js.snap +349 -0
  117. package/test/View/__snapshots__/render-scalebar.test.js.snap +49 -0
  118. package/test/View/__snapshots__/render-scaleline.test.js.snap +31 -0
  119. package/test/View/__snapshots__/render-sequence.test.js.snap +23 -0
  120. package/test/View/__snapshots__/render-stranded.test.js.snap +5 -0
  121. package/test/View/__snapshots__/render-transcripts.test.js.snap +193 -0
  122. package/test/View/render-bar-graph.test.js +87 -0
  123. package/test/View/render-blocks.test.js +171 -0
  124. package/test/View/render-chromosome.test.js +40 -0
  125. package/test/View/render-highlights.test.js +67 -0
  126. package/test/View/render-insert-variants.test.js +11 -0
  127. package/test/View/render-labels.test.js +266 -0
  128. package/test/View/render-legends.test.js +31 -0
  129. package/test/View/render-line-graph.test.js +169 -0
  130. package/test/View/render-scalebar.test.js +36 -0
  131. package/test/View/render-scaleline.test.js +28 -0
  132. package/test/View/render-sequence.test.js +49 -0
  133. package/test/View/render-stranded.test.js +10 -0
  134. package/test/View/render-transcripts.test.js +165 -0
  135. package/test/create-and-destroy.test.js +63 -0
  136. package/test/track-ordering.test.js +514 -0
  137. package/test/track_config/__snapshots__/config-settings.test.js.snap +23 -0
  138. package/test/track_config/config-settings.test.js +321 -0
  139. package/test/track_config/zoom-level-settings.test.js +98 -0
  140. package/test/utils.js +80 -0
  141. package/utils/createGenome.js +52 -0
  142. package/utils/devServer.js +36 -0
  143. package/utils/expandedTemplate.html +46 -0
  144. package/utils/git-hooks/post-commit +9 -0
  145. package/utils/git-hooks/pre-commit +7 -0
  146. package/utils/git-hooks/setup +6 -0
  147. package/utils/makeExpanded.js +19 -0
  148. package/webpack.config.js +39 -0
@@ -0,0 +1,3594 @@
1
+ (function () {
2
+ // Javascript ZLib
3
+ // By Thomas Down 2010-2011
4
+ //
5
+ // Based very heavily on portions of jzlib (by ymnk@jcraft.com), who in
6
+ // turn credits Jean-loup Gailly and Mark Adler for the original zlib code.
7
+ //
8
+ // inflate.js: ZLib inflate code
9
+ //
10
+ //
11
+ // Shared constants
12
+ //
13
+ var MAX_WBITS = 15; // 32K LZ77 window
14
+ var DEF_WBITS = MAX_WBITS;
15
+ var MAX_MEM_LEVEL = 9;
16
+ var MANY = 1440;
17
+ var BMAX = 15;
18
+
19
+ // preset dictionary flag in zlib header
20
+ var PRESET_DICT = 0x20;
21
+
22
+ var Z_NO_FLUSH = 0;
23
+ var Z_PARTIAL_FLUSH = 1;
24
+ var Z_SYNC_FLUSH = 2;
25
+ var Z_FULL_FLUSH = 3;
26
+ var Z_FINISH = 4;
27
+
28
+ var Z_DEFLATED = 8;
29
+
30
+ var Z_OK = 0;
31
+ var Z_STREAM_END = 1;
32
+ var Z_NEED_DICT = 2;
33
+ var Z_ERRNO = -1;
34
+ var Z_STREAM_ERROR = -2;
35
+ var Z_DATA_ERROR = -3;
36
+ var Z_MEM_ERROR = -4;
37
+ var Z_BUF_ERROR = -5;
38
+ var Z_VERSION_ERROR = -6;
39
+
40
+ var METHOD = 0; // waiting for method byte
41
+ var FLAG = 1; // waiting for flag byte
42
+ var DICT4 = 2; // four dictionary check bytes to go
43
+ var DICT3 = 3; // three dictionary check bytes to go
44
+ var DICT2 = 4; // two dictionary check bytes to go
45
+ var DICT1 = 5; // one dictionary check byte to go
46
+ var DICT0 = 6; // waiting for inflateSetDictionary
47
+ var BLOCKS = 7; // decompressing blocks
48
+ var CHECK4 = 8; // four check bytes to go
49
+ var CHECK3 = 9; // three check bytes to go
50
+ var CHECK2 = 10; // two check bytes to go
51
+ var CHECK1 = 11; // one check byte to go
52
+ var DONE = 12; // finished check, done
53
+ var BAD = 13; // got an error--stay here
54
+
55
+ var inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff];
56
+
57
+ var IB_TYPE = 0; // get type bits (3, including end bit)
58
+ var IB_LENS = 1; // get lengths for stored
59
+ var IB_STORED = 2; // processing stored block
60
+ var IB_TABLE = 3; // get table lengths
61
+ var IB_BTREE = 4; // get bit lengths tree for a dynamic block
62
+ var IB_DTREE = 5; // get length, distance trees for a dynamic block
63
+ var IB_CODES = 6; // processing fixed or dynamic block
64
+ var IB_DRY = 7; // output remaining window bytes
65
+ var IB_DONE = 8; // finished last block, done
66
+ var IB_BAD = 9; // ot a data error--stuck here
67
+
68
+ var fixed_bl = 9;
69
+ var fixed_bd = 5;
70
+
71
+ var fixed_tl = [
72
+ 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115,
73
+ 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192,
74
+ 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160,
75
+ 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 224,
76
+ 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144,
77
+ 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208,
78
+ 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 176,
79
+ 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240,
80
+ 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227,
81
+ 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200,
82
+ 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 168,
83
+ 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232,
84
+ 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152,
85
+ 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 216,
86
+ 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184,
87
+ 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248,
88
+ 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163,
89
+ 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 196,
90
+ 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164,
91
+ 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228,
92
+ 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 148,
93
+ 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212,
94
+ 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180,
95
+ 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244,
96
+ 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0,
97
+ 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204,
98
+ 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172,
99
+ 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 236,
100
+ 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156,
101
+ 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220,
102
+ 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188,
103
+ 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252,
104
+ 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131,
105
+ 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194,
106
+ 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 162,
107
+ 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226,
108
+ 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146,
109
+ 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210,
110
+ 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178,
111
+ 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242,
112
+ 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258,
113
+ 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 202,
114
+ 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170,
115
+ 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234,
116
+ 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154,
117
+ 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218,
118
+ 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186,
119
+ 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250,
120
+ 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195,
121
+ 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198,
122
+ 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166,
123
+ 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230,
124
+ 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150,
125
+ 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214,
126
+ 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182,
127
+ 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 246,
128
+ 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0,
129
+ 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206,
130
+ 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174,
131
+ 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238,
132
+ 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158,
133
+ 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222,
134
+ 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 190,
135
+ 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254,
136
+ 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115,
137
+ 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 193,
138
+
139
+ 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161,
140
+ 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225,
141
+ 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145,
142
+ 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 209,
143
+ 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177,
144
+ 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241,
145
+ 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227,
146
+ 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201,
147
+ 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169,
148
+ 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233,
149
+ 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 153,
150
+ 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217,
151
+ 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185,
152
+ 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 249,
153
+ 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163,
154
+ 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197,
155
+ 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165,
156
+ 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 229,
157
+ 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149,
158
+ 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213,
159
+ 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 181,
160
+ 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245,
161
+ 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0,
162
+ 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205,
163
+ 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 173,
164
+ 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237,
165
+ 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157,
166
+ 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 221,
167
+ 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189,
168
+ 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253,
169
+ 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131,
170
+ 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 195,
171
+ 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163,
172
+ 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227,
173
+ 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 147,
174
+ 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211,
175
+ 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179,
176
+ 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243,
177
+ 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258,
178
+ 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203,
179
+ 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171,
180
+ 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 235,
181
+ 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155,
182
+ 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219,
183
+ 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187,
184
+ 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 251,
185
+ 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195,
186
+ 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199,
187
+ 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 167,
188
+ 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231,
189
+ 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151,
190
+ 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215,
191
+ 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 183,
192
+ 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247,
193
+ 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0,
194
+ 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 207,
195
+ 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175,
196
+ 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239,
197
+ 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159,
198
+ 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 223,
199
+ 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191,
200
+ 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255
201
+ ];
202
+ var fixed_td = [
203
+ 80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097,
204
+ 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385,
205
+ 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5, 8193,
206
+ 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577,
207
+ 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145,
208
+ 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5, 24577,
209
+ 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289,
210
+ 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577
211
+ ];
212
+
213
+ // Tables for deflate from PKZIP's appnote.txt.
214
+ var cplens = [ // Copy lengths for literal codes 257..285
215
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
216
+ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
217
+ ];
218
+
219
+ // see note #13 above about 258
220
+ var cplext = [ // Extra bits for literal codes 257..285
221
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
222
+ 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
223
+ ];
224
+
225
+ var cpdist = [ // Copy offsets for distance codes 0..29
226
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
227
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
228
+ 8193, 12289, 16385, 24577
229
+ ];
230
+
231
+ var cpdext = [ // Extra bits for distance codes
232
+ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
233
+ 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
234
+ 12, 12, 13, 13
235
+ ];
236
+
237
+ //
238
+ // ZStream.java
239
+ //
240
+
241
+ function ZStream() {}
242
+
243
+ ZStream.prototype.inflateInit = function(w, nowrap) {
244
+ if (!w) {
245
+ w = DEF_WBITS;
246
+ }
247
+
248
+ if (nowrap) {
249
+ nowrap = false;
250
+ }
251
+
252
+ this.istate = new Inflate();
253
+
254
+ return this.istate.inflateInit(this, nowrap ? -w : w);
255
+ };
256
+
257
+ ZStream.prototype.inflate = function(f) {
258
+ if (this.istate == null) {
259
+ return Z_STREAM_ERROR;
260
+ }
261
+
262
+ return this.istate.inflate(this, f);
263
+ };
264
+
265
+ ZStream.prototype.inflateEnd = function() {
266
+ if (this.istate == null) {
267
+ return Z_STREAM_ERROR;
268
+ }
269
+
270
+ var ret = istate.inflateEnd(this);
271
+ this.istate = null;
272
+ return ret;
273
+ };
274
+
275
+ ZStream.prototype.inflateSync = function() {
276
+ // if(istate == null) return Z_STREAM_ERROR;
277
+ return istate.inflateSync(this);
278
+ };
279
+
280
+ ZStream.prototype.inflateSetDictionary = function(dictionary, dictLength) {
281
+ // if(istate == null) return Z_STREAM_ERROR;
282
+ return istate.inflateSetDictionary(this, dictionary, dictLength);
283
+ };
284
+
285
+ /*
286
+
287
+ public int deflateInit(int level){
288
+ return deflateInit(level, MAX_WBITS);
289
+ }
290
+ public int deflateInit(int level, boolean nowrap){
291
+ return deflateInit(level, MAX_WBITS, nowrap);
292
+ }
293
+ public int deflateInit(int level, int bits){
294
+ return deflateInit(level, bits, false);
295
+ }
296
+ public int deflateInit(int level, int bits, boolean nowrap){
297
+ dstate=new Deflate();
298
+ return dstate.deflateInit(this, level, nowrap?-bits:bits);
299
+ }
300
+ public int deflate(int flush){
301
+ if(dstate==null){
302
+ return Z_STREAM_ERROR;
303
+ }
304
+ return dstate.deflate(this, flush);
305
+ }
306
+ public int deflateEnd(){
307
+ if(dstate==null) return Z_STREAM_ERROR;
308
+ int ret=dstate.deflateEnd();
309
+ dstate=null;
310
+ return ret;
311
+ }
312
+ public int deflateParams(int level, int strategy){
313
+ if(dstate==null) return Z_STREAM_ERROR;
314
+ return dstate.deflateParams(this, level, strategy);
315
+ }
316
+ public int deflateSetDictionary (byte[] dictionary, int dictLength){
317
+ if(dstate == null)
318
+ return Z_STREAM_ERROR;
319
+ return dstate.deflateSetDictionary(this, dictionary, dictLength);
320
+ }
321
+
322
+ */
323
+
324
+ /*
325
+ // Flush as much pending output as possible. All deflate() output goes
326
+ // through this function so some applications may wish to modify it
327
+ // to avoid allocating a large strm->next_out buffer and copying into it.
328
+ // (See also read_buf()).
329
+ void flush_pending(){
330
+ int len=dstate.pending;
331
+
332
+ if(len>avail_out) len=avail_out;
333
+ if(len==0) return;
334
+
335
+ if(dstate.pending_buf.length<=dstate.pending_out ||
336
+ next_out.length<=next_out_index ||
337
+ dstate.pending_buf.length<(dstate.pending_out+len) ||
338
+ next_out.length<(next_out_index+len)){
339
+ System.out.println(dstate.pending_buf.length+", "+dstate.pending_out+
340
+ ", "+next_out.length+", "+next_out_index+", "+len);
341
+ System.out.println("avail_out="+avail_out);
342
+ }
343
+
344
+ System.arraycopy(dstate.pending_buf, dstate.pending_out,
345
+ next_out, next_out_index, len);
346
+
347
+ next_out_index+=len;
348
+ dstate.pending_out+=len;
349
+ total_out+=len;
350
+ avail_out-=len;
351
+ dstate.pending-=len;
352
+ if(dstate.pending==0){
353
+ dstate.pending_out=0;
354
+ }
355
+ }
356
+
357
+ // Read a new buffer from the current input stream, update the adler32
358
+ // and total number of bytes read. All deflate() input goes through
359
+ // this function so some applications may wish to modify it to avoid
360
+ // allocating a large strm->next_in buffer and copying from it.
361
+ // (See also flush_pending()).
362
+ int read_buf(byte[] buf, int start, int size) {
363
+ int len=avail_in;
364
+
365
+ if(len>size) len=size;
366
+ if(len==0) return 0;
367
+
368
+ avail_in-=len;
369
+
370
+ if(dstate.noheader==0) {
371
+ adler=_adler.adler32(adler, next_in, next_in_index, len);
372
+ }
373
+ System.arraycopy(next_in, next_in_index, buf, start, len);
374
+ next_in_index += len;
375
+ total_in += len;
376
+ return len;
377
+ }
378
+
379
+ public void free(){
380
+ next_in=null;
381
+ next_out=null;
382
+ msg=null;
383
+ _adler=null;
384
+ }
385
+ }
386
+ */
387
+
388
+
389
+ //
390
+ // Inflate.java
391
+ //
392
+
393
+ function Inflate() {
394
+ this.was = [0];
395
+ }
396
+
397
+ Inflate.prototype.inflateReset = function(z) {
398
+ if (z == null || z.istate == null) {
399
+ return Z_STREAM_ERROR;
400
+ }
401
+
402
+ z.total_in = z.total_out = 0;
403
+ z.msg = null;
404
+ z.istate.mode = z.istate.nowrap != 0 ? BLOCKS : METHOD;
405
+ z.istate.blocks.reset(z, null);
406
+ return Z_OK;
407
+ };
408
+
409
+ Inflate.prototype.inflateEnd = function(z) {
410
+ if (this.blocks != null) {
411
+ this.blocks.free(z);
412
+ }
413
+
414
+ this.blocks = null;
415
+ return Z_OK;
416
+ };
417
+
418
+ Inflate.prototype.inflateInit = function(z, w) {
419
+ z.msg = null;
420
+ this.blocks = null;
421
+
422
+ // handle undocumented nowrap option (no zlib header or check)
423
+ nowrap = 0;
424
+
425
+ if (w < 0) {
426
+ w = -w;
427
+ nowrap = 1;
428
+ }
429
+
430
+ // set window size
431
+ if (w < 8 || w > 15) {
432
+ this.inflateEnd(z);
433
+ return Z_STREAM_ERROR;
434
+ }
435
+
436
+ this.wbits = w;
437
+
438
+ z.istate.blocks = new InfBlocks(z, z.istate.nowrap != 0 ? null : this, 1 << w);
439
+
440
+ // reset state
441
+ this.inflateReset(z);
442
+ return Z_OK;
443
+ };
444
+
445
+ Inflate.prototype.inflate = function(z, f) {
446
+ var r, b;
447
+
448
+ if (z == null || z.istate == null || z.next_in == null) {
449
+ return Z_STREAM_ERROR;
450
+ }
451
+
452
+ f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
453
+ r = Z_BUF_ERROR;
454
+
455
+ while (true) {
456
+ switch (z.istate.mode) {
457
+ case METHOD:
458
+
459
+ if (z.avail_in == 0) {
460
+ return r;
461
+ }
462
+
463
+ r = f;
464
+
465
+ z.avail_in--;
466
+ z.total_in++;
467
+
468
+ if (((z.istate.method = z.next_in[z.next_in_index++]) & 0xf) != Z_DEFLATED) {
469
+ z.istate.mode = BAD;
470
+ z.msg = "unknown compression method";
471
+ z.istate.marker = 5; // can't try inflateSync
472
+ break;
473
+ }
474
+
475
+ if ((z.istate.method >> 4) + 8 > z.istate.wbits) {
476
+ z.istate.mode = BAD;
477
+ z.msg = "invalid window size";
478
+ z.istate.marker = 5; // can't try inflateSync
479
+ break;
480
+ }
481
+
482
+ z.istate.mode = FLAG;
483
+ case FLAG:
484
+ if (z.avail_in == 0) {
485
+ return r;
486
+ }
487
+
488
+ r = f;
489
+
490
+ z.avail_in--;
491
+ z.total_in++;
492
+ b = (z.next_in[z.next_in_index++]) & 0xff;
493
+
494
+ if ((((z.istate.method << 8) + b) % 31) != 0) {
495
+ z.istate.mode = BAD;
496
+ z.msg = "incorrect header check";
497
+ z.istate.marker = 5; // can't try inflateSync
498
+ break;
499
+ }
500
+
501
+ if ((b & PRESET_DICT) == 0) {
502
+ z.istate.mode = BLOCKS;
503
+ break;
504
+ }
505
+
506
+ z.istate.mode = DICT4;
507
+ case DICT4:
508
+ if (z.avail_in == 0) {
509
+ return r;
510
+ }
511
+
512
+ r = f;
513
+
514
+ z.avail_in--;
515
+ z.total_in++;
516
+ z.istate.need = ((z.next_in[z.next_in_index++] & 0xff) << 24) & 0xff000000;
517
+ z.istate.mode = DICT3;
518
+ case DICT3:
519
+ if (z.avail_in == 0) {
520
+ return r;
521
+ }
522
+
523
+ r = f;
524
+
525
+ z.avail_in--;
526
+ z.total_in++;
527
+ z.istate.need += ((z.next_in[z.next_in_index++] & 0xff) << 16) & 0xff0000;
528
+ z.istate.mode = DICT2;
529
+ case DICT2:
530
+ if (z.avail_in == 0) {
531
+ return r;
532
+ }
533
+
534
+ r = f;
535
+
536
+ z.avail_in--;
537
+ z.total_in++;
538
+ z.istate.need += ((z.next_in[z.next_in_index++] & 0xff) << 8) & 0xff00;
539
+ z.istate.mode = DICT1;
540
+ case DICT1:
541
+ if (z.avail_in == 0) {
542
+ return r;
543
+ }
544
+
545
+ r = f;
546
+
547
+ z.avail_in--;
548
+ z.total_in++;
549
+ z.istate.need += (z.next_in[z.next_in_index++] & 0xff);
550
+ z.adler = z.istate.need;
551
+ z.istate.mode = DICT0;
552
+ return Z_NEED_DICT;
553
+ case DICT0:
554
+ z.istate.mode = BAD;
555
+ z.msg = "need dictionary";
556
+ z.istate.marker = 0; // can try inflateSync
557
+ return Z_STREAM_ERROR;
558
+ case BLOCKS:
559
+ r = z.istate.blocks.proc(z, r);
560
+
561
+ if (r == Z_DATA_ERROR) {
562
+ z.istate.mode = BAD;
563
+ z.istate.marker = 0; // can try inflateSync
564
+ break;
565
+ }
566
+
567
+ if (r == Z_OK) {
568
+ r = f;
569
+ }
570
+
571
+ if (r != Z_STREAM_END) {
572
+ return r;
573
+ }
574
+
575
+ r = f;
576
+ z.istate.blocks.reset(z, z.istate.was);
577
+
578
+ if (z.istate.nowrap != 0) {
579
+ z.istate.mode = DONE;
580
+ break;
581
+ }
582
+
583
+ z.istate.mode = CHECK4;
584
+ case CHECK4:
585
+ if (z.avail_in == 0) {
586
+ return r;
587
+ }
588
+
589
+ r = f;
590
+
591
+ z.avail_in--;
592
+ z.total_in++;
593
+ z.istate.need = ((z.next_in[z.next_in_index++] & 0xff) << 24) & 0xff000000;
594
+ z.istate.mode = CHECK3;
595
+ case CHECK3:
596
+ if (z.avail_in == 0) {
597
+ return r;
598
+ }
599
+
600
+ r = f;
601
+
602
+ z.avail_in--;
603
+ z.total_in++;
604
+ z.istate.need += ((z.next_in[z.next_in_index++] & 0xff) << 16) & 0xff0000;
605
+ z.istate.mode = CHECK2;
606
+ case CHECK2:
607
+ if (z.avail_in == 0) {
608
+ return r;
609
+ }
610
+
611
+ r = f;
612
+
613
+ z.avail_in--;
614
+ z.total_in++;
615
+ z.istate.need += ((z.next_in[z.next_in_index++] & 0xff) << 8) & 0xff00;
616
+ z.istate.mode = CHECK1;
617
+ case CHECK1:
618
+ if (z.avail_in == 0) {
619
+ return r;
620
+ }
621
+
622
+ r = f;
623
+
624
+ z.avail_in--;
625
+ z.total_in++;
626
+ z.istate.need += (z.next_in[z.next_in_index++] & 0xff);
627
+
628
+ if (((z.istate.was[0])) != ((z.istate.need))) {
629
+ z.istate.mode = BAD;
630
+ z.msg = "incorrect data check";
631
+ z.istate.marker = 5; // can't try inflateSync
632
+ break;
633
+ }
634
+
635
+ z.istate.mode = DONE;
636
+ case DONE:
637
+ return Z_STREAM_END;
638
+ case BAD:
639
+ return Z_DATA_ERROR;
640
+ default:
641
+ return Z_STREAM_ERROR;
642
+ }
643
+ }
644
+ };
645
+
646
+ Inflate.prototype.inflateSetDictionary = function(z, dictionary, dictLength) {
647
+ var index = 0;
648
+ var length = dictLength;
649
+
650
+ if (z == null || z.istate == null || z.istate.mode != DICT0) {
651
+ return Z_STREAM_ERROR;
652
+ }
653
+
654
+ if (z._adler.adler32(1, dictionary, 0, dictLength) != z.adler) {
655
+ return Z_DATA_ERROR;
656
+ }
657
+
658
+ z.adler = z._adler.adler32(0, null, 0, 0);
659
+
660
+ if (length >= (1 << z.istate.wbits)) {
661
+ length = (1 << z.istate.wbits) - 1;
662
+ index = dictLength - length;
663
+ }
664
+
665
+ z.istate.blocks.set_dictionary(dictionary, index, length);
666
+ z.istate.mode = BLOCKS;
667
+ return Z_OK;
668
+ };
669
+
670
+ // static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff};
671
+ var mark = [0, 0, 255, 255];
672
+
673
+ Inflate.prototype.inflateSync = function(z) {
674
+ var n; // number of bytes to look at
675
+ var p; // pointer to bytes
676
+ var m; // number of marker bytes found in a row
677
+ var r, w; // temporaries to save total_in and total_out
678
+
679
+ // set up
680
+ if (z == null || z.istate == null) {
681
+ return Z_STREAM_ERROR;
682
+ }
683
+
684
+ if (z.istate.mode != BAD) {
685
+ z.istate.mode = BAD;
686
+ z.istate.marker = 0;
687
+ }
688
+
689
+ if ((n = z.avail_in) == 0) {
690
+ return Z_BUF_ERROR;
691
+ }
692
+
693
+ p = z.next_in_index;
694
+ m = z.istate.marker;
695
+
696
+ // search
697
+ while (n != 0 && m < 4) {
698
+ if (z.next_in[p] == mark[m]) {
699
+ m++;
700
+ } else if (z.next_in[p] != 0) {
701
+ m = 0;
702
+ } else {
703
+ m = 4 - m;
704
+ }
705
+
706
+ p++;
707
+ n--;
708
+ }
709
+
710
+ // restore
711
+ z.total_in += p - z.next_in_index;
712
+ z.next_in_index = p;
713
+ z.avail_in = n;
714
+ z.istate.marker = m;
715
+
716
+ // return no joy or set up to restart on a new block
717
+ if (m != 4) {
718
+ return Z_DATA_ERROR;
719
+ }
720
+
721
+ r = z.total_in;
722
+ w = z.total_out;
723
+ this.inflateReset(z);
724
+ z.total_in = r;
725
+ z.total_out = w;
726
+ z.istate.mode = BLOCKS;
727
+ return Z_OK;
728
+ };
729
+
730
+ // Returns true if inflate is currently at the end of a block generated
731
+ // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
732
+ // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
733
+ // but removes the length bytes of the resulting empty stored block. When
734
+ // decompressing, PPP checks that at the end of input packet, inflate is
735
+ // waiting for these length bytes.
736
+ Inflate.prototype.inflateSyncPoint = function(z) {
737
+ if (z == null || z.istate == null || z.istate.blocks == null) {
738
+ return Z_STREAM_ERROR;
739
+ }
740
+
741
+ return z.istate.blocks.sync_point();
742
+ };
743
+
744
+
745
+ //
746
+ // InfBlocks.java
747
+ //
748
+
749
+ var INFBLOCKS_BORDER = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
750
+
751
+ function InfBlocks(z, checkfn, w) {
752
+ this.hufts = new Int32Array(MANY * 3);
753
+ this.window = new Uint8Array(w);
754
+ this.end = w;
755
+ this.checkfn = checkfn;
756
+ this.mode = IB_TYPE;
757
+ this.reset(z, null);
758
+
759
+ this.left = 0; // if STORED, bytes left to copy
760
+
761
+ this.table = 0; // table lengths (14 bits)
762
+ this.index = 0; // index into blens (or border)
763
+ this.blens = null; // bit lengths of codes
764
+ this.bb = new Int32Array(1); // bit length tree depth
765
+ this.tb = new Int32Array(1); // bit length decoding tree
766
+
767
+ this.codes = new InfCodes();
768
+
769
+ this.last = 0; // true if this block is the last block
770
+
771
+ // mode independent information
772
+ this.bitk = 0; // bits in bit buffer
773
+ this.bitb = 0; // bit buffer
774
+ this.read = 0; // window read pointer
775
+ this.write = 0; // window write pointer
776
+ this.check = 0; // check on output
777
+
778
+ this.inftree = new InfTree();
779
+ }
780
+
781
+ InfBlocks.prototype.reset = function(z, c) {
782
+ if (c) {
783
+ c[0] = this.check;
784
+ }
785
+
786
+ if (this.mode == IB_CODES) {
787
+ this.codes.free(z);
788
+ }
789
+
790
+ this.mode = IB_TYPE;
791
+ this.bitk = 0;
792
+ this.bitb = 0;
793
+ this.read = this.write = 0;
794
+
795
+ if (this.checkfn) {
796
+ z.adler = this.check = z._adler.adler32(0, null, 0, 0);
797
+ }
798
+ };
799
+
800
+ InfBlocks.prototype.proc = function(z, r) {
801
+ var t; // temporary storage
802
+ var b; // bit buffer
803
+ var k; // bits in bit buffer
804
+ var p; // input data pointer
805
+ var n; // bytes available there
806
+ var q; // output window write pointer
807
+ var m; // bytes to end of window or read pointer
808
+
809
+ // copy input/output information to locals (UPDATE macro restores)
810
+ {
811
+ p = z.next_in_index;
812
+ n = z.avail_in;
813
+ b = this.bitb;
814
+ k = this.bitk;
815
+ } {
816
+ q = this.write;
817
+ m = (q < this.read ? this.read - q - 1 : this.end - q);
818
+ }
819
+
820
+ // process input based on current state
821
+ while (true) {
822
+ switch (this.mode) {
823
+ case IB_TYPE:
824
+ while (k < (3)) {
825
+ if (n != 0) {
826
+ r = Z_OK;
827
+ } else {
828
+ this.bitb = b;
829
+ this.bitk = k;
830
+ z.avail_in = n;
831
+ z.total_in += p - z.next_in_index;
832
+ z.next_in_index = p;
833
+ this.write = q;
834
+ return this.inflate_flush(z, r);
835
+ }
836
+
837
+ n--;
838
+ b |= (z.next_in[p++] & 0xff) << k;
839
+ k += 8;
840
+ }
841
+
842
+ t = (b & 7);
843
+ this.last = t & 1;
844
+
845
+ switch (t >>> 1) {
846
+ case 0: // stored
847
+ {
848
+ b >>>= (3);
849
+ k -= (3);
850
+ }
851
+
852
+ t = k & 7; // go to byte boundary
853
+
854
+ {
855
+ b >>>= (t);
856
+ k -= (t);
857
+ }
858
+
859
+ this.mode = IB_LENS; // get length of stored block
860
+ break;
861
+ case 1: // fixed
862
+ {
863
+ var bl = new Int32Array(1);
864
+ var bd = new Int32Array(1);
865
+ var tl = [];
866
+ var td = [];
867
+
868
+ inflate_trees_fixed(bl, bd, tl, td, z);
869
+ this.codes.init(bl[0], bd[0], tl[0], 0, td[0], 0, z);
870
+ }
871
+
872
+ {
873
+ b >>>= (3);
874
+ k -= (3);
875
+ }
876
+
877
+ this.mode = IB_CODES;
878
+ break;
879
+ case 2: // dynamic
880
+ {
881
+ b >>>= (3);k -= (3);
882
+ }
883
+
884
+ this.mode = IB_TABLE;
885
+ break;
886
+ case 3: // illegal
887
+ {
888
+ b >>>= (3);k -= (3);
889
+ }
890
+
891
+ this.mode = BAD;
892
+ z.msg = "invalid block type";
893
+ r = Z_DATA_ERROR;
894
+
895
+ this.bitb = b;
896
+ this.bitk = k;
897
+ z.avail_in = n;
898
+ z.total_in += p - z.next_in_index;
899
+ z.next_in_index = p;
900
+ this.write = q;
901
+ return this.inflate_flush(z, r);
902
+ }
903
+
904
+ break;
905
+ case IB_LENS:
906
+ while (k < (32)) {
907
+ if (n != 0) {
908
+ r = Z_OK;
909
+ } else {
910
+ this.bitb = b;
911
+ this.bitk = k;
912
+ z.avail_in = n;
913
+ z.total_in += p - z.next_in_index;
914
+ z.next_in_index = p;
915
+ this.write = q;
916
+ return this.inflate_flush(z, r);
917
+ }
918
+
919
+ n--;
920
+ b |= (z.next_in[p++] & 0xff) << k;
921
+ k += 8;
922
+ }
923
+
924
+ if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) {
925
+ this.mode = BAD;
926
+ z.msg = "invalid stored block lengths";
927
+ r = Z_DATA_ERROR;
928
+
929
+ this.bitb = b;
930
+ this.bitk = k;
931
+ z.avail_in = n;
932
+ z.total_in += p - z.next_in_index;
933
+ z.next_in_index = p;
934
+ this.write = q;
935
+ return this.inflate_flush(z, r);
936
+ }
937
+
938
+ this.left = (b & 0xffff);
939
+ b = k = 0; // dump bits
940
+ this.mode = this.left != 0 ? IB_STORED : (this.last != 0 ? IB_DRY : IB_TYPE);
941
+ break;
942
+ case IB_STORED:
943
+ if (n == 0) {
944
+ this.bitb = b;
945
+ this.bitk = k;
946
+ z.avail_in = n;
947
+ z.total_in += p - z.next_in_index;
948
+ z.next_in_index = p;
949
+ write = q;
950
+ return this.inflate_flush(z, r);
951
+ }
952
+
953
+ if (m == 0) {
954
+ if (q == end && read != 0) {
955
+ q = 0;
956
+ m = (q < this.read ? this.read - q - 1 : this.end - q);
957
+ }
958
+
959
+ if (m == 0) {
960
+ this.write = q;
961
+ r = this.inflate_flush(z, r);
962
+ q = this.write;
963
+ m = (q < this.read ? this.read - q - 1 : this.end - q);
964
+
965
+ if (q == this.end && this.read != 0) {
966
+ q = 0;
967
+ m = (q < this.read ? this.read - q - 1 : this.end - q);
968
+ }
969
+
970
+ if (m == 0) {
971
+ this.bitb = b;
972
+ this.bitk = k;
973
+ z.avail_in = n;
974
+ z.total_in += p - z.next_in_index;
975
+ z.next_in_index = p;
976
+ this.write = q;
977
+ return this.inflate_flush(z, r);
978
+ }
979
+ }
980
+ }
981
+
982
+ r = Z_OK;
983
+
984
+ t = this.left;
985
+
986
+ if (t > n) {
987
+ t = n;
988
+ }
989
+
990
+ if (t > m) {
991
+ t = m;
992
+ }
993
+
994
+ arrayCopy(z.next_in, p, this.window, q, t);
995
+ p += t;
996
+ n -= t;
997
+ q += t;
998
+ m -= t;
999
+
1000
+ if ((this.left -= t) != 0) {
1001
+ break;
1002
+ }
1003
+
1004
+ this.mode = (this.last != 0 ? IB_DRY : IB_TYPE);
1005
+ break;
1006
+ case IB_TABLE:
1007
+ while (k < (14)) {
1008
+ if (n != 0) {
1009
+ r = Z_OK;
1010
+ } else {
1011
+ this.bitb = b;
1012
+ this.bitk = k;
1013
+ z.avail_in = n;
1014
+ z.total_in += p - z.next_in_index;
1015
+ z.next_in_index = p;
1016
+ this.write = q;
1017
+ return this.inflate_flush(z, r);
1018
+ }
1019
+
1020
+ n--;
1021
+ b |= (z.next_in[p++] & 0xff) << k;
1022
+ k += 8;
1023
+ }
1024
+
1025
+ this.table = t = (b & 0x3fff);
1026
+
1027
+ if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
1028
+ this.mode = IB_BAD;
1029
+ z.msg = "too many length or distance symbols";
1030
+ r = Z_DATA_ERROR;
1031
+
1032
+ this.bitb = b;
1033
+ this.bitk = k;
1034
+ z.avail_in = n;
1035
+ z.total_in += p - z.next_in_index;
1036
+ z.next_in_index = p;
1037
+ this.write = q;
1038
+ return this.inflate_flush(z, r);
1039
+ }
1040
+
1041
+ t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
1042
+
1043
+ if (this.blens == null || this.blens.length < t) {
1044
+ this.blens = new Int32Array(t);
1045
+ } else {
1046
+ for (var i = 0; i < t; i++) {
1047
+ this.blens[i] = 0;
1048
+ }
1049
+ }
1050
+
1051
+ {
1052
+ b >>>= (14);
1053
+ k -= (14);
1054
+ }
1055
+
1056
+ this.index = 0;
1057
+ mode = IB_BTREE;
1058
+ case IB_BTREE:
1059
+ while (this.index < 4 + (this.table >>> 10)) {
1060
+ while (k < (3)) {
1061
+ if (n != 0) {
1062
+ r = Z_OK;
1063
+ } else {
1064
+ this.bitb = b;
1065
+ this.bitk = k;
1066
+ z.avail_in = n;
1067
+ z.total_in += p - z.next_in_index;
1068
+ z.next_in_index = p;
1069
+ this.write = q;
1070
+ return this.inflate_flush(z, r);
1071
+ }
1072
+
1073
+ n--;
1074
+ b |= (z.next_in[p++] & 0xff) << k;
1075
+ k += 8;
1076
+ }
1077
+
1078
+ this.blens[INFBLOCKS_BORDER[this.index++]] = b & 7;
1079
+
1080
+ {
1081
+ b >>>= (3);
1082
+ k -= (3);
1083
+ }
1084
+ }
1085
+
1086
+ while (this.index < 19) {
1087
+ this.blens[INFBLOCKS_BORDER[this.index++]] = 0;
1088
+ }
1089
+
1090
+ this.bb[0] = 7;
1091
+ t = this.inftree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z);
1092
+
1093
+ if (t != Z_OK) {
1094
+ r = t;
1095
+
1096
+ if (r == Z_DATA_ERROR) {
1097
+ this.blens = null;
1098
+ this.mode = IB_BAD;
1099
+ }
1100
+
1101
+ this.bitb = b;
1102
+ this.bitk = k;
1103
+ z.avail_in = n;
1104
+ z.total_in += p - z.next_in_index;
1105
+ z.next_in_index = p;
1106
+ write = q;
1107
+ return this.inflate_flush(z, r);
1108
+ }
1109
+
1110
+ this.index = 0;
1111
+ this.mode = IB_DTREE;
1112
+ case IB_DTREE:
1113
+ while (true) {
1114
+ t = this.table;
1115
+
1116
+ if (!(this.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))) {
1117
+ break;
1118
+ }
1119
+
1120
+ var h; //int[]
1121
+ var i, j, c;
1122
+
1123
+ t = this.bb[0];
1124
+
1125
+ while (k < (t)) {
1126
+ if (n != 0) {
1127
+ r = Z_OK;
1128
+ } else {
1129
+ this.bitb = b;
1130
+ this.bitk = k;
1131
+ z.avail_in = n;
1132
+ z.total_in += p - z.next_in_index;
1133
+ z.next_in_index = p;
1134
+ this.write = q;
1135
+ return this.inflate_flush(z, r);
1136
+ }
1137
+
1138
+ n--;
1139
+ b |= (z.next_in[p++] & 0xff) << k;
1140
+ k += 8;
1141
+ }
1142
+
1143
+ // if (this.tb[0]==-1){
1144
+ // dlog("null...");
1145
+ // }
1146
+
1147
+ t = this.hufts[(this.tb[0] + (b & inflate_mask[t])) * 3 + 1];
1148
+ c = this.hufts[(this.tb[0] + (b & inflate_mask[t])) * 3 + 2];
1149
+
1150
+ if (c < 16) {
1151
+ b >>>= (t);
1152
+ k -= (t);
1153
+ this.blens[this.index++] = c;
1154
+ } else { // c == 16..18
1155
+ i = c == 18 ? 7 : c - 14;
1156
+ j = c == 18 ? 11 : 3;
1157
+
1158
+ while (k < (t + i)) {
1159
+ if (n != 0) {
1160
+ r = Z_OK;
1161
+ } else {
1162
+ this.bitb = b;
1163
+ this.bitk = k;
1164
+ z.avail_in = n;
1165
+ z.total_in += p - z.next_in_index;
1166
+ z.next_in_index = p;
1167
+ this.write = q;
1168
+ return this.inflate_flush(z, r);
1169
+ }
1170
+
1171
+ n--;
1172
+ b |= (z.next_in[p++] & 0xff) << k;
1173
+ k += 8;
1174
+ }
1175
+
1176
+ b >>>= (t);
1177
+ k -= (t);
1178
+
1179
+ j += (b & inflate_mask[i]);
1180
+
1181
+ b >>>= (i);
1182
+ k -= (i);
1183
+
1184
+ i = this.index;
1185
+ t = this.table;
1186
+
1187
+ if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {
1188
+ this.blens = null;
1189
+ this.mode = IB_BAD;
1190
+ z.msg = "invalid bit length repeat";
1191
+ r = Z_DATA_ERROR;
1192
+
1193
+ this.bitb = b;
1194
+ this.bitk = k;
1195
+ z.avail_in = n;
1196
+ z.total_in += p - z.next_in_index;
1197
+ z.next_in_index = p;
1198
+ this.write = q;
1199
+ return this.inflate_flush(z, r);
1200
+ }
1201
+
1202
+ c = c == 16 ? this.blens[i - 1] : 0;
1203
+
1204
+ do {
1205
+ this.blens[i++] = c;
1206
+ } while (--j != 0);
1207
+
1208
+ this.index = i;
1209
+ }
1210
+ }
1211
+
1212
+ this.tb[0] = -1;
1213
+
1214
+ {
1215
+ var bl = new Int32Array(1);
1216
+ var bd = new Int32Array(1);
1217
+ var tl = new Int32Array(1);
1218
+ var td = new Int32Array(1);
1219
+ bl[0] = 9; // must be <= 9 for lookahead assumptions
1220
+ bd[0] = 6; // must be <= 9 for lookahead assumptions
1221
+
1222
+ t = this.table;
1223
+ t = this.inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), this.blens, bl, bd, tl, td, this.hufts, z);
1224
+
1225
+ if (t != Z_OK) {
1226
+ if (t == Z_DATA_ERROR) {
1227
+ this.blens = null;
1228
+ this.mode = BAD;
1229
+ }
1230
+
1231
+ r = t;
1232
+
1233
+ this.bitb = b;
1234
+ this.bitk = k;
1235
+ z.avail_in = n;
1236
+ z.total_in += p - z.next_in_index;
1237
+ z.next_in_index = p;
1238
+ this.write = q;
1239
+ return this.inflate_flush(z, r);
1240
+ }
1241
+ this.codes.init(bl[0], bd[0], this.hufts, tl[0], this.hufts, td[0], z);
1242
+ }
1243
+
1244
+ this.mode = IB_CODES;
1245
+ case IB_CODES:
1246
+ this.bitb = b;
1247
+ this.bitk = k;
1248
+ z.avail_in = n;
1249
+ z.total_in += p - z.next_in_index;
1250
+ z.next_in_index = p;
1251
+ this.write = q;
1252
+
1253
+ if ((r = this.codes.proc(this, z, r)) != Z_STREAM_END) {
1254
+ return this.inflate_flush(z, r);
1255
+ }
1256
+
1257
+ r = Z_OK;
1258
+ this.codes.free(z);
1259
+
1260
+ p = z.next_in_index;
1261
+ n = z.avail_in;
1262
+ b = this.bitb;
1263
+ k = this.bitk;
1264
+ q = this.write;
1265
+ m = (q < this.read ? this.read - q - 1 : this.end - q);
1266
+
1267
+ if (this.last == 0) {
1268
+ this.mode = IB_TYPE;
1269
+ break;
1270
+ }
1271
+
1272
+ this.mode = IB_DRY;
1273
+ case IB_DRY:
1274
+ this.write = q;
1275
+ r = this.inflate_flush(z, r);
1276
+ q = this.write;
1277
+ m = (q < this.read ? this.read - q - 1 : this.end - q);
1278
+
1279
+ if (this.read != this.write) {
1280
+ this.bitb = b;
1281
+ this.bitk = k;
1282
+ z.avail_in = n;
1283
+ z.total_in += p - z.next_in_index;
1284
+ z.next_in_index = p;
1285
+ this.write = q;
1286
+ return this.inflate_flush(z, r);
1287
+ }
1288
+
1289
+ mode = DONE;
1290
+ case IB_DONE:
1291
+ r = Z_STREAM_END;
1292
+
1293
+ this.bitb = b;
1294
+ this.bitk = k;
1295
+ z.avail_in = n;
1296
+ z.total_in += p - z.next_in_index;
1297
+ z.next_in_index = p;
1298
+ this.write = q;
1299
+ return this.inflate_flush(z, r);
1300
+ case IB_BAD:
1301
+ r = Z_DATA_ERROR;
1302
+
1303
+ this.bitb = b;
1304
+ this.bitk = k;
1305
+ z.avail_in = n;
1306
+ z.total_in += p - z.next_in_index;
1307
+ z.next_in_index = p;
1308
+ this.write = q;
1309
+ return this.inflate_flush(z, r);
1310
+ default:
1311
+ r = Z_STREAM_ERROR;
1312
+
1313
+ this.bitb = b;
1314
+ this.bitk = k;
1315
+ z.avail_in = n;
1316
+ z.total_in += p - z.next_in_index;
1317
+ z.next_in_index = p;
1318
+ this.write = q;
1319
+ return this.inflate_flush(z, r);
1320
+ }
1321
+ }
1322
+ };
1323
+
1324
+ InfBlocks.prototype.free = function(z) {
1325
+ this.reset(z, null);
1326
+ this.window = null;
1327
+ this.hufts = null;
1328
+ };
1329
+
1330
+ InfBlocks.prototype.set_dictionary = function(d, start, n) {
1331
+ arrayCopy(d, start, window, 0, n);
1332
+ this.read = this.write = n;
1333
+ };
1334
+
1335
+ // Returns true if inflate is currently at the end of a block generated
1336
+ // by Z_SYNC_FLUSH or Z_FULL_FLUSH.
1337
+ InfBlocks.prototype.sync_point = function() {
1338
+ return this.mode == IB_LENS;
1339
+ };
1340
+
1341
+ // copy as much as possible from the sliding window to the output area
1342
+ InfBlocks.prototype.inflate_flush = function(z, r) {
1343
+ var n;
1344
+ var p;
1345
+ var q;
1346
+
1347
+ // local copies of source and destination pointers
1348
+ p = z.next_out_index;
1349
+ q = this.read;
1350
+
1351
+ // compute number of bytes to copy as far as end of window
1352
+ n = ((q <= this.write ? this.write : this.end) - q);
1353
+
1354
+ if (n > z.avail_out) {
1355
+ n = z.avail_out;
1356
+ }
1357
+
1358
+ if (n != 0 && r == Z_BUF_ERROR) {
1359
+ r = Z_OK;
1360
+ }
1361
+
1362
+ // update counters
1363
+ z.avail_out -= n;
1364
+ z.total_out += n;
1365
+
1366
+ // update check information
1367
+ if (this.checkfn != null) {
1368
+ z.adler = this.check = z._adler.adler32(this.check, this.window, q, n);
1369
+ }
1370
+
1371
+ // copy as far as end of window
1372
+ arrayCopy(this.window, q, z.next_out, p, n);
1373
+ p += n;
1374
+ q += n;
1375
+
1376
+ // see if more to copy at beginning of window
1377
+ if (q == this.end) {
1378
+ // wrap pointers
1379
+ q = 0;
1380
+
1381
+ if (this.write == this.end) {
1382
+ this.write = 0;
1383
+ }
1384
+
1385
+ // compute bytes to copy
1386
+ n = this.write - q;
1387
+
1388
+ if (n > z.avail_out) {
1389
+ n = z.avail_out;
1390
+ }
1391
+
1392
+ if (n != 0 && r == Z_BUF_ERROR) {
1393
+ r = Z_OK;
1394
+ }
1395
+
1396
+ // update counters
1397
+ z.avail_out -= n;
1398
+ z.total_out += n;
1399
+
1400
+ // update check information
1401
+ if (this.checkfn != null) {
1402
+ z.adler = this.check = z._adler.adler32(this.check, this.window, q, n);
1403
+ }
1404
+
1405
+ // copy
1406
+ arrayCopy(this.window, q, z.next_out, p, n);
1407
+ p += n;
1408
+ q += n;
1409
+ }
1410
+
1411
+ // update pointers
1412
+ z.next_out_index = p;
1413
+ this.read = q;
1414
+
1415
+ // done
1416
+ return r;
1417
+ };
1418
+
1419
+ //
1420
+ // InfCodes.java
1421
+ //
1422
+
1423
+ var IC_START = 0; // x: set up for LEN
1424
+ var IC_LEN = 1; // i: get length/literal/eob next
1425
+ var IC_LENEXT = 2; // i: getting length extra (have base)
1426
+ var IC_DIST = 3; // i: get distance next
1427
+ var IC_DISTEXT = 4; // i: getting distance extra
1428
+ var IC_COPY = 5; // o: copying bytes in window, waiting for space
1429
+ var IC_LIT = 6; // o: got literal, waiting for output space
1430
+ var IC_WASH = 7; // o: got eob, possibly still output waiting
1431
+ var IC_END = 8; // x: got eob and all data flushed
1432
+ var IC_BADCODE = 9; // x: got error
1433
+
1434
+ function InfCodes() {}
1435
+
1436
+ InfCodes.prototype.init = function(bl, bd, tl, tl_index, td, td_index, z) {
1437
+ this.mode = IC_START;
1438
+ this.lbits = bl;
1439
+ this.dbits = bd;
1440
+ this.ltree = tl;
1441
+ this.ltree_index = tl_index;
1442
+ this.dtree = td;
1443
+ this.dtree_index = td_index;
1444
+ this.tree = null;
1445
+ };
1446
+
1447
+ InfCodes.prototype.proc = function(s, z, r) {
1448
+ var j; // temporary storage
1449
+ var t; // temporary pointer (int[])
1450
+ var tindex; // temporary pointer
1451
+ var e; // extra bits or operation
1452
+ var b = 0; // bit buffer
1453
+ var k = 0; // bits in bit buffer
1454
+ var p = 0; // input data pointer
1455
+ var n; // bytes available there
1456
+ var q; // output window write pointer
1457
+ var m; // bytes to end of window or read pointer
1458
+ var f; // pointer to copy strings from
1459
+
1460
+ // copy input/output information to locals (UPDATE macro restores)
1461
+ p = z.next_in_index;
1462
+ n = z.avail_in;
1463
+ b = s.bitb;
1464
+ k = s.bitk;
1465
+ q = s.write;
1466
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1467
+
1468
+ // process input and output based on current state
1469
+ while (true) {
1470
+ switch (this.mode) {
1471
+ // waiting for "i:"=input, "o:"=output, "x:"=nothing
1472
+ case IC_START: // x: set up for LEN
1473
+ if (m >= 258 && n >= 10) {
1474
+ s.bitb = b;
1475
+ s.bitk = k;
1476
+ z.avail_in = n;
1477
+ z.total_in += p - z.next_in_index;
1478
+ z.next_in_index = p;
1479
+ s.write = q;
1480
+ r = this.inflate_fast(this.lbits, this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, s, z);
1481
+ p = z.next_in_index;
1482
+ n = z.avail_in;
1483
+ b = s.bitb;
1484
+ k = s.bitk;
1485
+ q = s.write;
1486
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1487
+
1488
+ if (r != Z_OK) {
1489
+ this.mode = r == Z_STREAM_END ? IC_WASH : IC_BADCODE;
1490
+ break;
1491
+ }
1492
+ }
1493
+
1494
+ this.need = this.lbits;
1495
+ this.tree = this.ltree;
1496
+ this.tree_index = this.ltree_index;
1497
+
1498
+ this.mode = IC_LEN;
1499
+ case IC_LEN: // i: get length/literal/eob next
1500
+ j = this.need;
1501
+
1502
+ while (k < (j)) {
1503
+ if (n != 0) {
1504
+ r = Z_OK;
1505
+ } else {
1506
+ s.bitb = b;
1507
+ s.bitk = k;
1508
+ z.avail_in = n;
1509
+ z.total_in += p - z.next_in_index;
1510
+ z.next_in_index = p;
1511
+ s.write = q;
1512
+ return s.inflate_flush(z, r);
1513
+ }
1514
+
1515
+ n--;
1516
+ b |= (z.next_in[p++] & 0xff) << k;
1517
+ k += 8;
1518
+ }
1519
+
1520
+ tindex = (this.tree_index + (b & inflate_mask[j])) * 3;
1521
+
1522
+ b >>>= (this.tree[tindex + 1]);
1523
+ k -= (this.tree[tindex + 1]);
1524
+
1525
+ e = this.tree[tindex];
1526
+
1527
+ if (e == 0) { // literal
1528
+ this.lit = this.tree[tindex + 2];
1529
+ this.mode = IC_LIT;
1530
+ break;
1531
+ }
1532
+
1533
+ if ((e & 16) != 0) { // length
1534
+ this.get = e & 15;
1535
+ this.len = this.tree[tindex + 2];
1536
+ this.mode = IC_LENEXT;
1537
+ break;
1538
+ }
1539
+
1540
+ if ((e & 64) == 0) { // next table
1541
+ this.need = e;
1542
+ this.tree_index = tindex / 3 + this.tree[tindex + 2];
1543
+ break;
1544
+ }
1545
+
1546
+ if ((e & 32) != 0) { // end of block
1547
+ this.mode = IC_WASH;
1548
+ break;
1549
+ }
1550
+
1551
+ this.mode = IC_BADCODE; // invalid code
1552
+ z.msg = "invalid literal/length code";
1553
+ r = Z_DATA_ERROR;
1554
+
1555
+ s.bitb = b;
1556
+ s.bitk = k;
1557
+ z.avail_in = n;
1558
+ z.total_in += p - z.next_in_index;
1559
+ z.next_in_index = p;
1560
+ s.write = q;
1561
+ return s.inflate_flush(z, r);
1562
+ case IC_LENEXT: // i: getting length extra (have base)
1563
+ j = this.get;
1564
+
1565
+ while (k < (j)) {
1566
+ if (n != 0) {
1567
+ r = Z_OK;
1568
+ } else {
1569
+ s.bitb = b;
1570
+ s.bitk = k;
1571
+ z.avail_in = n;
1572
+ z.total_in += p - z.next_in_index;
1573
+ z.next_in_index = p;
1574
+ s.write = q;
1575
+ return s.inflate_flush(z, r);
1576
+ }
1577
+
1578
+ n--;
1579
+ b |= (z.next_in[p++] & 0xff) << k;
1580
+ k += 8;
1581
+ }
1582
+
1583
+ this.len += (b & inflate_mask[j]);
1584
+
1585
+ b >>= j;
1586
+ k -= j;
1587
+
1588
+ this.need = this.dbits;
1589
+ this.tree = this.dtree;
1590
+ this.tree_index = this.dtree_index;
1591
+ this.mode = IC_DIST;
1592
+ case IC_DIST: // i: get distance next
1593
+ j = this.need;
1594
+
1595
+ while (k < (j)) {
1596
+ if (n != 0) {
1597
+ r = Z_OK;
1598
+ } else {
1599
+ s.bitb = b;
1600
+ s.bitk = k;
1601
+ z.avail_in = n;
1602
+ z.total_in += p - z.next_in_index;
1603
+ z.next_in_index = p;
1604
+ s.write = q;
1605
+ return s.inflate_flush(z, r);
1606
+ }
1607
+
1608
+ n--;
1609
+ b |= (z.next_in[p++] & 0xff) << k;
1610
+ k += 8;
1611
+ }
1612
+
1613
+ tindex = (this.tree_index + (b & inflate_mask[j])) * 3;
1614
+
1615
+ b >>= this.tree[tindex + 1];
1616
+ k -= this.tree[tindex + 1];
1617
+
1618
+ e = (this.tree[tindex]);
1619
+
1620
+ if ((e & 16) != 0) { // distance
1621
+ this.get = e & 15;
1622
+ this.dist = this.tree[tindex + 2];
1623
+ this.mode = IC_DISTEXT;
1624
+ break;
1625
+ }
1626
+
1627
+ if ((e & 64) == 0) { // next table
1628
+ this.need = e;
1629
+ this.tree_index = tindex / 3 + this.tree[tindex + 2];
1630
+ break;
1631
+ }
1632
+
1633
+ this.mode = IC_BADCODE; // invalid code
1634
+ z.msg = "invalid distance code";
1635
+ r = Z_DATA_ERROR;
1636
+
1637
+ s.bitb = b;
1638
+ s.bitk = k;
1639
+ z.avail_in = n;
1640
+ z.total_in += p - z.next_in_index;
1641
+ z.next_in_index = p;
1642
+ s.write = q;
1643
+ return s.inflate_flush(z, r);
1644
+ case IC_DISTEXT: // i: getting distance extra
1645
+ j = this.get;
1646
+
1647
+ while (k < (j)) {
1648
+ if (n != 0) {
1649
+ r = Z_OK;
1650
+ } else {
1651
+ s.bitb = b;
1652
+ s.bitk = k;
1653
+ z.avail_in = n;
1654
+ z.total_in += p - z.next_in_index;
1655
+ z.next_in_index = p;
1656
+ s.write = q;
1657
+ return s.inflate_flush(z, r);
1658
+ }
1659
+
1660
+ n--;
1661
+ b |= (z.next_in[p++] & 0xff) << k;
1662
+ k += 8;
1663
+ }
1664
+
1665
+ this.dist += (b & inflate_mask[j]);
1666
+
1667
+ b >>= j;
1668
+ k -= j;
1669
+
1670
+ this.mode = IC_COPY;
1671
+ case IC_COPY: // o: copying bytes in window, waiting for space
1672
+ f = q - this.dist;
1673
+
1674
+ while (f < 0) { // modulo window size-"while" instead
1675
+ f += s.end; // of "if" handles invalid distances
1676
+ }
1677
+
1678
+ while (this.len != 0) {
1679
+ if (m == 0) {
1680
+ if (q == s.end && s.read != 0) {
1681
+ q = 0;
1682
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1683
+ }
1684
+
1685
+ if (m == 0) {
1686
+ s.write = q;
1687
+ r = s.inflate_flush(z, r);
1688
+ q = s.write;
1689
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1690
+
1691
+ if (q == s.end && s.read != 0) {
1692
+ q = 0;
1693
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1694
+ }
1695
+
1696
+ if (m == 0) {
1697
+ s.bitb = b;
1698
+ s.bitk = k;
1699
+ z.avail_in = n;
1700
+ z.total_in += p - z.next_in_index;
1701
+ z.next_in_index = p;
1702
+ s.write = q;
1703
+ return s.inflate_flush(z, r);
1704
+ }
1705
+ }
1706
+ }
1707
+
1708
+ s.window[q++] = s.window[f++];
1709
+ m--;
1710
+
1711
+ if (f == s.end) {
1712
+ f = 0;
1713
+ }
1714
+
1715
+ this.len--;
1716
+ }
1717
+
1718
+ this.mode = IC_START;
1719
+ break;
1720
+ case IC_LIT: // o: got literal, waiting for output space
1721
+ if (m == 0) {
1722
+ if (q == s.end && s.read != 0) {
1723
+ q = 0;
1724
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1725
+ }
1726
+
1727
+ if (m == 0) {
1728
+ s.write = q;
1729
+ r = s.inflate_flush(z, r);
1730
+ q = s.write;
1731
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1732
+
1733
+ if (q == s.end && s.read != 0) {
1734
+ q = 0;
1735
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1736
+ }
1737
+
1738
+ if (m == 0) {
1739
+ s.bitb = b;
1740
+ s.bitk = k;
1741
+ z.avail_in = n;
1742
+ z.total_in += p - z.next_in_index;
1743
+ z.next_in_index = p;
1744
+ s.write = q;
1745
+ return s.inflate_flush(z, r);
1746
+ }
1747
+ }
1748
+ }
1749
+
1750
+ r = Z_OK;
1751
+
1752
+ s.window[q++] = this.lit;
1753
+ m--;
1754
+
1755
+ this.mode = IC_START;
1756
+ break;
1757
+ case IC_WASH: // o: got eob, possibly more output
1758
+ if (k > 7) { // return unused byte, if any
1759
+ k -= 8;
1760
+ n++;
1761
+ p--; // can always return one
1762
+ }
1763
+
1764
+ s.write = q;
1765
+ r = s.inflate_flush(z, r);
1766
+ q = s.write;
1767
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1768
+
1769
+ if (s.read != s.write) {
1770
+ s.bitb = b;
1771
+ s.bitk = k;
1772
+ z.avail_in = n;
1773
+ z.total_in += p - z.next_in_index;
1774
+ z.next_in_index = p;
1775
+ s.write = q;
1776
+ return s.inflate_flush(z, r);
1777
+ }
1778
+
1779
+ this.mode = IC_END;
1780
+ case IC_END:
1781
+ r = Z_STREAM_END;
1782
+ s.bitb = b;
1783
+ s.bitk = k;
1784
+ z.avail_in = n;
1785
+ z.total_in += p - z.next_in_index;
1786
+ z.next_in_index = p;
1787
+ s.write = q;
1788
+ return s.inflate_flush(z, r);
1789
+ case IC_BADCODE: // x: got error
1790
+
1791
+ r = Z_DATA_ERROR;
1792
+
1793
+ s.bitb = b;
1794
+ s.bitk = k;
1795
+ z.avail_in = n;
1796
+ z.total_in += p - z.next_in_index;
1797
+ z.next_in_index = p;
1798
+ s.write = q;
1799
+ return s.inflate_flush(z, r);
1800
+ default:
1801
+ r = Z_STREAM_ERROR;
1802
+
1803
+ s.bitb = b;
1804
+ s.bitk = k;
1805
+ z.avail_in = n;
1806
+ z.total_in += p - z.next_in_index;
1807
+ z.next_in_index = p;
1808
+ s.write = q;
1809
+ return s.inflate_flush(z, r);
1810
+ }
1811
+ }
1812
+ };
1813
+
1814
+ InfCodes.prototype.free = function(z) {
1815
+ // ZFREE(z, c);
1816
+ };
1817
+
1818
+ // Called with number of bytes left to write in window at least 258
1819
+ // (the maximum string length) and number of input bytes available
1820
+ // at least ten. The ten bytes are six bytes for the longest length/
1821
+ // distance pair plus four bytes for overloading the bit buffer.
1822
+
1823
+ InfCodes.prototype.inflate_fast = function(bl, bd, tl, tl_index, td, td_index, s, z) {
1824
+ var t; // temporary pointer
1825
+ var tp; // temporary pointer (int[])
1826
+ var tp_index; // temporary pointer
1827
+ var e; // extra bits or operation
1828
+ var b; // bit buffer
1829
+ var k; // bits in bit buffer
1830
+ var p; // input data pointer
1831
+ var n; // bytes available there
1832
+ var q; // output window write pointer
1833
+ var m; // bytes to end of window or read pointer
1834
+ var ml; // mask for literal/length tree
1835
+ var md; // mask for distance tree
1836
+ var c; // bytes to copy
1837
+ var d; // distance back to copy from
1838
+ var r; // copy source pointer
1839
+
1840
+ var tp_index_t_3; // (tp_index+t)*3
1841
+
1842
+ // load input, output, bit values
1843
+ p = z.next_in_index;
1844
+ n = z.avail_in;
1845
+ b = s.bitb;
1846
+ k = s.bitk;
1847
+ q = s.write;
1848
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1849
+
1850
+ // initialize masks
1851
+ ml = inflate_mask[bl];
1852
+ md = inflate_mask[bd];
1853
+
1854
+ // do until not enough input or output space for fast loop
1855
+ do { // assume called with m >= 258 && n >= 10
1856
+ // get literal/length code
1857
+ while (k < (20)) { // max bits for literal/length code
1858
+ n--;
1859
+ b |= (z.next_in[p++] & 0xff) << k;
1860
+ k += 8;
1861
+ }
1862
+
1863
+ t = b & ml;
1864
+ tp = tl;
1865
+ tp_index = tl_index;
1866
+ tp_index_t_3 = (tp_index + t) * 3;
1867
+
1868
+ if ((e = tp[tp_index_t_3]) == 0) {
1869
+ b >>= (tp[tp_index_t_3 + 1]);
1870
+ k -= (tp[tp_index_t_3 + 1]);
1871
+
1872
+ s.window[q++] = tp[tp_index_t_3 + 2];
1873
+ m--;
1874
+ continue;
1875
+ }
1876
+
1877
+ do {
1878
+ b >>= (tp[tp_index_t_3 + 1]);
1879
+ k -= (tp[tp_index_t_3 + 1]);
1880
+
1881
+ if ((e & 16) != 0) {
1882
+ e &= 15;
1883
+ c = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]);
1884
+
1885
+ b >>= e;
1886
+ k -= e;
1887
+
1888
+ // decode distance base of block to copy
1889
+ while (k < (15)) { // max bits for distance code
1890
+ n--;
1891
+ b |= (z.next_in[p++] & 0xff) << k;
1892
+ k += 8;
1893
+ }
1894
+
1895
+ t = b & md;
1896
+ tp = td;
1897
+ tp_index = td_index;
1898
+ tp_index_t_3 = (tp_index + t) * 3;
1899
+ e = tp[tp_index_t_3];
1900
+
1901
+ do {
1902
+ b >>= (tp[tp_index_t_3 + 1]);
1903
+ k -= (tp[tp_index_t_3 + 1]);
1904
+
1905
+ if ((e & 16) != 0) {
1906
+ // get extra bits to add to distance base
1907
+ e &= 15;
1908
+
1909
+ while (k < (e)) { // get extra bits (up to 13)
1910
+ n--;
1911
+ b |= (z.next_in[p++] & 0xff) << k;
1912
+ k += 8;
1913
+ }
1914
+
1915
+ d = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]);
1916
+
1917
+ b >>= (e);
1918
+ k -= (e);
1919
+
1920
+ // do the copy
1921
+ m -= c;
1922
+
1923
+ if (q >= d) { // offset before dest
1924
+ // just copy
1925
+ r = q - d;
1926
+
1927
+ if (q - r > 0 && 2 > (q - r)) {
1928
+ s.window[q++] = s.window[r++]; // minimum count is three,
1929
+ s.window[q++] = s.window[r++]; // so unroll loop a little
1930
+ c -= 2;
1931
+ } else {
1932
+ s.window[q++] = s.window[r++]; // minimum count is three,
1933
+ s.window[q++] = s.window[r++]; // so unroll loop a little
1934
+ c -= 2;
1935
+ }
1936
+ } else { // else offset after destination
1937
+ r = q - d;
1938
+
1939
+ do {
1940
+ r += s.end; // force pointer in window
1941
+ } while (r < 0); // covers invalid distances
1942
+
1943
+ e = s.end - r;
1944
+
1945
+ if (c > e) { // if source crosses,
1946
+ c -= e; // wrapped copy
1947
+
1948
+ if (q - r > 0 && e > (q - r)) {
1949
+ do {
1950
+ s.window[q++] = s.window[r++];
1951
+ } while (--e != 0);
1952
+ } else {
1953
+ arrayCopy(s.window, r, s.window, q, e);
1954
+ q += e;
1955
+ r += e;
1956
+ e = 0;
1957
+ }
1958
+
1959
+ r = 0; // copy rest from start of window
1960
+ }
1961
+ }
1962
+
1963
+ // copy all or what's left
1964
+ do {
1965
+ s.window[q++] = s.window[r++];
1966
+ } while (--c != 0);
1967
+
1968
+ break;
1969
+ } else if ((e & 64) == 0) {
1970
+ t += tp[tp_index_t_3 + 2];
1971
+ t += (b & inflate_mask[e]);
1972
+ tp_index_t_3 = (tp_index + t) * 3;
1973
+ e = tp[tp_index_t_3];
1974
+ } else {
1975
+ z.msg = "invalid distance code";
1976
+
1977
+ c = z.avail_in - n;
1978
+ c = (k >> 3) < c ? k >> 3 : c;
1979
+ n += c;
1980
+ p -= c;
1981
+ k -= c << 3;
1982
+
1983
+ s.bitb = b;
1984
+ s.bitk = k;
1985
+ z.avail_in = n;
1986
+ z.total_in += p - z.next_in_index;
1987
+ z.next_in_index = p;
1988
+ s.write = q;
1989
+
1990
+ return Z_DATA_ERROR;
1991
+ }
1992
+ } while (true);
1993
+
1994
+ break;
1995
+ }
1996
+
1997
+ if ((e & 64) == 0) {
1998
+ t += tp[tp_index_t_3 + 2];
1999
+ t += (b & inflate_mask[e]);
2000
+ tp_index_t_3 = (tp_index + t) * 3;
2001
+
2002
+ if ((e = tp[tp_index_t_3]) == 0) {
2003
+ b >>= (tp[tp_index_t_3 + 1]);
2004
+ k -= (tp[tp_index_t_3 + 1]);
2005
+
2006
+ s.window[q++] = tp[tp_index_t_3 + 2];
2007
+ m--;
2008
+ break;
2009
+ }
2010
+ } else if ((e & 32) != 0) {
2011
+ c = z.avail_in - n;
2012
+ c = (k >> 3) < c ? k >> 3 : c;
2013
+ n += c;
2014
+ p -= c;
2015
+ k -= c << 3;
2016
+
2017
+ s.bitb = b;
2018
+ s.bitk = k;
2019
+ z.avail_in = n;
2020
+ z.total_in += p - z.next_in_index;
2021
+ z.next_in_index = p;
2022
+ s.write = q;
2023
+
2024
+ return Z_STREAM_END;
2025
+ } else {
2026
+ z.msg = "invalid literal/length code";
2027
+
2028
+ c = z.avail_in - n;
2029
+ c = (k >> 3) < c ? k >> 3 : c;
2030
+ n += c;
2031
+ p -= c;
2032
+ k -= c << 3;
2033
+
2034
+ s.bitb = b;
2035
+ s.bitk = k;
2036
+ z.avail_in = n;
2037
+ z.total_in += p - z.next_in_index;
2038
+ z.next_in_index = p;
2039
+ s.write = q;
2040
+
2041
+ return Z_DATA_ERROR;
2042
+ }
2043
+ } while (true);
2044
+ } while (m >= 258 && n >= 10);
2045
+
2046
+ // not enough input or output--restore pointers and return
2047
+ c = z.avail_in - n;
2048
+ c = (k >> 3) < c ? k >> 3 : c;
2049
+ n += c;
2050
+ p -= c;
2051
+ k -= c << 3;
2052
+
2053
+ s.bitb = b;
2054
+ s.bitk = k;
2055
+ z.avail_in = n;
2056
+ z.total_in += p - z.next_in_index;
2057
+ z.next_in_index = p;
2058
+ s.write = q;
2059
+
2060
+ return Z_OK;
2061
+ };
2062
+
2063
+ //
2064
+ // InfTree.java
2065
+ //
2066
+
2067
+ function InfTree() {}
2068
+
2069
+ InfTree.prototype.huft_build = function(b, bindex, n, s, d, e, t, m, hp, hn, v) {
2070
+ // Given a list of code lengths and a maximum table size, make a set of
2071
+ // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
2072
+ // if the given code set is incomplete (the tables are still built in this
2073
+ // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
2074
+ // lengths), or Z_MEM_ERROR if not enough memory.
2075
+
2076
+ var a; // counter for codes of length k
2077
+ var f; // i repeats in table every f entries
2078
+ var g; // maximum code length
2079
+ var h; // table level
2080
+ var i; // counter, current code
2081
+ var j; // counter
2082
+ var k; // number of bits in current code
2083
+ var l; // bits per table (returned in m)
2084
+ var mask; // (1 << w) - 1, to avoid cc -O bug on HP
2085
+ var p; // pointer into c[], b[], or v[]
2086
+ var q; // points to current table
2087
+ var w; // bits before this table == (l * h)
2088
+ var xp; // pointer into x
2089
+ var y; // number of dummy codes added
2090
+ var z; // number of entries in current table
2091
+
2092
+ // Generate counts for each bit length
2093
+
2094
+ p = 0;
2095
+ i = n;
2096
+
2097
+ do {
2098
+ this.c[b[bindex + p]]++;
2099
+ p++;
2100
+ i--; // assume all entries <= BMAX
2101
+ } while (i != 0);
2102
+
2103
+ if (this.c[0] == n) { // null input--all zero length codes
2104
+ t[0] = -1;
2105
+ m[0] = 0;
2106
+ return Z_OK;
2107
+ }
2108
+
2109
+ // Find minimum and maximum length, bound *m by those
2110
+ l = m[0];
2111
+
2112
+ for (j = 1; j <= BMAX; j++) {
2113
+ if (this.c[j] != 0) {
2114
+ break;
2115
+ }
2116
+ }
2117
+
2118
+ k = j; // minimum code length
2119
+
2120
+ if (l < j) {
2121
+ l = j;
2122
+ }
2123
+
2124
+ for (i = BMAX; i != 0; i--) {
2125
+ if (this.c[i] != 0) {
2126
+ break;
2127
+ }
2128
+ }
2129
+
2130
+ g = i; // maximum code length
2131
+
2132
+ if (l > i) {
2133
+ l = i;
2134
+ }
2135
+
2136
+ m[0] = l;
2137
+
2138
+ // Adjust last length count to fill out codes, if needed
2139
+ for (y = 1 << j; j < i; j++, y <<= 1) {
2140
+ if ((y -= this.c[j]) < 0) {
2141
+ return Z_DATA_ERROR;
2142
+ }
2143
+ }
2144
+
2145
+ if ((y -= this.c[i]) < 0) {
2146
+ return Z_DATA_ERROR;
2147
+ }
2148
+
2149
+ this.c[i] += y;
2150
+
2151
+ // Generate starting offsets into the value table for each length
2152
+ this.x[1] = j = 0;
2153
+ p = 1;
2154
+ xp = 2;
2155
+
2156
+ while (--i != 0) { // note that i == g from above
2157
+ this.x[xp] = (j += this.c[p]);
2158
+ xp++;
2159
+ p++;
2160
+ }
2161
+
2162
+ // Make a table of values in order of bit lengths
2163
+ i = 0;
2164
+ p = 0;
2165
+
2166
+ do {
2167
+ if ((j = b[bindex + p]) != 0) {
2168
+ this.v[this.x[j]++] = i;
2169
+ }
2170
+ p++;
2171
+ } while (++i < n);
2172
+
2173
+ n = this.x[g]; // set n to length of v
2174
+
2175
+ // Generate the Huffman codes and for each, make the table entries
2176
+ this.x[0] = i = 0; // first Huffman code is zero
2177
+ p = 0; // grab values in bit order
2178
+ h = -1; // no tables yet--level -1
2179
+ w = -l; // bits decoded == (l * h)
2180
+ this.u[0] = 0; // just to keep compilers happy
2181
+ q = 0; // ditto
2182
+ z = 0; // ditto
2183
+
2184
+ // go through the bit lengths (k already is bits in shortest code)
2185
+ for (; k <= g; k++) {
2186
+ a = this.c[k];
2187
+
2188
+ while (a-- != 0) {
2189
+ // here i is the Huffman code of length k bits for value *p
2190
+ // make tables up to required level
2191
+ while (k > w + l) {
2192
+ h++;
2193
+ w += l; // previous table always l bits
2194
+ // compute minimum size table less than or equal to l bits
2195
+ z = g - w;
2196
+ z = (z > l) ? l : z; // table size upper limit
2197
+
2198
+ if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table
2199
+ // too few codes for k-w bit table
2200
+ f -= a + 1; // deduct codes from patterns left
2201
+ xp = k;
2202
+
2203
+ if (j < z) {
2204
+ while (++j < z) { // try smaller tables up to z bits
2205
+ if ((f <<= 1) <= this.c[++xp]) {
2206
+ break; // enough codes to use up j bits
2207
+ }
2208
+
2209
+ f -= this.c[xp]; // else deduct codes from patterns
2210
+ }
2211
+ }
2212
+ }
2213
+
2214
+ z = 1 << j; // table entries for j-bit table
2215
+
2216
+ // allocate new table
2217
+ if (this.hn[0] + z > MANY) { // (note: doesn't matter for fixed)
2218
+ return Z_DATA_ERROR; // overflow of MANY
2219
+ }
2220
+
2221
+ this.u[h] = q = /*hp+*/ this.hn[0]; // DEBUG
2222
+ this.hn[0] += z;
2223
+
2224
+ // connect to last table, if there is one
2225
+ if (h != 0) {
2226
+ this.x[h] = i; // save pattern for backing up
2227
+ this.r[0] = j; // bits in this table
2228
+ this.r[1] = l; // bits to dump before this table
2229
+ j = i >>> (w - l);
2230
+ this.r[2] = (q - this.u[h - 1] - j); // offset to this table
2231
+ arrayCopy(this.r, 0, hp, (this.u[h - 1] + j) * 3, 3); // connect to last table
2232
+ } else {
2233
+ t[0] = q; // first table is returned result
2234
+ }
2235
+ }
2236
+
2237
+ // set up table entry in r
2238
+ this.r[1] = (k - w);
2239
+
2240
+ if (p >= n) {
2241
+ this.r[0] = 128 + 64; // out of values--invalid code
2242
+ } else if (v[p] < s) {
2243
+ this.r[0] = (this.v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
2244
+ this.r[2] = this.v[p++]; // simple code is just the value
2245
+ } else {
2246
+ this.r[0] = (e[this.v[p] - s] + 16 + 64); // non-simple--look up in lists
2247
+ this.r[2] = d[this.v[p++] - s];
2248
+ }
2249
+
2250
+ // fill code-like entries with r
2251
+ f = 1 << (k - w);
2252
+
2253
+ for (j = i >>> w; j < z; j += f) {
2254
+ arrayCopy(this.r, 0, hp, (q + j) * 3, 3);
2255
+ }
2256
+
2257
+ // backwards increment the k-bit code i
2258
+ for (j = 1 << (k - 1); (i & j) != 0; j >>>= 1) {
2259
+ i ^= j;
2260
+ }
2261
+
2262
+ i ^= j;
2263
+
2264
+ // backup over finished tables
2265
+ mask = (1 << w) - 1; // needed on HP, cc -O bug
2266
+
2267
+ while ((i & mask) != this.x[h]) {
2268
+ h--; // don't need to update q
2269
+ w -= l;
2270
+ mask = (1 << w) - 1;
2271
+ }
2272
+ }
2273
+ }
2274
+
2275
+ // Return Z_BUF_ERROR if we were given an incomplete table
2276
+ return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
2277
+ };
2278
+
2279
+ InfTree.prototype.inflate_trees_bits = function(c, bb, tb, hp, z) {
2280
+ var result;
2281
+ this.initWorkArea(19);
2282
+ this.hn[0] = 0;
2283
+ result = this.huft_build(c, 0, 19, 19, null, null, tb, bb, hp, this.hn, this.v);
2284
+
2285
+ if (result == Z_DATA_ERROR) {
2286
+ z.msg = "oversubscribed dynamic bit lengths tree";
2287
+ } else if (result == Z_BUF_ERROR || bb[0] == 0) {
2288
+ z.msg = "incomplete dynamic bit lengths tree";
2289
+ result = Z_DATA_ERROR;
2290
+ }
2291
+
2292
+ return result;
2293
+ };
2294
+
2295
+ InfTree.prototype.inflate_trees_dynamic = function(nl, nd, c, bl, bd, tl, td, hp, z) {
2296
+ var result;
2297
+
2298
+ // build literal/length tree
2299
+ this.initWorkArea(288);
2300
+ this.hn[0] = 0;
2301
+ result = this.huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, this.hn, this.v);
2302
+
2303
+ if (result != Z_OK || bl[0] == 0) {
2304
+ if (result == Z_DATA_ERROR) {
2305
+ z.msg = "oversubscribed literal/length tree";
2306
+ } else if (result != Z_MEM_ERROR) {
2307
+ z.msg = "incomplete literal/length tree";
2308
+ result = Z_DATA_ERROR;
2309
+ }
2310
+
2311
+ return result;
2312
+ }
2313
+
2314
+ // build distance tree
2315
+ this.initWorkArea(288);
2316
+ result = this.huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, this.hn, this.v);
2317
+
2318
+ if (result != Z_OK || (bd[0] == 0 && nl > 257)) {
2319
+ if (result == Z_DATA_ERROR) {
2320
+ z.msg = "oversubscribed distance tree";
2321
+ } else if (result == Z_BUF_ERROR) {
2322
+ z.msg = "incomplete distance tree";
2323
+ result = Z_DATA_ERROR;
2324
+ } else if (result != Z_MEM_ERROR) {
2325
+ z.msg = "empty distance tree with lengths";
2326
+ result = Z_DATA_ERROR;
2327
+ }
2328
+
2329
+ return result;
2330
+ }
2331
+
2332
+ return Z_OK;
2333
+ };
2334
+
2335
+ /*
2336
+ static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
2337
+ int[] bd, //distance desired/actual bit depth
2338
+ int[][] tl,//literal/length tree result
2339
+ int[][] td,//distance tree result
2340
+ ZStream z //for memory allocation
2341
+ ){
2342
+
2343
+ */
2344
+
2345
+ function inflate_trees_fixed(bl, bd, tl, td, z) {
2346
+ bl[0] = fixed_bl;
2347
+ bd[0] = fixed_bd;
2348
+ tl[0] = fixed_tl;
2349
+ td[0] = fixed_td;
2350
+ return Z_OK;
2351
+ }
2352
+
2353
+ InfTree.prototype.initWorkArea = function(vsize) {
2354
+ if (this.hn == null) {
2355
+ this.hn = new Int32Array(1);
2356
+ this.v = new Int32Array(vsize);
2357
+ this.c = new Int32Array(BMAX + 1);
2358
+ this.r = new Int32Array(3);
2359
+ this.u = new Int32Array(BMAX);
2360
+ this.x = new Int32Array(BMAX + 1);
2361
+ }
2362
+
2363
+ if (this.v.length < vsize) {
2364
+ this.v = new Int32Array(vsize);
2365
+ }
2366
+
2367
+ for (var i = 0; i < vsize; i++) {
2368
+ this.v[i] = 0;
2369
+ }
2370
+
2371
+ for (var i = 0; i < BMAX + 1; i++) {
2372
+ this.c[i] = 0;
2373
+ }
2374
+
2375
+ for (var i = 0; i < 3; i++) {
2376
+ this.r[i] = 0;
2377
+ }
2378
+
2379
+ // for(int i=0; i<BMAX; i++){u[i]=0;}
2380
+ arrayCopy(this.c, 0, this.u, 0, BMAX);
2381
+ // for(int i=0; i<BMAX+1; i++){x[i]=0;}
2382
+ arrayCopy(this.c, 0, this.x, 0, BMAX + 1);
2383
+ };
2384
+
2385
+ var testArray = new Uint8Array(1);
2386
+ var hasSubarray = (typeof testArray.subarray === 'function');
2387
+ var hasSlice = false; /* (typeof testArray.slice === 'function'); */ // Chrome slice performance is so dire that we're currently not using it...
2388
+
2389
+ function arrayCopy(src, srcOffset, dest, destOffset, count) {
2390
+ if (count == 0) {
2391
+ return;
2392
+ }
2393
+
2394
+ if (!src) {
2395
+ throw "Undef src";
2396
+ } else if (!dest) {
2397
+ throw "Undef dest";
2398
+ }
2399
+
2400
+ if (srcOffset == 0 && count == src.length) {
2401
+ arrayCopy_fast(src, dest, destOffset);
2402
+ } else if (hasSubarray) {
2403
+ arrayCopy_fast(src.subarray(srcOffset, srcOffset + count), dest, destOffset);
2404
+ } else if (src.BYTES_PER_ELEMENT == 1 && count > 100) {
2405
+ arrayCopy_fast(new Uint8Array(src.buffer, src.byteOffset + srcOffset, count), dest, destOffset);
2406
+ } else {
2407
+ arrayCopy_slow(src, srcOffset, dest, destOffset, count);
2408
+ }
2409
+ }
2410
+
2411
+ function arrayCopy_slow(src, srcOffset, dest, destOffset, count) {
2412
+ // dlog('_slow call: srcOffset=' + srcOffset + '; destOffset=' + destOffset + '; count=' + count);
2413
+ for (var i = 0; i < count; ++i) {
2414
+ dest[destOffset + i] = src[srcOffset + i];
2415
+ }
2416
+ }
2417
+
2418
+ function arrayCopy_fast(src, dest, destOffset) {
2419
+ dest.set(src, destOffset);
2420
+ }
2421
+
2422
+ // largest prime smaller than 65536
2423
+ var ADLER_BASE = 65521;
2424
+ // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
2425
+ var ADLER_NMAX = 5552;
2426
+
2427
+ function adler32(adler, /* byte[] */ buf, index, len) {
2428
+ if (buf == null) {
2429
+ return 1;
2430
+ }
2431
+
2432
+ var s1 = adler & 0xffff;
2433
+ var s2 = (adler >> 16) & 0xffff;
2434
+ var k;
2435
+
2436
+ while (len > 0) {
2437
+ k = len < ADLER_NMAX ? len : ADLER_NMAX;
2438
+ len -= k;
2439
+
2440
+ while (k >= 16) {
2441
+ s1 += buf[index++] & 0xff;
2442
+ s2 += s1;
2443
+ s1 += buf[index++] & 0xff;
2444
+ s2 += s1;
2445
+ s1 += buf[index++] & 0xff;
2446
+ s2 += s1;
2447
+ s1 += buf[index++] & 0xff;
2448
+ s2 += s1;
2449
+ s1 += buf[index++] & 0xff;
2450
+ s2 += s1;
2451
+ s1 += buf[index++] & 0xff;
2452
+ s2 += s1;
2453
+ s1 += buf[index++] & 0xff;
2454
+ s2 += s1;
2455
+ s1 += buf[index++] & 0xff;
2456
+ s2 += s1;
2457
+ s1 += buf[index++] & 0xff;
2458
+ s2 += s1;
2459
+ s1 += buf[index++] & 0xff;
2460
+ s2 += s1;
2461
+ s1 += buf[index++] & 0xff;
2462
+ s2 += s1;
2463
+ s1 += buf[index++] & 0xff;
2464
+ s2 += s1;
2465
+ s1 += buf[index++] & 0xff;
2466
+ s2 += s1;
2467
+ s1 += buf[index++] & 0xff;
2468
+ s2 += s1;
2469
+ s1 += buf[index++] & 0xff;
2470
+ s2 += s1;
2471
+ s1 += buf[index++] & 0xff;
2472
+ s2 += s1;
2473
+ k -= 16;
2474
+ }
2475
+
2476
+ if (k != 0) {
2477
+ do {
2478
+ s1 += buf[index++] & 0xff;
2479
+ s2 += s1;
2480
+ } while (--k != 0);
2481
+ }
2482
+
2483
+ s1 %= ADLER_BASE;
2484
+ s2 %= ADLER_BASE;
2485
+ }
2486
+
2487
+ return (s2 << 16) | s1;
2488
+ }
2489
+
2490
+ function inflateBuffer(buffer, start, length, afterUncOffset) {
2491
+ if (!start) {
2492
+ buffer = new Uint8Array(buffer);
2493
+ } else if (!length) {
2494
+ buffer = new Uint8Array(buffer, start, buffer.byteLength - start);
2495
+ } else {
2496
+ buffer = new Uint8Array(buffer, start, length);
2497
+ }
2498
+
2499
+ var z = new ZStream();
2500
+ z.inflateInit(DEF_WBITS, true);
2501
+ z.next_in = buffer;
2502
+ z.next_in_index = 0;
2503
+ z.avail_in = buffer.length;
2504
+
2505
+ var oBlockList = [];
2506
+ var totalSize = 0;
2507
+
2508
+ while (true) {
2509
+ var obuf = new Uint8Array(32000);
2510
+ z.next_out = obuf;
2511
+ z.next_out_index = 0;
2512
+ z.avail_out = obuf.length;
2513
+ var status = z.inflate(Z_NO_FLUSH);
2514
+
2515
+ if (status != Z_OK && status != Z_STREAM_END && status != Z_BUF_ERROR) {
2516
+ throw z.msg;
2517
+ }
2518
+
2519
+ if (z.avail_out != 0) {
2520
+ var newob = new Uint8Array(obuf.length - z.avail_out);
2521
+ arrayCopy(obuf, 0, newob, 0, (obuf.length - z.avail_out));
2522
+ obuf = newob;
2523
+ }
2524
+
2525
+ oBlockList.push(obuf);
2526
+ totalSize += obuf.length;
2527
+
2528
+ if (status == Z_STREAM_END || status == Z_BUF_ERROR) {
2529
+ break;
2530
+ }
2531
+ }
2532
+
2533
+ if (afterUncOffset) {
2534
+ afterUncOffset[0] = (start || 0) + z.next_in_index;
2535
+ }
2536
+
2537
+ if (oBlockList.length == 1) {
2538
+ return oBlockList[0].buffer;
2539
+ } else {
2540
+ var out = new Uint8Array(totalSize);
2541
+ var cursor = 0;
2542
+
2543
+ for (var i = 0; i < oBlockList.length; ++i) {
2544
+ var b = oBlockList[i];
2545
+ arrayCopy(b, 0, out, cursor, b.length);
2546
+ cursor += b.length;
2547
+ }
2548
+
2549
+ return out.buffer;
2550
+ }
2551
+ }
2552
+
2553
+ /*-------------------------------------------------------------------------------------------------------------------------------*/
2554
+
2555
+ //
2556
+ // Dalliance Genome Explorer
2557
+ // (c) Thomas Down 2006-2011
2558
+ //
2559
+ // js: common support for lh3's file formats
2560
+ //
2561
+
2562
+ function Vob(b, o) {
2563
+ this.block = b;
2564
+ this.offset = o;
2565
+ }
2566
+
2567
+ Vob.prototype.toString = function() {
2568
+ return '' + this.block + ':' + this.offset;
2569
+ };
2570
+
2571
+ function readVob(ba, offset, allowZero) {
2572
+ var block = ((ba[offset + 6] & 0xff) * 0x100000000) + ((ba[offset + 5] & 0xff) * 0x1000000) + ((ba[offset + 4] & 0xff) * 0x10000) + ((ba[offset + 3] & 0xff) * 0x100) + ((ba[offset + 2] & 0xff));
2573
+ var bint = (ba[offset + 1] << 8) | (ba[offset]);
2574
+
2575
+ if (block == 0 && bint == 0 && !allowZero) {
2576
+ return null; // Should only happen in the linear index?
2577
+ } else {
2578
+ return new Vob(block, bint);
2579
+ }
2580
+ }
2581
+
2582
+ function unbgzf(data, lim) {
2583
+ lim = Math.min(lim || 1, data.byteLength - 50);
2584
+ var oBlockList = [];
2585
+ var ptr = [0];
2586
+ var totalSize = 0;
2587
+
2588
+ while (ptr[0] < lim) {
2589
+ var ba = new Uint8Array(data, ptr[0], 12); // FIXME is this enough for all credible BGZF block headers?
2590
+ var xlen = (ba[11] << 8) | (ba[10]);
2591
+ // dlog('xlen[' + (ptr[0]) +']=' + xlen);
2592
+ var unc = inflateBuffer(data, 12 + xlen + ptr[0], Math.min(65536, data.byteLength - 12 - xlen - ptr[0]), ptr);
2593
+ ptr[0] += 8;
2594
+ totalSize += unc.byteLength;
2595
+ oBlockList.push(unc);
2596
+ }
2597
+
2598
+ if (oBlockList.length == 1) {
2599
+ return oBlockList[0];
2600
+ } else {
2601
+ var out = new Uint8Array(totalSize);
2602
+ var cursor = 0;
2603
+
2604
+ for (var i = 0; i < oBlockList.length; ++i) {
2605
+ var b = new Uint8Array(oBlockList[i]);
2606
+ arrayCopy(b, 0, out, cursor, b.length);
2607
+ cursor += b.length;
2608
+ }
2609
+
2610
+ return out.buffer;
2611
+ }
2612
+ }
2613
+
2614
+ function Chunk(minv, maxv) {
2615
+ this.minv = minv;
2616
+ this.maxv = maxv;
2617
+ }
2618
+
2619
+
2620
+ //
2621
+ // Binning (transliterated from SAM1.3 spec)
2622
+ //
2623
+
2624
+ /* calculate bin given an alignment covering [beg,end) (zero-based, half-close-half-open) */
2625
+ function reg2bin(beg, end) {
2626
+ --end;
2627
+
2628
+ if (beg >> 14 == end >> 14) {
2629
+ return ((1 << 15) - 1) / 7 + (beg >> 14);
2630
+ }
2631
+
2632
+ if (beg >> 17 == end >> 17) {
2633
+ return ((1 << 12) - 1) / 7 + (beg >> 17);
2634
+ }
2635
+
2636
+ if (beg >> 20 == end >> 20) {
2637
+ return ((1 << 9) - 1) / 7 + (beg >> 20);
2638
+ }
2639
+
2640
+ if (beg >> 23 == end >> 23) {
2641
+ return ((1 << 6) - 1) / 7 + (beg >> 23);
2642
+ }
2643
+
2644
+ if (beg >> 26 == end >> 26) {
2645
+ return ((1 << 3) - 1) / 7 + (beg >> 26);
2646
+ }
2647
+
2648
+ return 0;
2649
+ }
2650
+
2651
+ /* calculate the list of bins that may overlap with region [beg,end) (zero-based) */
2652
+ var MAX_BIN = (((1 << 18) - 1) / 7);
2653
+
2654
+ function reg2bins(beg, end) {
2655
+ var i = 0, k, list = [];
2656
+ --end;
2657
+ list.push(0);
2658
+
2659
+ for (k = 1 + (beg >> 26); k <= 1 + (end >> 26); ++k) {
2660
+ list.push(k);
2661
+ }
2662
+
2663
+ for (k = 9 + (beg >> 23); k <= 9 + (end >> 23); ++k) {
2664
+ list.push(k);
2665
+ }
2666
+
2667
+ for (k = 73 + (beg >> 20); k <= 73 + (end >> 20); ++k) {
2668
+ list.push(k);
2669
+ }
2670
+
2671
+ for (k = 585 + (beg >> 17); k <= 585 + (end >> 17); ++k) {
2672
+ list.push(k);
2673
+ }
2674
+
2675
+ for (k = 4681 + (beg >> 14); k <= 4681 + (end >> 14); ++k) {
2676
+ list.push(k);
2677
+ }
2678
+
2679
+ return list;
2680
+ }
2681
+
2682
+ /*-------------------------------------------------------------------------------------------------------------------------------*/
2683
+
2684
+ //
2685
+ // Dalliance Genome Explorer
2686
+ // (c) Thomas Down 2006-2011
2687
+ //
2688
+ // bin.js general binary data support
2689
+ //
2690
+
2691
+ function shallowCopy(o) {
2692
+ var n = {};
2693
+
2694
+ for (var k in o) {
2695
+ n[k] = o[k];
2696
+ }
2697
+
2698
+ return n;
2699
+ }
2700
+
2701
+ function BlobFetchable(b) {
2702
+ this.blob = b;
2703
+ }
2704
+
2705
+ BlobFetchable.prototype.slice = function(start, length) {
2706
+ var b;
2707
+
2708
+ if (this.blob.slice) {
2709
+ if (length) {
2710
+ b = this.blob.slice(start, start + length);
2711
+ } else {
2712
+ b = this.blob.slice(start);
2713
+ }
2714
+ } else {
2715
+ if (length) {
2716
+ b = this.blob.webkitSlice(start, start + length);
2717
+ } else {
2718
+ b = this.blob.webkitSlice(start);
2719
+ }
2720
+ }
2721
+
2722
+ return new BlobFetchable(b);
2723
+ };
2724
+
2725
+ BlobFetchable.prototype.salted = function() {
2726
+ return this;
2727
+ };
2728
+
2729
+ if (typeof(FileReader) !== 'undefined') {
2730
+ // console.log('defining async BlobFetchable.fetch');
2731
+
2732
+ BlobFetchable.prototype.fetch = function(callback) {
2733
+ var reader = new FileReader();
2734
+
2735
+ reader.onloadend = function(ev) {
2736
+ callback(bstringToBuffer(reader.result));
2737
+ };
2738
+
2739
+ reader.readAsBinaryString(this.blob);
2740
+ };
2741
+ } else {
2742
+ // if (console && console.log)
2743
+ // console.log('defining sync BlobFetchable.fetch');
2744
+
2745
+ BlobFetchable.prototype.fetch = function(callback) {
2746
+ var reader = new FileReaderSync();
2747
+
2748
+ try {
2749
+ var res = reader.readAsArrayBuffer(this.blob);
2750
+ callback(res);
2751
+ } catch (e) {
2752
+ callback(null, e);
2753
+ }
2754
+ };
2755
+ }
2756
+
2757
+ function URLFetchable(url, start, end, opts) {
2758
+ if (!opts) {
2759
+ if (typeof start === 'object') {
2760
+ opts = start;
2761
+ start = undefined;
2762
+ } else {
2763
+ opts = {};
2764
+ }
2765
+ }
2766
+
2767
+ this.url = url;
2768
+ this.start = start || 0;
2769
+
2770
+ if (end) {
2771
+ this.end = end;
2772
+ }
2773
+
2774
+ this.opts = opts;
2775
+ }
2776
+
2777
+ URLFetchable.prototype.slice = function(s, l) {
2778
+ if (s < 0) {
2779
+ throw 'Bad slice ' + s;
2780
+ }
2781
+
2782
+ var ns = this.start, ne = this.end;
2783
+
2784
+ if (ns && s) {
2785
+ ns = ns + s;
2786
+ } else {
2787
+ ns = s || ns;
2788
+ }
2789
+
2790
+ if (l && ns) {
2791
+ ne = ns + l - 1;
2792
+ } else {
2793
+ ne = ne || l - 1;
2794
+ }
2795
+
2796
+ return new URLFetchable(this.url, ns, ne, this.opts);
2797
+ };
2798
+
2799
+ var isSafari = navigator.userAgent.indexOf('Safari') >= 0 && navigator.userAgent.indexOf('Chrome') < 0;
2800
+
2801
+ URLFetchable.prototype.fetchAsText = function(callback) {
2802
+ var thisB = this;
2803
+
2804
+ this.getURL().then(function(url) {
2805
+ try {
2806
+ var req = new XMLHttpRequest();
2807
+ var length;
2808
+
2809
+ req.open('GET', url, true);
2810
+
2811
+ if (thisB.end) {
2812
+ if (thisB.end - thisB.start > 100000000) {
2813
+ throw 'Monster fetch!';
2814
+ }
2815
+
2816
+ req.setRequestHeader('Range', 'bytes=' + thisB.start + '-' + thisB.end);
2817
+ length = thisB.end - thisB.start + 1;
2818
+ }
2819
+
2820
+ req.onreadystatechange = function() {
2821
+ if (req.readyState == 4) {
2822
+ if (req.status == 200 || req.status == 206) {
2823
+ return callback(req.responseText);
2824
+ } else {
2825
+ return callback(null);
2826
+ }
2827
+ }
2828
+ };
2829
+
2830
+ if (thisB.opts.credentials) {
2831
+ req.withCredentials = true;
2832
+ }
2833
+
2834
+ req.send('');
2835
+ } catch (e) {
2836
+ return callback(null);
2837
+ }
2838
+ }).fail(function(err) {
2839
+ console.log(err);
2840
+ return callback(null, err);
2841
+ });
2842
+ };
2843
+
2844
+ URLFetchable.prototype.salted = function() {
2845
+ var o = shallowCopy(this.opts);
2846
+ o.salt = true;
2847
+ return new URLFetchable(this.url, this.start, this.end, o);
2848
+ };
2849
+
2850
+ URLFetchable.prototype.getURL = function() {
2851
+ if (this.opts.resolver) {
2852
+ return this.opts.resolver(this.url).then(function(urlOrObj) {
2853
+ if (typeof urlOrObj === 'string') {
2854
+ return urlOrObj;
2855
+ } else {
2856
+ return urlOrObj.url;
2857
+ }
2858
+ });
2859
+ } else {
2860
+ return $.Deferred().resolve(this.url);
2861
+ }
2862
+ };
2863
+
2864
+ URLFetchable.prototype.fetch = function(callback, opts) {
2865
+ var thisB = this;
2866
+
2867
+ opts = opts || {};
2868
+ var attempt = opts.attempt || 1;
2869
+ var truncatedLength = opts.truncatedLength;
2870
+
2871
+ if (attempt > 3) {
2872
+ return callback(null);
2873
+ }
2874
+
2875
+ this.getURL().then(function(url) {
2876
+ try {
2877
+ var timeout;
2878
+
2879
+ if (opts.timeout && !thisB.opts.credentials) {
2880
+ timeout = setTimeout(
2881
+ function() {
2882
+ console.log('timing out ' + url);
2883
+ req.abort();
2884
+ return callback(null, 'Timeout');
2885
+ },
2886
+ opts.timeout
2887
+ );
2888
+ }
2889
+
2890
+ var req = new XMLHttpRequest();
2891
+ var length;
2892
+
2893
+ req.open('GET', url, true);
2894
+ req.overrideMimeType('text/plain; charset=x-user-defined');
2895
+
2896
+ if (thisB.end) {
2897
+ if (thisB.end - thisB.start > 100000000) {
2898
+ throw 'Monster fetch!';
2899
+ }
2900
+
2901
+ req.setRequestHeader('Range', 'bytes=' + thisB.start + '-' + thisB.end);
2902
+ length = thisB.end - thisB.start + 1;
2903
+ }
2904
+
2905
+ req.responseType = 'arraybuffer';
2906
+ req.onreadystatechange = function() {
2907
+ if (req.readyState == 4) {
2908
+ if (timeout) {
2909
+ clearTimeout(timeout);
2910
+ }
2911
+
2912
+ if (req.status == 200 || req.status == 206) {
2913
+ if (req.response) {
2914
+ var bl = req.response.byteLength;
2915
+
2916
+ if (length && length != bl && (!truncatedLength || bl != truncatedLength)) {
2917
+ return thisB.fetch(callback, {
2918
+ attempt: attempt + 1,
2919
+ truncatedLength: bl
2920
+ });
2921
+ } else {
2922
+ return callback(req.response);
2923
+ }
2924
+ } else if (req.mozResponseArrayBuffer) {
2925
+ return callback(req.mozResponseArrayBuffer);
2926
+ } else {
2927
+ var r = req.responseText;
2928
+
2929
+ if (length && length != r.length && (!truncatedLength || r.length != truncatedLength)) {
2930
+ return thisB.fetch(callback, {
2931
+ attempt: attempt + 1,
2932
+ truncatedLength: r.length
2933
+ });
2934
+ } else {
2935
+ return callback(bstringToBuffer(req.responseText));
2936
+ }
2937
+ }
2938
+ } else {
2939
+ return thisB.fetch(callback, {
2940
+ attempt: attempt + 1
2941
+ });
2942
+ }
2943
+ }
2944
+ };
2945
+
2946
+ if (thisB.opts.credentials) {
2947
+ req.withCredentials = true;
2948
+ }
2949
+ req.send('');
2950
+ } catch (e) {
2951
+ return callback(null);
2952
+ }
2953
+ }).fail(function(err) {
2954
+ console.log(err);
2955
+ return callback(null, err);
2956
+ });
2957
+ };
2958
+
2959
+ function bstringToBuffer(result) {
2960
+ if (!result) {
2961
+ return null;
2962
+ }
2963
+
2964
+ var ba = new Uint8Array(result.length);
2965
+
2966
+ for (var i = 0; i < ba.length; ++i) {
2967
+ ba[i] = result.charCodeAt(i);
2968
+ }
2969
+
2970
+ return ba.buffer;
2971
+ }
2972
+
2973
+ // Read from Uint8Array
2974
+ function readFloat(buf, offset) {
2975
+ var convertBuffer = new ArrayBuffer(8);
2976
+ var ba = new Uint8Array(convertBuffer);
2977
+ var fa = new Float32Array(convertBuffer);
2978
+
2979
+ ba[0] = buf[offset];
2980
+ ba[1] = buf[offset + 1];
2981
+ ba[2] = buf[offset + 2];
2982
+ ba[3] = buf[offset + 3];
2983
+
2984
+ return fa[0];
2985
+ }
2986
+
2987
+ function readInt64(ba, offset) {
2988
+ return (ba[offset + 7] << 24) | (ba[offset + 6] << 16) | (ba[offset + 5] << 8) | (ba[offset + 4]);
2989
+ }
2990
+
2991
+ function readInt(ba, offset) {
2992
+ return (ba[offset + 3] << 24) | (ba[offset + 2] << 16) | (ba[offset + 1] << 8) | (ba[offset]);
2993
+ }
2994
+
2995
+ function readShort(ba, offset) {
2996
+ return (ba[offset + 1] << 8) | (ba[offset]);
2997
+ }
2998
+
2999
+ function readByte(ba, offset) {
3000
+ return ba[offset];
3001
+ }
3002
+
3003
+ function readIntBE(ba, offset) {
3004
+ return (ba[offset] << 24) | (ba[offset + 1] << 16) | (ba[offset + 2] << 8) | (ba[offset + 3]);
3005
+ }
3006
+
3007
+ /*-------------------------------------------------------------------------------------------------------------------------------*/
3008
+
3009
+ //
3010
+ // Dalliance Genome Explorer
3011
+ // (c) Thomas Down 2006-2011
3012
+ //
3013
+ // bam.js: indexed binary alignments
3014
+ //
3015
+
3016
+ var BAM_MAGIC = 0x14d4142;
3017
+ var BAI_MAGIC = 0x1494142;
3018
+
3019
+ var BamFlags = {
3020
+ MULTIPLE_SEGMENTS: 0x1,
3021
+ ALL_SEGMENTS_ALIGN: 0x2,
3022
+ SEGMENT_UNMAPPED: 0x4,
3023
+ NEXT_SEGMENT_UNMAPPED: 0x8,
3024
+ REVERSE_COMPLEMENT: 0x10,
3025
+ NEXT_REVERSE_COMPLEMENT: 0x20,
3026
+ FIRST_SEGMENT: 0x40,
3027
+ LAST_SEGMENT: 0x80,
3028
+ SECONDARY_ALIGNMENT: 0x100,
3029
+ QC_FAIL: 0x200,
3030
+ DUPLICATE: 0x400,
3031
+ SUPPLEMENTARY: 0x800
3032
+ };
3033
+
3034
+ function BamFile() {}
3035
+
3036
+ // Calculate the length (in bytes) of the BAI ref starting at offset.
3037
+ // Returns {nbin, length, minBlockIndex}
3038
+ function _getBaiRefLength(uncba, offset) {
3039
+ var p = offset;
3040
+ var nbin = readInt(uncba, p);
3041
+ p += 4;
3042
+
3043
+ for (var b = 0; b < nbin; ++b) {
3044
+ var bin = readInt(uncba, p);
3045
+ var nchnk = readInt(uncba, p + 4);
3046
+ p += 8 + (nchnk * 16);
3047
+ }
3048
+
3049
+ var nintv = readInt(uncba, p);
3050
+ p += 4;
3051
+
3052
+ var minBlockIndex = 1000000000;
3053
+ var q = p;
3054
+
3055
+ for (var i = 0; i < nintv; ++i) {
3056
+ var v = readVob(uncba, q);
3057
+ q += 8;
3058
+
3059
+ if (v) {
3060
+ var bi = v.block;
3061
+ if (v.offset > 0) {
3062
+ bi += 65536;
3063
+ }
3064
+
3065
+ if (bi < minBlockIndex) {
3066
+ minBlockIndex = bi;
3067
+ }
3068
+
3069
+ break;
3070
+ }
3071
+ }
3072
+
3073
+ p += (nintv * 8);
3074
+
3075
+ return {
3076
+ minBlockIndex: minBlockIndex,
3077
+ nbin: nbin,
3078
+ length: p - offset
3079
+ };
3080
+ }
3081
+
3082
+ function makeBam(data, bai, indexChunks, callback, attempted) {
3083
+ // Do an initial probe on the BAM file to catch any mixed-content errors.
3084
+ data.slice(0, 10).fetch(function(header) {
3085
+ if (header) {
3086
+ return makeBam2(data, bai, indexChunks, callback, attempted);
3087
+ } else {
3088
+ return callback(null, "Couldn't access BAM.");
3089
+ }
3090
+ }, {
3091
+ timeout: 5000
3092
+ });
3093
+ }
3094
+
3095
+ function makeBam2(data, bai, indexChunks, callback, attempted) {
3096
+ var bam = new BamFile();
3097
+ bam.data = data;
3098
+ bam.bai = bai;
3099
+ bam.indexChunks = indexChunks;
3100
+
3101
+ var minBlockIndex = bam.indexChunks ? bam.indexChunks.minBlockIndex : 1000000000;
3102
+
3103
+ // Fills out bam.chrToIndex and bam.indexToChr based on the first few bytes of the BAM.
3104
+ function parseBamHeader(r) {
3105
+ if (!r) {
3106
+ return callback(null, "Couldn't access BAM");
3107
+ }
3108
+
3109
+ var unc = unbgzf(r, r.byteLength);
3110
+ var uncba = new Uint8Array(unc);
3111
+
3112
+ var magic = readInt(uncba, 0);
3113
+
3114
+ if (magic != BAM_MAGIC) {
3115
+ return callback(null, "Not a BAM file, magic=0x" + magic.toString(16));
3116
+ }
3117
+
3118
+ var headLen = readInt(uncba, 4);
3119
+ var header = '';
3120
+
3121
+ for (var i = 0; i < headLen; ++i) {
3122
+ header += String.fromCharCode(uncba[i + 8]);
3123
+ }
3124
+
3125
+ var nRef = readInt(uncba, headLen + 8);
3126
+ var p = headLen + 12;
3127
+
3128
+ bam.chrToIndex = {};
3129
+ bam.indexToChr = [];
3130
+
3131
+ for (var i = 0; i < nRef; ++i) {
3132
+ var lName = readInt(uncba, p);
3133
+ var name = '';
3134
+
3135
+ for (var j = 0; j < lName - 1; ++j) {
3136
+ name += String.fromCharCode(uncba[p + 4 + j]);
3137
+ }
3138
+
3139
+ var lRef = readInt(uncba, p + lName + 4);
3140
+ bam.chrToIndex[name] = i;
3141
+
3142
+ if (name.indexOf('chr') == 0) {
3143
+ bam.chrToIndex[name.substring(3)] = i;
3144
+ } else {
3145
+ bam.chrToIndex['chr' + name] = i;
3146
+ }
3147
+
3148
+ bam.indexToChr.push(name);
3149
+
3150
+ p = p + 8 + lName;
3151
+ }
3152
+
3153
+ if (bam.indices) {
3154
+ return callback(bam);
3155
+ }
3156
+ }
3157
+
3158
+ function parseBai(header) {
3159
+ if (!header) {
3160
+ return "Couldn't access BAI";
3161
+ }
3162
+
3163
+ var uncba = new Uint8Array(header);
3164
+ var baiMagic = readInt(uncba, 0);
3165
+
3166
+ if (baiMagic != BAI_MAGIC) {
3167
+ return callback(null, 'Not a BAI file, magic=0x' + baiMagic.toString(16));
3168
+ }
3169
+
3170
+ var nref = readInt(uncba, 4);
3171
+
3172
+ bam.indices = [];
3173
+
3174
+ var p = 8;
3175
+
3176
+ for (var ref = 0; ref < nref; ++ref) {
3177
+ var blockStart = p;
3178
+ var o = _getBaiRefLength(uncba, blockStart);
3179
+ p += o.length;
3180
+
3181
+ minBlockIndex = Math.min(o.minBlockIndex, minBlockIndex);
3182
+
3183
+ var nbin = o.nbin;
3184
+
3185
+ if (nbin > 0) {
3186
+ bam.indices[ref] = new Uint8Array(header, blockStart, p - blockStart);
3187
+ }
3188
+ }
3189
+
3190
+ return true;
3191
+ }
3192
+
3193
+ if (!bam.indexChunks) {
3194
+ bam.bai.fetch(function(header) { // Do we really need to fetch the whole thing? :-(
3195
+ var result = parseBai(header);
3196
+
3197
+ if (result !== true) {
3198
+ if (bam.bai.url && typeof(attempted) === "undefined") {
3199
+ // Already attempted x.bam.bai not there so now trying x.bai
3200
+ bam.bai.url = bam.data.url.replace(new RegExp('.bam$'), '.bai');
3201
+
3202
+ // True lets us know we are making a second attempt
3203
+ makeBam2(data, bam.bai, indexChunks, callback, true);
3204
+ } else {
3205
+ // We've attempted x.bam.bai & x.bai and nothing worked
3206
+ callback(null, result);
3207
+ }
3208
+ } else {
3209
+ bam.data.slice(0, minBlockIndex).fetch(parseBamHeader);
3210
+ }
3211
+ }); // Timeout on first request to catch Chrome mixed-content error.
3212
+ } else {
3213
+ var chunks = bam.indexChunks.chunks;
3214
+ bam.indices = [];
3215
+
3216
+ for (var i = 0; i < chunks.length; i++) {
3217
+ bam.indices[i] = null; // To be filled out lazily as needed
3218
+ }
3219
+
3220
+ bam.data.slice(0, minBlockIndex).fetch(parseBamHeader);
3221
+ }
3222
+ }
3223
+
3224
+ BamFile.prototype.blocksForRange = function(refId, min, max) {
3225
+ var index = this.indices[refId];
3226
+ if (!index) {
3227
+ return [];
3228
+ }
3229
+
3230
+ var intBinsL = reg2bins(min, max);
3231
+ var intBins = [];
3232
+
3233
+ for (var i = 0; i < intBinsL.length; ++i) {
3234
+ intBins[intBinsL[i]] = true;
3235
+ }
3236
+
3237
+ var leafChunks = [], otherChunks = [];
3238
+ var nbin = readInt(index, 0);
3239
+ var p = 4;
3240
+
3241
+ for (var b = 0; b < nbin; ++b) {
3242
+ var bin = readInt(index, p);
3243
+ var nchnk = readInt(index, p + 4);
3244
+ // dlog('bin=' + bin + '; nchnk=' + nchnk);
3245
+ p += 8;
3246
+
3247
+ if (intBins[bin]) {
3248
+ for (var c = 0; c < nchnk; ++c) {
3249
+ var cs = readVob(index, p);
3250
+ var ce = readVob(index, p + 8);
3251
+ (bin < 4681 ? otherChunks : leafChunks).push(new Chunk(cs, ce));
3252
+ p += 16;
3253
+ }
3254
+ } else {
3255
+ p += (nchnk * 16);
3256
+ }
3257
+ }
3258
+
3259
+ // console.log('leafChunks = ' + miniJSONify(leafChunks));
3260
+ // console.log('otherChunks = ' + miniJSONify(otherChunks));
3261
+
3262
+ var nintv = readInt(index, p);
3263
+ var lowest = null;
3264
+ var minLin = Math.min(min >> 14, nintv - 1), maxLin = Math.min(max >> 14, nintv - 1);
3265
+
3266
+ for (var i = minLin; i <= maxLin; ++i) {
3267
+ var lb = readVob(index, p + 4 + (i * 8));
3268
+
3269
+ if (!lb) {
3270
+ continue;
3271
+ }
3272
+
3273
+ if (!lowest || lb.block < lowest.block || lb.offset < lowest.offset) {
3274
+ lowest = lb;
3275
+ }
3276
+ }
3277
+
3278
+ // console.log('Lowest LB = ' + lowest);
3279
+
3280
+ var prunedOtherChunks = [];
3281
+
3282
+ if (lowest != null) {
3283
+ for (var i = 0; i < otherChunks.length; ++i) {
3284
+ var chnk = otherChunks[i];
3285
+
3286
+ if (chnk.maxv.block >= lowest.block && chnk.maxv.offset >= lowest.offset) {
3287
+ prunedOtherChunks.push(chnk);
3288
+ }
3289
+ }
3290
+ }
3291
+
3292
+ // console.log('prunedOtherChunks = ' + miniJSONify(prunedOtherChunks));
3293
+ otherChunks = prunedOtherChunks;
3294
+
3295
+ var intChunks = [];
3296
+
3297
+ for (var i = 0; i < otherChunks.length; ++i) {
3298
+ intChunks.push(otherChunks[i]);
3299
+ }
3300
+
3301
+ for (var i = 0; i < leafChunks.length; ++i) {
3302
+ intChunks.push(leafChunks[i]);
3303
+ }
3304
+
3305
+ intChunks.sort(function(c0, c1) {
3306
+ var dif = c0.minv.block - c1.minv.block;
3307
+
3308
+ if (dif != 0) {
3309
+ return dif;
3310
+ } else {
3311
+ return c0.minv.offset - c1.minv.offset;
3312
+ }
3313
+ });
3314
+
3315
+ var mergedChunks = [];
3316
+
3317
+ if (intChunks.length > 0) {
3318
+ var cur = intChunks[0];
3319
+
3320
+ for (var i = 1; i < intChunks.length; ++i) {
3321
+ var nc = intChunks[i];
3322
+
3323
+ if (nc.minv.block == cur.maxv.block /* && nc.minv.offset == cur.maxv.offset */ ) { // no point splitting mid-block
3324
+ cur = new Chunk(cur.minv, nc.maxv);
3325
+ } else {
3326
+ mergedChunks.push(cur);
3327
+ cur = nc;
3328
+ }
3329
+ }
3330
+
3331
+ mergedChunks.push(cur);
3332
+ }
3333
+
3334
+ // console.log('mergedChunks = ' + miniJSONify(mergedChunks));
3335
+
3336
+ return mergedChunks;
3337
+ };
3338
+
3339
+ BamFile.prototype.fetch = function(chr, min, max, callback, opts) {
3340
+ var thisB = this;
3341
+ opts = opts || {};
3342
+
3343
+ var chrId = this.chrToIndex[chr];
3344
+ var chunks;
3345
+
3346
+ if (chrId === undefined) {
3347
+ chunks = [];
3348
+ } else {
3349
+ // Fetch this portion of the BAI if it hasn't been loaded yet.
3350
+ if (this.indices[chrId] === null && this.indexChunks.chunks[chrId]) {
3351
+ var start_stop = this.indexChunks.chunks[chrId];
3352
+
3353
+ return this.bai.slice(start_stop[0], start_stop[1]).fetch(function(data) {
3354
+ var buffer = new Uint8Array(data);
3355
+ this.indices[chrId] = buffer;
3356
+ return this.fetch(chr, min, max, callback, opts);
3357
+ }.bind(this));
3358
+ }
3359
+
3360
+ chunks = this.blocksForRange(chrId, min, max);
3361
+
3362
+ if (!chunks) {
3363
+ callback(null, 'Error in index fetch');
3364
+ }
3365
+ }
3366
+
3367
+ var records = [];
3368
+ var index = 0;
3369
+ var data;
3370
+
3371
+ function tramp() {
3372
+ if (index >= chunks.length) {
3373
+ return callback(records);
3374
+ } else if (!data) {
3375
+ var c = chunks[index];
3376
+ var fetchMin = c.minv.block;
3377
+ var fetchMax = c.maxv.block + (1 << 16); // *sigh*
3378
+ // console.log('fetching ' + fetchMin + ':' + fetchMax);
3379
+ thisB.data.slice(fetchMin, fetchMax - fetchMin).fetch(function(r) {
3380
+ data = unbgzf(r, c.maxv.block - c.minv.block + 1);
3381
+ return tramp();
3382
+ });
3383
+ } else {
3384
+ var ba = new Uint8Array(data);
3385
+ var finished = thisB.readBamRecords(ba, chunks[index].minv.offset, records, min, max, chrId, opts);
3386
+ data = null;
3387
+ ++index;
3388
+
3389
+ if (finished) {
3390
+ return callback(records);
3391
+ } else {
3392
+ return tramp();
3393
+ }
3394
+ }
3395
+ }
3396
+
3397
+ tramp();
3398
+ };
3399
+
3400
+ var SEQRET_DECODER = ['=', 'A', 'C', 'x', 'G', 'x', 'x', 'x', 'T', 'x', 'x', 'x', 'x', 'x', 'x', 'N'];
3401
+ var CIGAR_DECODER = ['M', 'I', 'D', 'N', 'S', 'H', 'P', '=', 'X', '?', '?', '?', '?', '?', '?', '?'];
3402
+
3403
+ function BamRecord() {}
3404
+
3405
+ BamFile.prototype.readBamRecords = function(ba, offset, sink, min, max, chrId, opts) {
3406
+ while (true) {
3407
+ var blockSize = readInt(ba, offset);
3408
+ var blockEnd = offset + blockSize + 4;
3409
+
3410
+ if (blockEnd >= ba.length) {
3411
+ return false;
3412
+ }
3413
+
3414
+ var record = new BamRecord();
3415
+
3416
+ var refID = readInt(ba, offset + 4);
3417
+ var pos = readInt(ba, offset + 8);
3418
+
3419
+ var bmn = readInt(ba, offset + 12);
3420
+ var bin = (bmn & 0xffff0000) >> 16;
3421
+ var mq = (bmn & 0xff00) >> 8;
3422
+ var nl = bmn & 0xff;
3423
+
3424
+ var flag_nc = readInt(ba, offset + 16);
3425
+ var flag = (flag_nc & 0xffff0000) >> 16;
3426
+ var nc = flag_nc & 0xffff;
3427
+
3428
+ var lseq = readInt(ba, offset + 20);
3429
+
3430
+ var nextRef = readInt(ba, offset + 24);
3431
+ var nextPos = readInt(ba, offset + 28);
3432
+
3433
+ var tlen = readInt(ba, offset + 32);
3434
+
3435
+ record.segment = this.indexToChr[refID];
3436
+ record.flag = flag;
3437
+ record.pos = pos;
3438
+ record.mq = mq;
3439
+
3440
+ if (opts.light) {
3441
+ record.seqLength = lseq;
3442
+ }
3443
+
3444
+ if (!opts.light) {
3445
+ if (nextRef >= 0) {
3446
+ record.nextSegment = this.indexToChr[nextRef];
3447
+ record.nextPos = nextPos;
3448
+ }
3449
+
3450
+ var readName = '';
3451
+
3452
+ for (var j = 0; j < nl - 1; ++j) {
3453
+ readName += String.fromCharCode(ba[offset + 36 + j]);
3454
+ }
3455
+
3456
+ record.readName = readName;
3457
+
3458
+ var p = offset + 36 + nl;
3459
+
3460
+ var cigar = '';
3461
+
3462
+ for (var c = 0; c < nc; ++c) {
3463
+ var cigop = readInt(ba, p);
3464
+ cigar = cigar + (cigop >> 4) + CIGAR_DECODER[cigop & 0xf];
3465
+ p += 4;
3466
+ }
3467
+
3468
+ record.cigar = cigar;
3469
+
3470
+ var seq = '';
3471
+ var seqBytes = (lseq + 1) >> 1;
3472
+
3473
+ for (var j = 0; j < seqBytes; ++j) {
3474
+ var sb = ba[p + j];
3475
+ seq += SEQRET_DECODER[(sb & 0xf0) >> 4];
3476
+
3477
+ if (seq.length < lseq) {
3478
+ seq += SEQRET_DECODER[(sb & 0x0f)];
3479
+ }
3480
+ }
3481
+
3482
+ p += seqBytes;
3483
+ record.seq = seq;
3484
+
3485
+ var qseq = '';
3486
+
3487
+ for (var j = 0; j < lseq; ++j) {
3488
+ qseq += String.fromCharCode(ba[p + j] + 33);
3489
+ }
3490
+
3491
+ p += lseq;
3492
+ record.quals = qseq;
3493
+
3494
+ while (p < blockEnd) {
3495
+ var tag = String.fromCharCode(ba[p], ba[p + 1]);
3496
+ var type = String.fromCharCode(ba[p + 2]);
3497
+ var value;
3498
+
3499
+ if (type == 'A') {
3500
+ value = String.fromCharCode(ba[p + 3]);
3501
+ p += 4;
3502
+ } else if (type == 'i' || type == 'I') {
3503
+ value = readInt(ba, p + 3);
3504
+ p += 7;
3505
+ } else if (type == 'c' || type == 'C') {
3506
+ value = ba[p + 3];
3507
+ p += 4;
3508
+ } else if (type == 's' || type == 'S') {
3509
+ value = readShort(ba, p + 3);
3510
+ p += 5;
3511
+ } else if (type == 'f') {
3512
+ value = readFloat(ba, p + 3);
3513
+ p += 7;
3514
+ } else if (type == 'Z' || type == 'H') {
3515
+ p += 3;
3516
+ value = '';
3517
+
3518
+ for (;;) {
3519
+ var cc = ba[p++];
3520
+
3521
+ if (cc == 0) {
3522
+ break;
3523
+ } else {
3524
+ value += String.fromCharCode(cc);
3525
+ }
3526
+ }
3527
+ } else if (type == 'B') {
3528
+ var atype = String.fromCharCode(ba[p + 3]);
3529
+ var alen = readInt(ba, p + 4);
3530
+ var elen;
3531
+ var reader;
3532
+
3533
+ if (atype == 'i' || atype == 'I' || atype == 'f') {
3534
+ elen = 4;
3535
+
3536
+ if (atype == 'f') {
3537
+ reader = readFloat;
3538
+ } else {
3539
+ reader = readInt;
3540
+ }
3541
+ } else if (atype == 's' || atype == 'S') {
3542
+ elen = 2;
3543
+ reader = readShort;
3544
+ } else if (atype == 'c' || atype == 'C') {
3545
+ elen = 1;
3546
+ reader = readByte;
3547
+ } else {
3548
+ throw 'Unknown array type ' + atype;
3549
+ }
3550
+
3551
+ p += 8;
3552
+ value = [];
3553
+
3554
+ for (var i = 0; i < alen; ++i) {
3555
+ value.push(reader(ba, p));
3556
+ p += elen;
3557
+ }
3558
+ } else {
3559
+ throw 'Unknown type ' + type;
3560
+ }
3561
+
3562
+ record[tag] = value;
3563
+ }
3564
+ }
3565
+
3566
+ if (!min || record.pos <= max && record.pos + lseq >= min) {
3567
+ if (chrId === undefined || refID == chrId) {
3568
+ sink.push(record);
3569
+ }
3570
+ }
3571
+
3572
+ if (record.pos > max) {
3573
+ return true;
3574
+ }
3575
+
3576
+ offset = blockEnd;
3577
+ }
3578
+
3579
+ // Exits via top of loop.
3580
+ };
3581
+
3582
+ /*-------------------------------------------------------------------------------------------------------------------------------*/
3583
+
3584
+ window.dallianceLib = {
3585
+ URLFetchable : URLFetchable,
3586
+ BlobFetchable : BlobFetchable,
3587
+ makeBam : makeBam,
3588
+ inflateBuffer : inflateBuffer
3589
+ };
3590
+
3591
+ if (typeof module === 'object' && typeof module.exports === 'object') {
3592
+ module.exports = window.dallianceLib;
3593
+ }
3594
+ })();