-
Notifications
You must be signed in to change notification settings - Fork 0
/
subtitles-octopus-worker.js
executable file
·10258 lines (9270 loc) · 413 KB
/
subtitles-octopus-worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var Module = typeof Module !== "undefined" ? Module : {};
if (!Module.expectedDataFileDownloads) {
Module.expectedDataFileDownloads = 0;
Module.finishedDataFileDownloads = 0;
}
Module.expectedDataFileDownloads++;
(function() {
var loadPackage = function(metadata) {
var PACKAGE_PATH;
if (typeof window === "object") {
PACKAGE_PATH = window["encodeURIComponent"](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf("/")) + "/");
} else if (typeof location !== "undefined") {
PACKAGE_PATH = encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf("/")) + "/");
} else {
throw "using preloaded data can only be done on a web page or in a web worker";
}
var PACKAGE_NAME = "dist/js/subtitles-octopus-worker.data";
var REMOTE_PACKAGE_BASE = "subtitles-octopus-worker.data";
if (typeof Module["locateFilePackage"] === "function" && !Module["locateFile"]) {
Module["locateFile"] = Module["locateFilePackage"];
err("warning: you defined Module.locateFilePackage, that has been renamed to Module.locateFile (using your locateFilePackage for now)");
}
var REMOTE_PACKAGE_NAME = Module["locateFile"] ? Module["locateFile"](REMOTE_PACKAGE_BASE, "") : REMOTE_PACKAGE_BASE;
var REMOTE_PACKAGE_SIZE = metadata["remote_package_size"];
var PACKAGE_UUID = metadata["package_uuid"];
function fetchRemotePackage(packageName, packageSize, callback, errback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", packageName, true);
xhr.responseType = "arraybuffer";
xhr.onprogress = function(event) {
var url = packageName;
var size = packageSize;
if (event.total) size = event.total;
if (event.loaded) {
if (!xhr.addedTotal) {
xhr.addedTotal = true;
if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
Module.dataFileDownloads[url] = {
loaded: event.loaded,
total: size
};
} else {
Module.dataFileDownloads[url].loaded = event.loaded;
}
var total = 0;
var loaded = 0;
var num = 0;
for (var download in Module.dataFileDownloads) {
var data = Module.dataFileDownloads[download];
total += data.total;
loaded += data.loaded;
num++;
}
total = Math.ceil(total * Module.expectedDataFileDownloads / num);
if (Module["setStatus"]) Module["setStatus"]("Downloading data... (" + loaded + "/" + total + ")");
} else if (!Module.dataFileDownloads) {
if (Module["setStatus"]) Module["setStatus"]("Downloading data...");
}
};
xhr.onerror = function(event) {
throw new Error("NetworkError for: " + packageName);
};
xhr.onload = function(event) {
if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || xhr.status == 0 && xhr.response) {
var packageData = xhr.response;
callback(packageData);
} else {
throw new Error(xhr.statusText + " : " + xhr.responseURL);
}
};
xhr.send(null);
}
function handleError(error) {
console.error("package error:", error);
}
var fetchedCallback = null;
var fetched = Module["getPreloadedPackage"] ? Module["getPreloadedPackage"](REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE) : null;
if (!fetched) fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, function(data) {
if (fetchedCallback) {
fetchedCallback(data);
fetchedCallback = null;
} else {
fetched = data;
}
}, handleError);
function runWithFS() {
function assert(check, msg) {
if (!check) throw msg + new Error().stack;
}
Module["FS_createPath"]("/", "assets", true, true);
function DataRequest(start, end, audio) {
this.start = start;
this.end = end;
this.audio = audio;
}
DataRequest.prototype = {
requests: {},
open: function(mode, name) {
this.name = name;
this.requests[name] = this;
Module["addRunDependency"]("fp " + this.name);
},
send: function() {},
onload: function() {
var byteArray = this.byteArray.subarray(this.start, this.end);
this.finish(byteArray);
},
finish: function(byteArray) {
var that = this;
Module["FS_createPreloadedFile"](this.name, null, byteArray, true, true, function() {
Module["removeRunDependency"]("fp " + that.name);
}, function() {
if (that.audio) {
Module["removeRunDependency"]("fp " + that.name);
} else {
err("Preloading file " + that.name + " failed");
}
}, false, true);
this.requests[this.name] = null;
}
};
var files = metadata["files"];
for (var i = 0; i < files.length; ++i) {
new DataRequest(files[i]["start"], files[i]["end"], files[i]["audio"]).open("GET", files[i]["filename"]);
}
function processPackageData(arrayBuffer) {
Module.finishedDataFileDownloads++;
assert(arrayBuffer, "Loading data file failed.");
assert(arrayBuffer instanceof ArrayBuffer, "bad input to processPackageData");
var byteArray = new Uint8Array(arrayBuffer);
DataRequest.prototype.byteArray = byteArray;
var files = metadata["files"];
for (var i = 0; i < files.length; ++i) {
DataRequest.prototype.requests[files[i].filename].onload();
}
Module["removeRunDependency"]("datafile_dist/js/subtitles-octopus-worker.data");
}
Module["addRunDependency"]("datafile_dist/js/subtitles-octopus-worker.data");
if (!Module.preloadResults) Module.preloadResults = {};
Module.preloadResults[PACKAGE_NAME] = {
fromCache: false
};
if (fetched) {
processPackageData(fetched);
fetched = null;
} else {
fetchedCallback = processPackageData;
}
}
if (Module["calledRun"]) {
runWithFS();
} else {
if (!Module["preRun"]) Module["preRun"] = [];
Module["preRun"].push(runWithFS);
}
};
loadPackage({
"files": [ {
"start": 0,
"audio": 0,
"end": 145972,
"filename": "/assets/default.woff2"
}, {
"start": 145972,
"audio": 0,
"end": 146775,
"filename": "/assets/fonts.conf"
} ],
"remote_package_size": 146775,
"package_uuid": "43f55d8e-e644-4070-b252-e03ac41196bc"
});
})();
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
};
}
var hasNativeConsole = typeof console !== "undefined";
function makeCustomConsole() {
var console = function() {
function postConsoleMessage(prefix, args) {
postMessage({
target: "console-" + prefix,
content: JSON.stringify(Array.prototype.slice.call(args))
});
}
return {
log: function() {
postConsoleMessage("log", arguments);
},
debug: function() {
postConsoleMessage("debug", arguments);
},
info: function() {
postConsoleMessage("info", arguments);
},
warn: function() {
postConsoleMessage("warn", arguments);
},
error: function() {
postConsoleMessage("error", arguments);
}
};
}();
return console;
}
Module = Module || {};
Module["preRun"] = Module["preRun"] || [];
Module["preRun"].push(function() {
var i;
Module["FS_createFolder"]("/", "fonts", true, true);
if (!self.subContent) {
if (self.subUrl.endsWith(".br")) {
self.subContent = Module["BrotliDecode"](readBinary(self.subUrl));
} else {
self.subContent = read_(self.subUrl);
}
}
if (self.availableFonts && self.availableFonts.length !== 0) {
var sections = parseAss(self.subContent);
for (var i = 0; i < sections.length; i++) {
for (var j = 0; j < sections[i].body.length; j++) {
if (sections[i].body[j].key === "Style") {
self.writeFontToFS(sections[i].body[j].value["Fontname"]);
}
}
}
var regex = /\\fn([^\\}]*?)[\\}]/g;
var matches;
while (matches = regex.exec(self.subContent)) {
self.writeFontToFS(matches[1]);
}
}
if (self.subContent) {
Module["FS"].writeFile("/sub.ass", self.subContent);
}
self.subContent = null;
var fontFiles = self.fontFiles || [];
for (i = 0; i < fontFiles.length; i++) {
Module["FS_createPreloadedFile"]("/fonts", "font" + i + "-" + fontFiles[i].split("/").pop(), fontFiles[i], true, true);
}
});
Module["onRuntimeInitialized"] = function() {
self.octObj = new Module.SubtitleOctopus();
self.changed = Module._malloc(4);
self.octObj.initLibrary(screen.width, screen.height);
self.octObj.createTrack("/sub.ass");
self.ass_track = self.octObj.track;
self.ass_library = self.octObj.ass_library;
self.ass_renderer = self.octObj.ass_renderer;
};
Module["print"] = function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(" ");
console.log(text);
};
Module["printErr"] = function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(" ");
console.error(text);
};
if (!hasNativeConsole) {
var console = {
log: function(x) {
if (typeof dump === "function") dump("log: " + x + "\n");
},
debug: function(x) {
if (typeof dump === "function") dump("debug: " + x + "\n");
},
info: function(x) {
if (typeof dump === "function") dump("info: " + x + "\n");
},
warn: function(x) {
if (typeof dump === "function") dump("warn: " + x + "\n");
},
error: function(x) {
if (typeof dump === "function") dump("error: " + x + "\n");
}
};
}
if ("performance" in self === false) {
self.performance = {};
}
Date.now = Date.now || function() {
return new Date().getTime();
};
if ("now" in self.performance === false) {
var nowOffset = Date.now();
if (performance.timing && performance.timing.navigationStart) {
nowOffset = performance.timing.navigationStart;
}
self.performance.now = function now() {
return Date.now() - nowOffset;
};
}
(function(f) {
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = f();
} else if (typeof define === "function" && define.amd) {
define([], f);
} else {
var g;
if (typeof window !== "undefined") {
g = window;
} else if (typeof global !== "undefined") {
g = global;
} else if (typeof self !== "undefined") {
g = self;
} else {
g = this;
}
g.unbrotli = f();
}
})(function() {
var exports;
return function() {
function r(e, n, t) {
function o(i, f) {
if (!n[i]) {
if (!e[i]) {
var c = "function" == typeof require && require;
if (!f && c) return c(i, !0);
if (u) return u(i, !0);
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}
var p = n[i] = {
exports: {}
};
e[i][0].call(p.exports, function(r) {
var n = e[i][1][r];
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
return o;
}
return r;
}()({
1: [ function(require, module, exports) {
var BROTLI_READ_SIZE = 4096;
var BROTLI_IBUF_SIZE = 2 * BROTLI_READ_SIZE + 32;
var BROTLI_IBUF_MASK = 2 * BROTLI_READ_SIZE - 1;
var kBitMask = new Uint32Array([ 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215 ]);
function BrotliBitReader(input) {
this.buf_ = new Uint8Array(BROTLI_IBUF_SIZE);
this.input_ = input;
this.reset();
}
BrotliBitReader.READ_SIZE = BROTLI_READ_SIZE;
BrotliBitReader.IBUF_MASK = BROTLI_IBUF_MASK;
BrotliBitReader.prototype.reset = function() {
this.buf_ptr_ = 0;
this.val_ = 0;
this.pos_ = 0;
this.bit_pos_ = 0;
this.bit_end_pos_ = 0;
this.eos_ = 0;
this.readMoreInput();
for (var i = 0; i < 4; i++) {
this.val_ |= this.buf_[this.pos_] << 8 * i;
++this.pos_;
}
return this.bit_end_pos_ > 0;
};
BrotliBitReader.prototype.readMoreInput = function() {
if (this.bit_end_pos_ > 256) {
return;
} else if (this.eos_) {
if (this.bit_pos_ > this.bit_end_pos_) throw new Error("Unexpected end of input " + this.bit_pos_ + " " + this.bit_end_pos_);
} else {
var dst = this.buf_ptr_;
var bytes_read = this.input_.read(this.buf_, dst, BROTLI_READ_SIZE);
if (bytes_read < 0) {
throw new Error("Unexpected end of input");
}
if (bytes_read < BROTLI_READ_SIZE) {
this.eos_ = 1;
for (var p = 0; p < 32; p++) this.buf_[dst + bytes_read + p] = 0;
}
if (dst === 0) {
for (var p = 0; p < 32; p++) this.buf_[(BROTLI_READ_SIZE << 1) + p] = this.buf_[p];
this.buf_ptr_ = BROTLI_READ_SIZE;
} else {
this.buf_ptr_ = 0;
}
this.bit_end_pos_ += bytes_read << 3;
}
};
BrotliBitReader.prototype.fillBitWindow = function() {
while (this.bit_pos_ >= 8) {
this.val_ >>>= 8;
this.val_ |= this.buf_[this.pos_ & BROTLI_IBUF_MASK] << 24;
++this.pos_;
this.bit_pos_ = this.bit_pos_ - 8 >>> 0;
this.bit_end_pos_ = this.bit_end_pos_ - 8 >>> 0;
}
};
BrotliBitReader.prototype.readBits = function(n_bits) {
if (32 - this.bit_pos_ < n_bits) {
this.fillBitWindow();
}
var val = this.val_ >>> this.bit_pos_ & kBitMask[n_bits];
this.bit_pos_ += n_bits;
return val;
};
module.exports = BrotliBitReader;
}, {} ],
2: [ function(require, module, exports) {
exports.lookup = new Uint8Array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 12, 16, 12, 12, 20, 12, 16, 24, 28, 12, 12, 32, 12, 36, 12, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 32, 32, 24, 40, 28, 12, 12, 48, 52, 52, 52, 48, 52, 52, 52, 48, 52, 52, 52, 52, 52, 48, 52, 52, 52, 52, 52, 48, 52, 52, 52, 52, 52, 24, 12, 28, 12, 12, 12, 56, 60, 60, 60, 56, 60, 60, 60, 56, 60, 60, 60, 60, 60, 56, 60, 60, 60, 60, 60, 56, 60, 60, 60, 60, 60, 24, 12, 28, 12, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 56, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35, 36, 36, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 39, 40, 40, 40, 40, 41, 41, 41, 41, 42, 42, 42, 42, 43, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 58, 58, 58, 58, 59, 59, 59, 59, 60, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]);
exports.lookupOffsets = new Uint16Array([ 1024, 1536, 1280, 1536, 0, 256, 768, 512 ]);
}, {} ],
3: [ function(require, module, exports) {
var BrotliInput = require("./streams").BrotliInput;
var BrotliOutput = require("./streams").BrotliOutput;
var BrotliBitReader = require("./bit_reader");
var BrotliDictionary = require("./dictionary");
var HuffmanCode = require("./huffman").HuffmanCode;
var BrotliBuildHuffmanTable = require("./huffman").BrotliBuildHuffmanTable;
var Context = require("./context");
var Prefix = require("./prefix");
var Transform = require("./transform");
var kDefaultCodeLength = 8;
var kCodeLengthRepeatCode = 16;
var kNumLiteralCodes = 256;
var kNumInsertAndCopyCodes = 704;
var kNumBlockLengthCodes = 26;
var kLiteralContextBits = 6;
var kDistanceContextBits = 2;
var HUFFMAN_TABLE_BITS = 8;
var HUFFMAN_TABLE_MASK = 255;
var HUFFMAN_MAX_TABLE_SIZE = 1080;
var CODE_LENGTH_CODES = 18;
var kCodeLengthCodeOrder = new Uint8Array([ 1, 2, 3, 4, 0, 5, 17, 6, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]);
var NUM_DISTANCE_SHORT_CODES = 16;
var kDistanceShortCodeIndexOffset = new Uint8Array([ 3, 2, 1, 0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 ]);
var kDistanceShortCodeValueOffset = new Int8Array([ 0, 0, 0, 0, -1, 1, -2, 2, -3, 3, -1, 1, -2, 2, -3, 3 ]);
var kMaxHuffmanTableSize = new Uint16Array([ 256, 402, 436, 468, 500, 534, 566, 598, 630, 662, 694, 726, 758, 790, 822, 854, 886, 920, 952, 984, 1016, 1048, 1080 ]);
function DecodeWindowBits(br) {
var n;
if (br.readBits(1) === 0) {
return 16;
}
n = br.readBits(3);
if (n > 0) {
return 17 + n;
}
n = br.readBits(3);
if (n > 0) {
return 8 + n;
}
return 17;
}
function DecodeVarLenUint8(br) {
if (br.readBits(1)) {
var nbits = br.readBits(3);
if (nbits === 0) {
return 1;
} else {
return br.readBits(nbits) + (1 << nbits);
}
}
return 0;
}
function MetaBlockLength() {
this.meta_block_length = 0;
this.input_end = 0;
this.is_uncompressed = 0;
this.is_metadata = false;
}
function DecodeMetaBlockLength(br) {
var out = new MetaBlockLength();
var size_nibbles;
var size_bytes;
var i;
out.input_end = br.readBits(1);
if (out.input_end && br.readBits(1)) {
return out;
}
size_nibbles = br.readBits(2) + 4;
if (size_nibbles === 7) {
out.is_metadata = true;
if (br.readBits(1) !== 0) throw new Error("Invalid reserved bit");
size_bytes = br.readBits(2);
if (size_bytes === 0) return out;
for (i = 0; i < size_bytes; i++) {
var next_byte = br.readBits(8);
if (i + 1 === size_bytes && size_bytes > 1 && next_byte === 0) throw new Error("Invalid size byte");
out.meta_block_length |= next_byte << i * 8;
}
} else {
for (i = 0; i < size_nibbles; ++i) {
var next_nibble = br.readBits(4);
if (i + 1 === size_nibbles && size_nibbles > 4 && next_nibble === 0) throw new Error("Invalid size nibble");
out.meta_block_length |= next_nibble << i * 4;
}
}
++out.meta_block_length;
if (!out.input_end && !out.is_metadata) {
out.is_uncompressed = br.readBits(1);
}
return out;
}
function ReadSymbol(table, index, br) {
var nbits;
br.fillBitWindow();
index += br.val_ >>> br.bit_pos_ & HUFFMAN_TABLE_MASK;
nbits = table[index].bits - HUFFMAN_TABLE_BITS;
if (nbits > 0) {
br.bit_pos_ += HUFFMAN_TABLE_BITS;
index += table[index].value;
index += br.val_ >>> br.bit_pos_ & (1 << nbits) - 1;
}
br.bit_pos_ += table[index].bits;
return table[index].value;
}
function ReadHuffmanCodeLengths(code_length_code_lengths, num_symbols, code_lengths, br) {
var symbol = 0;
var prev_code_len = kDefaultCodeLength;
var repeat = 0;
var repeat_code_len = 0;
var space = 32768;
var table = [];
for (var i = 0; i < 32; i++) table.push(new HuffmanCode(0, 0));
BrotliBuildHuffmanTable(table, 0, 5, code_length_code_lengths, CODE_LENGTH_CODES);
while (symbol < num_symbols && space > 0) {
var p = 0;
var code_len;
br.readMoreInput();
br.fillBitWindow();
p += br.val_ >>> br.bit_pos_ & 31;
br.bit_pos_ += table[p].bits;
code_len = table[p].value & 255;
if (code_len < kCodeLengthRepeatCode) {
repeat = 0;
code_lengths[symbol++] = code_len;
if (code_len !== 0) {
prev_code_len = code_len;
space -= 32768 >> code_len;
}
} else {
var extra_bits = code_len - 14;
var old_repeat;
var repeat_delta;
var new_len = 0;
if (code_len === kCodeLengthRepeatCode) {
new_len = prev_code_len;
}
if (repeat_code_len !== new_len) {
repeat = 0;
repeat_code_len = new_len;
}
old_repeat = repeat;
if (repeat > 0) {
repeat -= 2;
repeat <<= extra_bits;
}
repeat += br.readBits(extra_bits) + 3;
repeat_delta = repeat - old_repeat;
if (symbol + repeat_delta > num_symbols) {
throw new Error("[ReadHuffmanCodeLengths] symbol + repeat_delta > num_symbols");
}
for (var x = 0; x < repeat_delta; x++) code_lengths[symbol + x] = repeat_code_len;
symbol += repeat_delta;
if (repeat_code_len !== 0) {
space -= repeat_delta << 15 - repeat_code_len;
}
}
}
if (space !== 0) {
throw new Error("[ReadHuffmanCodeLengths] space = " + space);
}
for (;symbol < num_symbols; symbol++) code_lengths[symbol] = 0;
}
function ReadHuffmanCode(alphabet_size, tables, table, br) {
var table_size = 0;
var simple_code_or_skip;
var code_lengths = new Uint8Array(alphabet_size);
br.readMoreInput();
simple_code_or_skip = br.readBits(2);
if (simple_code_or_skip === 1) {
var i;
var max_bits_counter = alphabet_size - 1;
var max_bits = 0;
var symbols = new Int32Array(4);
var num_symbols = br.readBits(2) + 1;
while (max_bits_counter) {
max_bits_counter >>= 1;
++max_bits;
}
for (i = 0; i < num_symbols; ++i) {
symbols[i] = br.readBits(max_bits) % alphabet_size;
code_lengths[symbols[i]] = 2;
}
code_lengths[symbols[0]] = 1;
switch (num_symbols) {
case 1:
break;
case 3:
if (symbols[0] === symbols[1] || symbols[0] === symbols[2] || symbols[1] === symbols[2]) {
throw new Error("[ReadHuffmanCode] invalid symbols");
}
break;
case 2:
if (symbols[0] === symbols[1]) {
throw new Error("[ReadHuffmanCode] invalid symbols");
}
code_lengths[symbols[1]] = 1;
break;
case 4:
if (symbols[0] === symbols[1] || symbols[0] === symbols[2] || symbols[0] === symbols[3] || symbols[1] === symbols[2] || symbols[1] === symbols[3] || symbols[2] === symbols[3]) {
throw new Error("[ReadHuffmanCode] invalid symbols");
}
if (br.readBits(1)) {
code_lengths[symbols[2]] = 3;
code_lengths[symbols[3]] = 3;
} else {
code_lengths[symbols[0]] = 2;
}
break;
}
} else {
var i;
var code_length_code_lengths = new Uint8Array(CODE_LENGTH_CODES);
var space = 32;
var num_codes = 0;
var huff = [ new HuffmanCode(2, 0), new HuffmanCode(2, 4), new HuffmanCode(2, 3), new HuffmanCode(3, 2), new HuffmanCode(2, 0), new HuffmanCode(2, 4), new HuffmanCode(2, 3), new HuffmanCode(4, 1), new HuffmanCode(2, 0), new HuffmanCode(2, 4), new HuffmanCode(2, 3), new HuffmanCode(3, 2), new HuffmanCode(2, 0), new HuffmanCode(2, 4), new HuffmanCode(2, 3), new HuffmanCode(4, 5) ];
for (i = simple_code_or_skip; i < CODE_LENGTH_CODES && space > 0; ++i) {
var code_len_idx = kCodeLengthCodeOrder[i];
var p = 0;
var v;
br.fillBitWindow();
p += br.val_ >>> br.bit_pos_ & 15;
br.bit_pos_ += huff[p].bits;
v = huff[p].value;
code_length_code_lengths[code_len_idx] = v;
if (v !== 0) {
space -= 32 >> v;
++num_codes;
}
}
if (!(num_codes === 1 || space === 0)) throw new Error("[ReadHuffmanCode] invalid num_codes or space");
ReadHuffmanCodeLengths(code_length_code_lengths, alphabet_size, code_lengths, br);
}
table_size = BrotliBuildHuffmanTable(tables, table, HUFFMAN_TABLE_BITS, code_lengths, alphabet_size);
if (table_size === 0) {
throw new Error("[ReadHuffmanCode] BuildHuffmanTable failed: ");
}
return table_size;
}
function ReadBlockLength(table, index, br) {
var code;
var nbits;
code = ReadSymbol(table, index, br);
nbits = Prefix.kBlockLengthPrefixCode[code].nbits;
return Prefix.kBlockLengthPrefixCode[code].offset + br.readBits(nbits);
}
function TranslateShortCodes(code, ringbuffer, index) {
var val;
if (code < NUM_DISTANCE_SHORT_CODES) {
index += kDistanceShortCodeIndexOffset[code];
index &= 3;
val = ringbuffer[index] + kDistanceShortCodeValueOffset[code];
} else {
val = code - NUM_DISTANCE_SHORT_CODES + 1;
}
return val;
}
function MoveToFront(v, index) {
var value = v[index];
var i = index;
for (;i; --i) v[i] = v[i - 1];
v[0] = value;
}
function InverseMoveToFrontTransform(v, v_len) {
var mtf = new Uint8Array(256);
var i;
for (i = 0; i < 256; ++i) {
mtf[i] = i;
}
for (i = 0; i < v_len; ++i) {
var index = v[i];
v[i] = mtf[index];
if (index) MoveToFront(mtf, index);
}
}
function HuffmanTreeGroup(alphabet_size, num_htrees) {
this.alphabet_size = alphabet_size;
this.num_htrees = num_htrees;
this.codes = new Array(num_htrees + num_htrees * kMaxHuffmanTableSize[alphabet_size + 31 >>> 5]);
this.htrees = new Uint32Array(num_htrees);
}
HuffmanTreeGroup.prototype.decode = function(br) {
var i;
var table_size;
var next = 0;
for (i = 0; i < this.num_htrees; ++i) {
this.htrees[i] = next;
table_size = ReadHuffmanCode(this.alphabet_size, this.codes, next, br);
next += table_size;
}
};
function DecodeContextMap(context_map_size, br) {
var out = {
num_htrees: null,
context_map: null
};
var use_rle_for_zeros;
var max_run_length_prefix = 0;
var table;
var i;
br.readMoreInput();
var num_htrees = out.num_htrees = DecodeVarLenUint8(br) + 1;
var context_map = out.context_map = new Uint8Array(context_map_size);
if (num_htrees <= 1) {
return out;
}
use_rle_for_zeros = br.readBits(1);
if (use_rle_for_zeros) {
max_run_length_prefix = br.readBits(4) + 1;
}
table = [];
for (i = 0; i < HUFFMAN_MAX_TABLE_SIZE; i++) {
table[i] = new HuffmanCode(0, 0);
}
ReadHuffmanCode(num_htrees + max_run_length_prefix, table, 0, br);
for (i = 0; i < context_map_size; ) {
var code;
br.readMoreInput();
code = ReadSymbol(table, 0, br);
if (code === 0) {
context_map[i] = 0;
++i;
} else if (code <= max_run_length_prefix) {
var reps = 1 + (1 << code) + br.readBits(code);
while (--reps) {
if (i >= context_map_size) {
throw new Error("[DecodeContextMap] i >= context_map_size");
}
context_map[i] = 0;
++i;
}
} else {
context_map[i] = code - max_run_length_prefix;
++i;
}
}
if (br.readBits(1)) {
InverseMoveToFrontTransform(context_map, context_map_size);
}
return out;
}
function DecodeBlockType(max_block_type, trees, tree_type, block_types, ringbuffers, indexes, br) {
var ringbuffer = tree_type * 2;
var index = tree_type;
var type_code = ReadSymbol(trees, tree_type * HUFFMAN_MAX_TABLE_SIZE, br);
var block_type;
if (type_code === 0) {
block_type = ringbuffers[ringbuffer + (indexes[index] & 1)];
} else if (type_code === 1) {
block_type = ringbuffers[ringbuffer + (indexes[index] - 1 & 1)] + 1;
} else {
block_type = type_code - 2;
}
if (block_type >= max_block_type) {
block_type -= max_block_type;
}
block_types[tree_type] = block_type;
ringbuffers[ringbuffer + (indexes[index] & 1)] = block_type;
++indexes[index];
}
function CopyUncompressedBlockToOutput(output, len, pos, ringbuffer, ringbuffer_mask, br) {
var rb_size = ringbuffer_mask + 1;
var rb_pos = pos & ringbuffer_mask;
var br_pos = br.pos_ & BrotliBitReader.IBUF_MASK;
var nbytes;
if (len < 8 || br.bit_pos_ + (len << 3) < br.bit_end_pos_) {
while (len-- > 0) {
br.readMoreInput();
ringbuffer[rb_pos++] = br.readBits(8);
if (rb_pos === rb_size) {
output.write(ringbuffer, rb_size);
rb_pos = 0;
}
}
return;
}
if (br.bit_end_pos_ < 32) {
throw new Error("[CopyUncompressedBlockToOutput] br.bit_end_pos_ < 32");
}
while (br.bit_pos_ < 32) {
ringbuffer[rb_pos] = br.val_ >>> br.bit_pos_;
br.bit_pos_ += 8;
++rb_pos;
--len;
}
nbytes = br.bit_end_pos_ - br.bit_pos_ >> 3;
if (br_pos + nbytes > BrotliBitReader.IBUF_MASK) {
var tail = BrotliBitReader.IBUF_MASK + 1 - br_pos;
for (var x = 0; x < tail; x++) ringbuffer[rb_pos + x] = br.buf_[br_pos + x];
nbytes -= tail;
rb_pos += tail;
len -= tail;
br_pos = 0;
}
for (var x = 0; x < nbytes; x++) ringbuffer[rb_pos + x] = br.buf_[br_pos + x];
rb_pos += nbytes;
len -= nbytes;
if (rb_pos >= rb_size) {
output.write(ringbuffer, rb_size);
rb_pos -= rb_size;
for (var x = 0; x < rb_pos; x++) ringbuffer[x] = ringbuffer[rb_size + x];
}
while (rb_pos + len >= rb_size) {
nbytes = rb_size - rb_pos;
if (br.input_.read(ringbuffer, rb_pos, nbytes) < nbytes) {
throw new Error("[CopyUncompressedBlockToOutput] not enough bytes");
}
output.write(ringbuffer, rb_size);
len -= nbytes;
rb_pos = 0;
}
if (br.input_.read(ringbuffer, rb_pos, len) < len) {
throw new Error("[CopyUncompressedBlockToOutput] not enough bytes");
}
br.reset();
}
function JumpToByteBoundary(br) {
var new_bit_pos = br.bit_pos_ + 7 & ~7;
var pad_bits = br.readBits(new_bit_pos - br.bit_pos_);
return pad_bits == 0;
}
function BrotliDecompressedSize(buffer) {
var input = new BrotliInput(buffer);
var br = new BrotliBitReader(input);
DecodeWindowBits(br);
var out = DecodeMetaBlockLength(br);
return out.meta_block_length;
}
exports.BrotliDecompressedSize = BrotliDecompressedSize;
function BrotliDecompressBuffer(buffer, output_size) {
var input = new BrotliInput(buffer);
if (output_size == null) {
output_size = BrotliDecompressedSize(buffer);
}
var output_buffer = new Uint8Array(output_size);
var output = new BrotliOutput(output_buffer);
BrotliDecompress(input, output);
if (output.pos < output.buffer.length) {
output.buffer = output.buffer.subarray(0, output.pos);
}
return output.buffer;
}
exports.BrotliDecompressBuffer = BrotliDecompressBuffer;
function BrotliDecompress(input, output) {
var i;
var pos = 0;
var input_end = 0;
var window_bits = 0;
var max_backward_distance;
var max_distance = 0;
var ringbuffer_size;
var ringbuffer_mask;
var ringbuffer;
var ringbuffer_end;
var dist_rb = [ 16, 15, 11, 4 ];
var dist_rb_idx = 0;
var prev_byte1 = 0;
var prev_byte2 = 0;
var hgroup = [ new HuffmanTreeGroup(0, 0), new HuffmanTreeGroup(0, 0), new HuffmanTreeGroup(0, 0) ];
var block_type_trees;
var block_len_trees;
var br;
var kRingBufferWriteAheadSlack = 128 + BrotliBitReader.READ_SIZE;
br = new BrotliBitReader(input);
window_bits = DecodeWindowBits(br);
max_backward_distance = (1 << window_bits) - 16;
ringbuffer_size = 1 << window_bits;
ringbuffer_mask = ringbuffer_size - 1;
ringbuffer = new Uint8Array(ringbuffer_size + kRingBufferWriteAheadSlack + BrotliDictionary.maxDictionaryWordLength);
ringbuffer_end = ringbuffer_size;
block_type_trees = [];
block_len_trees = [];
for (var x = 0; x < 3 * HUFFMAN_MAX_TABLE_SIZE; x++) {
block_type_trees[x] = new HuffmanCode(0, 0);
block_len_trees[x] = new HuffmanCode(0, 0);
}
while (!input_end) {
var meta_block_remaining_len = 0;
var is_uncompressed;
var block_length = [ 1 << 28, 1 << 28, 1 << 28 ];
var block_type = [ 0 ];
var num_block_types = [ 1, 1, 1 ];
var block_type_rb = [ 0, 1, 0, 1, 0, 1 ];
var block_type_rb_index = [ 0 ];
var distance_postfix_bits;
var num_direct_distance_codes;
var distance_postfix_mask;
var num_distance_codes;
var context_map = null;
var context_modes = null;
var num_literal_htrees;
var dist_context_map = null;
var num_dist_htrees;
var context_offset = 0;
var context_map_slice = null;
var literal_htree_index = 0;
var dist_context_offset = 0;
var dist_context_map_slice = null;
var dist_htree_index = 0;
var context_lookup_offset1 = 0;
var context_lookup_offset2 = 0;
var context_mode;
var htree_command;
for (i = 0; i < 3; ++i) {
hgroup[i].codes = null;
hgroup[i].htrees = null;
}
br.readMoreInput();
var _out = DecodeMetaBlockLength(br);
meta_block_remaining_len = _out.meta_block_length;
if (pos + meta_block_remaining_len > output.buffer.length) {
var tmp = new Uint8Array(pos + meta_block_remaining_len);
tmp.set(output.buffer);
output.buffer = tmp;
}
input_end = _out.input_end;
is_uncompressed = _out.is_uncompressed;
if (_out.is_metadata) {
JumpToByteBoundary(br);
for (;meta_block_remaining_len > 0; --meta_block_remaining_len) {
br.readMoreInput();
br.readBits(8);
}
continue;
}
if (meta_block_remaining_len === 0) {
continue;
}
if (is_uncompressed) {
br.bit_pos_ = br.bit_pos_ + 7 & ~7;
CopyUncompressedBlockToOutput(output, meta_block_remaining_len, pos, ringbuffer, ringbuffer_mask, br);
pos += meta_block_remaining_len;
continue;
}
for (i = 0; i < 3; ++i) {
num_block_types[i] = DecodeVarLenUint8(br) + 1;
if (num_block_types[i] >= 2) {
ReadHuffmanCode(num_block_types[i] + 2, block_type_trees, i * HUFFMAN_MAX_TABLE_SIZE, br);
ReadHuffmanCode(kNumBlockLengthCodes, block_len_trees, i * HUFFMAN_MAX_TABLE_SIZE, br);
block_length[i] = ReadBlockLength(block_len_trees, i * HUFFMAN_MAX_TABLE_SIZE, br);
block_type_rb_index[i] = 1;
}
}
br.readMoreInput();
distance_postfix_bits = br.readBits(2);
num_direct_distance_codes = NUM_DISTANCE_SHORT_CODES + (br.readBits(4) << distance_postfix_bits);
distance_postfix_mask = (1 << distance_postfix_bits) - 1;
num_distance_codes = num_direct_distance_codes + (48 << distance_postfix_bits);
context_modes = new Uint8Array(num_block_types[0]);
for (i = 0; i < num_block_types[0]; ++i) {
br.readMoreInput();
context_modes[i] = br.readBits(2) << 1;
}
var _o1 = DecodeContextMap(num_block_types[0] << kLiteralContextBits, br);
num_literal_htrees = _o1.num_htrees;
context_map = _o1.context_map;
var _o2 = DecodeContextMap(num_block_types[2] << kDistanceContextBits, br);
num_dist_htrees = _o2.num_htrees;
dist_context_map = _o2.context_map;
hgroup[0] = new HuffmanTreeGroup(kNumLiteralCodes, num_literal_htrees);
hgroup[1] = new HuffmanTreeGroup(kNumInsertAndCopyCodes, num_block_types[1]);
hgroup[2] = new HuffmanTreeGroup(num_distance_codes, num_dist_htrees);
for (i = 0; i < 3; ++i) {
hgroup[i].decode(br);
}
context_map_slice = 0;