stream.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.LZWStream = exports.StringStream = exports.StreamsSequenceStream = exports.Stream = exports.RunLengthStream = exports.PredictorStream = exports.NullStream = exports.FlateStream = exports.DecodeStream = exports.DecryptStream = exports.AsciiHexStream = exports.Ascii85Stream = undefined;
  27. var _util = require('../shared/util');
  28. var _primitives = require('./primitives');
  29. var Stream = function StreamClosure() {
  30. function Stream(arrayBuffer, start, length, dict) {
  31. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  32. this.start = start || 0;
  33. this.pos = this.start;
  34. this.end = start + length || this.bytes.length;
  35. this.dict = dict;
  36. }
  37. Stream.prototype = {
  38. get length() {
  39. return this.end - this.start;
  40. },
  41. get isEmpty() {
  42. return this.length === 0;
  43. },
  44. getByte: function Stream_getByte() {
  45. if (this.pos >= this.end) {
  46. return -1;
  47. }
  48. return this.bytes[this.pos++];
  49. },
  50. getUint16: function Stream_getUint16() {
  51. var b0 = this.getByte();
  52. var b1 = this.getByte();
  53. if (b0 === -1 || b1 === -1) {
  54. return -1;
  55. }
  56. return (b0 << 8) + b1;
  57. },
  58. getInt32: function Stream_getInt32() {
  59. var b0 = this.getByte();
  60. var b1 = this.getByte();
  61. var b2 = this.getByte();
  62. var b3 = this.getByte();
  63. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  64. },
  65. getBytes: function Stream_getBytes(length) {
  66. var bytes = this.bytes;
  67. var pos = this.pos;
  68. var strEnd = this.end;
  69. if (!length) {
  70. return bytes.subarray(pos, strEnd);
  71. }
  72. var end = pos + length;
  73. if (end > strEnd) {
  74. end = strEnd;
  75. }
  76. this.pos = end;
  77. return bytes.subarray(pos, end);
  78. },
  79. peekByte: function Stream_peekByte() {
  80. var peekedByte = this.getByte();
  81. this.pos--;
  82. return peekedByte;
  83. },
  84. peekBytes: function Stream_peekBytes(length) {
  85. var bytes = this.getBytes(length);
  86. this.pos -= bytes.length;
  87. return bytes;
  88. },
  89. skip: function Stream_skip(n) {
  90. if (!n) {
  91. n = 1;
  92. }
  93. this.pos += n;
  94. },
  95. reset: function Stream_reset() {
  96. this.pos = this.start;
  97. },
  98. moveStart: function Stream_moveStart() {
  99. this.start = this.pos;
  100. },
  101. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  102. return new Stream(this.bytes.buffer, start, length, dict);
  103. }
  104. };
  105. return Stream;
  106. }();
  107. var StringStream = function StringStreamClosure() {
  108. function StringStream(str) {
  109. var bytes = (0, _util.stringToBytes)(str);
  110. Stream.call(this, bytes);
  111. }
  112. StringStream.prototype = Stream.prototype;
  113. return StringStream;
  114. }();
  115. var DecodeStream = function DecodeStreamClosure() {
  116. var emptyBuffer = new Uint8Array(0);
  117. function DecodeStream(maybeMinBufferLength) {
  118. this.pos = 0;
  119. this.bufferLength = 0;
  120. this.eof = false;
  121. this.buffer = emptyBuffer;
  122. this.minBufferLength = 512;
  123. if (maybeMinBufferLength) {
  124. while (this.minBufferLength < maybeMinBufferLength) {
  125. this.minBufferLength *= 2;
  126. }
  127. }
  128. }
  129. DecodeStream.prototype = {
  130. get isEmpty() {
  131. while (!this.eof && this.bufferLength === 0) {
  132. this.readBlock();
  133. }
  134. return this.bufferLength === 0;
  135. },
  136. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  137. var buffer = this.buffer;
  138. if (requested <= buffer.byteLength) {
  139. return buffer;
  140. }
  141. var size = this.minBufferLength;
  142. while (size < requested) {
  143. size *= 2;
  144. }
  145. var buffer2 = new Uint8Array(size);
  146. buffer2.set(buffer);
  147. return this.buffer = buffer2;
  148. },
  149. getByte: function DecodeStream_getByte() {
  150. var pos = this.pos;
  151. while (this.bufferLength <= pos) {
  152. if (this.eof) {
  153. return -1;
  154. }
  155. this.readBlock();
  156. }
  157. return this.buffer[this.pos++];
  158. },
  159. getUint16: function DecodeStream_getUint16() {
  160. var b0 = this.getByte();
  161. var b1 = this.getByte();
  162. if (b0 === -1 || b1 === -1) {
  163. return -1;
  164. }
  165. return (b0 << 8) + b1;
  166. },
  167. getInt32: function DecodeStream_getInt32() {
  168. var b0 = this.getByte();
  169. var b1 = this.getByte();
  170. var b2 = this.getByte();
  171. var b3 = this.getByte();
  172. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  173. },
  174. getBytes: function DecodeStream_getBytes(length) {
  175. var end,
  176. pos = this.pos;
  177. if (length) {
  178. this.ensureBuffer(pos + length);
  179. end = pos + length;
  180. while (!this.eof && this.bufferLength < end) {
  181. this.readBlock();
  182. }
  183. var bufEnd = this.bufferLength;
  184. if (end > bufEnd) {
  185. end = bufEnd;
  186. }
  187. } else {
  188. while (!this.eof) {
  189. this.readBlock();
  190. }
  191. end = this.bufferLength;
  192. }
  193. this.pos = end;
  194. return this.buffer.subarray(pos, end);
  195. },
  196. peekByte: function DecodeStream_peekByte() {
  197. var peekedByte = this.getByte();
  198. this.pos--;
  199. return peekedByte;
  200. },
  201. peekBytes: function DecodeStream_peekBytes(length) {
  202. var bytes = this.getBytes(length);
  203. this.pos -= bytes.length;
  204. return bytes;
  205. },
  206. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  207. var end = start + length;
  208. while (this.bufferLength <= end && !this.eof) {
  209. this.readBlock();
  210. }
  211. return new Stream(this.buffer, start, length, dict);
  212. },
  213. skip: function DecodeStream_skip(n) {
  214. if (!n) {
  215. n = 1;
  216. }
  217. this.pos += n;
  218. },
  219. reset: function DecodeStream_reset() {
  220. this.pos = 0;
  221. },
  222. getBaseStreams: function DecodeStream_getBaseStreams() {
  223. if (this.str && this.str.getBaseStreams) {
  224. return this.str.getBaseStreams();
  225. }
  226. return [];
  227. }
  228. };
  229. return DecodeStream;
  230. }();
  231. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  232. function StreamsSequenceStream(streams) {
  233. this.streams = streams;
  234. DecodeStream.call(this, null);
  235. }
  236. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  237. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  238. var streams = this.streams;
  239. if (streams.length === 0) {
  240. this.eof = true;
  241. return;
  242. }
  243. var stream = streams.shift();
  244. var chunk = stream.getBytes();
  245. var bufferLength = this.bufferLength;
  246. var newLength = bufferLength + chunk.length;
  247. var buffer = this.ensureBuffer(newLength);
  248. buffer.set(chunk, bufferLength);
  249. this.bufferLength = newLength;
  250. };
  251. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  252. var baseStreams = [];
  253. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  254. var stream = this.streams[i];
  255. if (stream.getBaseStreams) {
  256. _util.Util.appendToArray(baseStreams, stream.getBaseStreams());
  257. }
  258. }
  259. return baseStreams;
  260. };
  261. return StreamsSequenceStream;
  262. }();
  263. var FlateStream = function FlateStreamClosure() {
  264. var codeLenCodeMap = new Int32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
  265. var lengthDecode = new Int32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]);
  266. var distDecode = new Int32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]);
  267. var fixedLitCodeTab = [new Int32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9];
  268. var fixedDistCodeTab = [new Int32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5];
  269. function FlateStream(str, maybeLength) {
  270. this.str = str;
  271. this.dict = str.dict;
  272. var cmf = str.getByte();
  273. var flg = str.getByte();
  274. if (cmf === -1 || flg === -1) {
  275. throw new _util.FormatError('Invalid header in flate stream: ' + cmf + ', ' + flg);
  276. }
  277. if ((cmf & 0x0f) !== 0x08) {
  278. throw new _util.FormatError('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  279. }
  280. if (((cmf << 8) + flg) % 31 !== 0) {
  281. throw new _util.FormatError('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  282. }
  283. if (flg & 0x20) {
  284. throw new _util.FormatError('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  285. }
  286. this.codeSize = 0;
  287. this.codeBuf = 0;
  288. DecodeStream.call(this, maybeLength);
  289. }
  290. FlateStream.prototype = Object.create(DecodeStream.prototype);
  291. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  292. var str = this.str;
  293. var codeSize = this.codeSize;
  294. var codeBuf = this.codeBuf;
  295. var b;
  296. while (codeSize < bits) {
  297. if ((b = str.getByte()) === -1) {
  298. throw new _util.FormatError('Bad encoding in flate stream');
  299. }
  300. codeBuf |= b << codeSize;
  301. codeSize += 8;
  302. }
  303. b = codeBuf & (1 << bits) - 1;
  304. this.codeBuf = codeBuf >> bits;
  305. this.codeSize = codeSize -= bits;
  306. return b;
  307. };
  308. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  309. var str = this.str;
  310. var codes = table[0];
  311. var maxLen = table[1];
  312. var codeSize = this.codeSize;
  313. var codeBuf = this.codeBuf;
  314. var b;
  315. while (codeSize < maxLen) {
  316. if ((b = str.getByte()) === -1) {
  317. break;
  318. }
  319. codeBuf |= b << codeSize;
  320. codeSize += 8;
  321. }
  322. var code = codes[codeBuf & (1 << maxLen) - 1];
  323. var codeLen = code >> 16;
  324. var codeVal = code & 0xffff;
  325. if (codeLen < 1 || codeSize < codeLen) {
  326. throw new _util.FormatError('Bad encoding in flate stream');
  327. }
  328. this.codeBuf = codeBuf >> codeLen;
  329. this.codeSize = codeSize - codeLen;
  330. return codeVal;
  331. };
  332. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  333. var n = lengths.length;
  334. var maxLen = 0;
  335. var i;
  336. for (i = 0; i < n; ++i) {
  337. if (lengths[i] > maxLen) {
  338. maxLen = lengths[i];
  339. }
  340. }
  341. var size = 1 << maxLen;
  342. var codes = new Int32Array(size);
  343. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  344. for (var val = 0; val < n; ++val) {
  345. if (lengths[val] === len) {
  346. var code2 = 0;
  347. var t = code;
  348. for (i = 0; i < len; ++i) {
  349. code2 = code2 << 1 | t & 1;
  350. t >>= 1;
  351. }
  352. for (i = code2; i < size; i += skip) {
  353. codes[i] = len << 16 | val;
  354. }
  355. ++code;
  356. }
  357. }
  358. }
  359. return [codes, maxLen];
  360. };
  361. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  362. var buffer, len;
  363. var str = this.str;
  364. var hdr = this.getBits(3);
  365. if (hdr & 1) {
  366. this.eof = true;
  367. }
  368. hdr >>= 1;
  369. if (hdr === 0) {
  370. var b;
  371. if ((b = str.getByte()) === -1) {
  372. throw new _util.FormatError('Bad block header in flate stream');
  373. }
  374. var blockLen = b;
  375. if ((b = str.getByte()) === -1) {
  376. throw new _util.FormatError('Bad block header in flate stream');
  377. }
  378. blockLen |= b << 8;
  379. if ((b = str.getByte()) === -1) {
  380. throw new _util.FormatError('Bad block header in flate stream');
  381. }
  382. var check = b;
  383. if ((b = str.getByte()) === -1) {
  384. throw new _util.FormatError('Bad block header in flate stream');
  385. }
  386. check |= b << 8;
  387. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  388. throw new _util.FormatError('Bad uncompressed block length in flate stream');
  389. }
  390. this.codeBuf = 0;
  391. this.codeSize = 0;
  392. var bufferLength = this.bufferLength;
  393. buffer = this.ensureBuffer(bufferLength + blockLen);
  394. var end = bufferLength + blockLen;
  395. this.bufferLength = end;
  396. if (blockLen === 0) {
  397. if (str.peekByte() === -1) {
  398. this.eof = true;
  399. }
  400. } else {
  401. for (var n = bufferLength; n < end; ++n) {
  402. if ((b = str.getByte()) === -1) {
  403. this.eof = true;
  404. break;
  405. }
  406. buffer[n] = b;
  407. }
  408. }
  409. return;
  410. }
  411. var litCodeTable;
  412. var distCodeTable;
  413. if (hdr === 1) {
  414. litCodeTable = fixedLitCodeTab;
  415. distCodeTable = fixedDistCodeTab;
  416. } else if (hdr === 2) {
  417. var numLitCodes = this.getBits(5) + 257;
  418. var numDistCodes = this.getBits(5) + 1;
  419. var numCodeLenCodes = this.getBits(4) + 4;
  420. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  421. var i;
  422. for (i = 0; i < numCodeLenCodes; ++i) {
  423. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  424. }
  425. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  426. len = 0;
  427. i = 0;
  428. var codes = numLitCodes + numDistCodes;
  429. var codeLengths = new Uint8Array(codes);
  430. var bitsLength, bitsOffset, what;
  431. while (i < codes) {
  432. var code = this.getCode(codeLenCodeTab);
  433. if (code === 16) {
  434. bitsLength = 2;
  435. bitsOffset = 3;
  436. what = len;
  437. } else if (code === 17) {
  438. bitsLength = 3;
  439. bitsOffset = 3;
  440. what = len = 0;
  441. } else if (code === 18) {
  442. bitsLength = 7;
  443. bitsOffset = 11;
  444. what = len = 0;
  445. } else {
  446. codeLengths[i++] = len = code;
  447. continue;
  448. }
  449. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  450. while (repeatLength-- > 0) {
  451. codeLengths[i++] = what;
  452. }
  453. }
  454. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  455. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  456. } else {
  457. throw new _util.FormatError('Unknown block type in flate stream');
  458. }
  459. buffer = this.buffer;
  460. var limit = buffer ? buffer.length : 0;
  461. var pos = this.bufferLength;
  462. while (true) {
  463. var code1 = this.getCode(litCodeTable);
  464. if (code1 < 256) {
  465. if (pos + 1 >= limit) {
  466. buffer = this.ensureBuffer(pos + 1);
  467. limit = buffer.length;
  468. }
  469. buffer[pos++] = code1;
  470. continue;
  471. }
  472. if (code1 === 256) {
  473. this.bufferLength = pos;
  474. return;
  475. }
  476. code1 -= 257;
  477. code1 = lengthDecode[code1];
  478. var code2 = code1 >> 16;
  479. if (code2 > 0) {
  480. code2 = this.getBits(code2);
  481. }
  482. len = (code1 & 0xffff) + code2;
  483. code1 = this.getCode(distCodeTable);
  484. code1 = distDecode[code1];
  485. code2 = code1 >> 16;
  486. if (code2 > 0) {
  487. code2 = this.getBits(code2);
  488. }
  489. var dist = (code1 & 0xffff) + code2;
  490. if (pos + len >= limit) {
  491. buffer = this.ensureBuffer(pos + len);
  492. limit = buffer.length;
  493. }
  494. for (var k = 0; k < len; ++k, ++pos) {
  495. buffer[pos] = buffer[pos - dist];
  496. }
  497. }
  498. };
  499. return FlateStream;
  500. }();
  501. var PredictorStream = function PredictorStreamClosure() {
  502. function PredictorStream(str, maybeLength, params) {
  503. if (!(0, _primitives.isDict)(params)) {
  504. return str;
  505. }
  506. var predictor = this.predictor = params.get('Predictor') || 1;
  507. if (predictor <= 1) {
  508. return str;
  509. }
  510. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  511. throw new _util.FormatError('Unsupported predictor: ' + predictor);
  512. }
  513. if (predictor === 2) {
  514. this.readBlock = this.readBlockTiff;
  515. } else {
  516. this.readBlock = this.readBlockPng;
  517. }
  518. this.str = str;
  519. this.dict = str.dict;
  520. var colors = this.colors = params.get('Colors') || 1;
  521. var bits = this.bits = params.get('BitsPerComponent') || 8;
  522. var columns = this.columns = params.get('Columns') || 1;
  523. this.pixBytes = colors * bits + 7 >> 3;
  524. this.rowBytes = columns * colors * bits + 7 >> 3;
  525. DecodeStream.call(this, maybeLength);
  526. return this;
  527. }
  528. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  529. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  530. var rowBytes = this.rowBytes;
  531. var bufferLength = this.bufferLength;
  532. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  533. var bits = this.bits;
  534. var colors = this.colors;
  535. var rawBytes = this.str.getBytes(rowBytes);
  536. this.eof = !rawBytes.length;
  537. if (this.eof) {
  538. return;
  539. }
  540. var inbuf = 0,
  541. outbuf = 0;
  542. var inbits = 0,
  543. outbits = 0;
  544. var pos = bufferLength;
  545. var i;
  546. if (bits === 1 && colors === 1) {
  547. for (i = 0; i < rowBytes; ++i) {
  548. var c = rawBytes[i] ^ inbuf;
  549. c ^= c >> 1;
  550. c ^= c >> 2;
  551. c ^= c >> 4;
  552. inbuf = (c & 1) << 7;
  553. buffer[pos++] = c;
  554. }
  555. } else if (bits === 8) {
  556. for (i = 0; i < colors; ++i) {
  557. buffer[pos++] = rawBytes[i];
  558. }
  559. for (; i < rowBytes; ++i) {
  560. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  561. pos++;
  562. }
  563. } else if (bits === 16) {
  564. var bytesPerPixel = colors * 2;
  565. for (i = 0; i < bytesPerPixel; ++i) {
  566. buffer[pos++] = rawBytes[i];
  567. }
  568. for (; i < rowBytes; i += 2) {
  569. var sum = ((rawBytes[i] & 0xFF) << 8) + (rawBytes[i + 1] & 0xFF) + ((buffer[pos - bytesPerPixel] & 0xFF) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xFF);
  570. buffer[pos++] = sum >> 8 & 0xFF;
  571. buffer[pos++] = sum & 0xFF;
  572. }
  573. } else {
  574. var compArray = new Uint8Array(colors + 1);
  575. var bitMask = (1 << bits) - 1;
  576. var j = 0,
  577. k = bufferLength;
  578. var columns = this.columns;
  579. for (i = 0; i < columns; ++i) {
  580. for (var kk = 0; kk < colors; ++kk) {
  581. if (inbits < bits) {
  582. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  583. inbits += 8;
  584. }
  585. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  586. inbits -= bits;
  587. outbuf = outbuf << bits | compArray[kk];
  588. outbits += bits;
  589. if (outbits >= 8) {
  590. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  591. outbits -= 8;
  592. }
  593. }
  594. }
  595. if (outbits > 0) {
  596. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  597. }
  598. }
  599. this.bufferLength += rowBytes;
  600. };
  601. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  602. var rowBytes = this.rowBytes;
  603. var pixBytes = this.pixBytes;
  604. var predictor = this.str.getByte();
  605. var rawBytes = this.str.getBytes(rowBytes);
  606. this.eof = !rawBytes.length;
  607. if (this.eof) {
  608. return;
  609. }
  610. var bufferLength = this.bufferLength;
  611. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  612. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  613. if (prevRow.length === 0) {
  614. prevRow = new Uint8Array(rowBytes);
  615. }
  616. var i,
  617. j = bufferLength,
  618. up,
  619. c;
  620. switch (predictor) {
  621. case 0:
  622. for (i = 0; i < rowBytes; ++i) {
  623. buffer[j++] = rawBytes[i];
  624. }
  625. break;
  626. case 1:
  627. for (i = 0; i < pixBytes; ++i) {
  628. buffer[j++] = rawBytes[i];
  629. }
  630. for (; i < rowBytes; ++i) {
  631. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  632. j++;
  633. }
  634. break;
  635. case 2:
  636. for (i = 0; i < rowBytes; ++i) {
  637. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  638. }
  639. break;
  640. case 3:
  641. for (i = 0; i < pixBytes; ++i) {
  642. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  643. }
  644. for (; i < rowBytes; ++i) {
  645. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  646. j++;
  647. }
  648. break;
  649. case 4:
  650. for (i = 0; i < pixBytes; ++i) {
  651. up = prevRow[i];
  652. c = rawBytes[i];
  653. buffer[j++] = up + c;
  654. }
  655. for (; i < rowBytes; ++i) {
  656. up = prevRow[i];
  657. var upLeft = prevRow[i - pixBytes];
  658. var left = buffer[j - pixBytes];
  659. var p = left + up - upLeft;
  660. var pa = p - left;
  661. if (pa < 0) {
  662. pa = -pa;
  663. }
  664. var pb = p - up;
  665. if (pb < 0) {
  666. pb = -pb;
  667. }
  668. var pc = p - upLeft;
  669. if (pc < 0) {
  670. pc = -pc;
  671. }
  672. c = rawBytes[i];
  673. if (pa <= pb && pa <= pc) {
  674. buffer[j++] = left + c;
  675. } else if (pb <= pc) {
  676. buffer[j++] = up + c;
  677. } else {
  678. buffer[j++] = upLeft + c;
  679. }
  680. }
  681. break;
  682. default:
  683. throw new _util.FormatError('Unsupported predictor: ' + predictor);
  684. }
  685. this.bufferLength += rowBytes;
  686. };
  687. return PredictorStream;
  688. }();
  689. var DecryptStream = function DecryptStreamClosure() {
  690. function DecryptStream(str, maybeLength, decrypt) {
  691. this.str = str;
  692. this.dict = str.dict;
  693. this.decrypt = decrypt;
  694. this.nextChunk = null;
  695. this.initialized = false;
  696. DecodeStream.call(this, maybeLength);
  697. }
  698. var chunkSize = 512;
  699. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  700. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  701. var chunk;
  702. if (this.initialized) {
  703. chunk = this.nextChunk;
  704. } else {
  705. chunk = this.str.getBytes(chunkSize);
  706. this.initialized = true;
  707. }
  708. if (!chunk || chunk.length === 0) {
  709. this.eof = true;
  710. return;
  711. }
  712. this.nextChunk = this.str.getBytes(chunkSize);
  713. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  714. var decrypt = this.decrypt;
  715. chunk = decrypt(chunk, !hasMoreData);
  716. var bufferLength = this.bufferLength;
  717. var i,
  718. n = chunk.length;
  719. var buffer = this.ensureBuffer(bufferLength + n);
  720. for (i = 0; i < n; i++) {
  721. buffer[bufferLength++] = chunk[i];
  722. }
  723. this.bufferLength = bufferLength;
  724. };
  725. return DecryptStream;
  726. }();
  727. var Ascii85Stream = function Ascii85StreamClosure() {
  728. function Ascii85Stream(str, maybeLength) {
  729. this.str = str;
  730. this.dict = str.dict;
  731. this.input = new Uint8Array(5);
  732. if (maybeLength) {
  733. maybeLength = 0.8 * maybeLength;
  734. }
  735. DecodeStream.call(this, maybeLength);
  736. }
  737. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  738. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  739. var TILDA_CHAR = 0x7E;
  740. var Z_LOWER_CHAR = 0x7A;
  741. var EOF = -1;
  742. var str = this.str;
  743. var c = str.getByte();
  744. while ((0, _util.isSpace)(c)) {
  745. c = str.getByte();
  746. }
  747. if (c === EOF || c === TILDA_CHAR) {
  748. this.eof = true;
  749. return;
  750. }
  751. var bufferLength = this.bufferLength,
  752. buffer;
  753. var i;
  754. if (c === Z_LOWER_CHAR) {
  755. buffer = this.ensureBuffer(bufferLength + 4);
  756. for (i = 0; i < 4; ++i) {
  757. buffer[bufferLength + i] = 0;
  758. }
  759. this.bufferLength += 4;
  760. } else {
  761. var input = this.input;
  762. input[0] = c;
  763. for (i = 1; i < 5; ++i) {
  764. c = str.getByte();
  765. while ((0, _util.isSpace)(c)) {
  766. c = str.getByte();
  767. }
  768. input[i] = c;
  769. if (c === EOF || c === TILDA_CHAR) {
  770. break;
  771. }
  772. }
  773. buffer = this.ensureBuffer(bufferLength + i - 1);
  774. this.bufferLength += i - 1;
  775. if (i < 5) {
  776. for (; i < 5; ++i) {
  777. input[i] = 0x21 + 84;
  778. }
  779. this.eof = true;
  780. }
  781. var t = 0;
  782. for (i = 0; i < 5; ++i) {
  783. t = t * 85 + (input[i] - 0x21);
  784. }
  785. for (i = 3; i >= 0; --i) {
  786. buffer[bufferLength + i] = t & 0xFF;
  787. t >>= 8;
  788. }
  789. }
  790. };
  791. return Ascii85Stream;
  792. }();
  793. var AsciiHexStream = function AsciiHexStreamClosure() {
  794. function AsciiHexStream(str, maybeLength) {
  795. this.str = str;
  796. this.dict = str.dict;
  797. this.firstDigit = -1;
  798. if (maybeLength) {
  799. maybeLength = 0.5 * maybeLength;
  800. }
  801. DecodeStream.call(this, maybeLength);
  802. }
  803. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  804. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  805. var UPSTREAM_BLOCK_SIZE = 8000;
  806. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  807. if (!bytes.length) {
  808. this.eof = true;
  809. return;
  810. }
  811. var maxDecodeLength = bytes.length + 1 >> 1;
  812. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  813. var bufferLength = this.bufferLength;
  814. var firstDigit = this.firstDigit;
  815. for (var i = 0, ii = bytes.length; i < ii; i++) {
  816. var ch = bytes[i],
  817. digit;
  818. if (ch >= 0x30 && ch <= 0x39) {
  819. digit = ch & 0x0F;
  820. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  821. digit = (ch & 0x0F) + 9;
  822. } else if (ch === 0x3E) {
  823. this.eof = true;
  824. break;
  825. } else {
  826. continue;
  827. }
  828. if (firstDigit < 0) {
  829. firstDigit = digit;
  830. } else {
  831. buffer[bufferLength++] = firstDigit << 4 | digit;
  832. firstDigit = -1;
  833. }
  834. }
  835. if (firstDigit >= 0 && this.eof) {
  836. buffer[bufferLength++] = firstDigit << 4;
  837. firstDigit = -1;
  838. }
  839. this.firstDigit = firstDigit;
  840. this.bufferLength = bufferLength;
  841. };
  842. return AsciiHexStream;
  843. }();
  844. var RunLengthStream = function RunLengthStreamClosure() {
  845. function RunLengthStream(str, maybeLength) {
  846. this.str = str;
  847. this.dict = str.dict;
  848. DecodeStream.call(this, maybeLength);
  849. }
  850. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  851. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  852. var repeatHeader = this.str.getBytes(2);
  853. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  854. this.eof = true;
  855. return;
  856. }
  857. var buffer;
  858. var bufferLength = this.bufferLength;
  859. var n = repeatHeader[0];
  860. if (n < 128) {
  861. buffer = this.ensureBuffer(bufferLength + n + 1);
  862. buffer[bufferLength++] = repeatHeader[1];
  863. if (n > 0) {
  864. var source = this.str.getBytes(n);
  865. buffer.set(source, bufferLength);
  866. bufferLength += n;
  867. }
  868. } else {
  869. n = 257 - n;
  870. var b = repeatHeader[1];
  871. buffer = this.ensureBuffer(bufferLength + n + 1);
  872. for (var i = 0; i < n; i++) {
  873. buffer[bufferLength++] = b;
  874. }
  875. }
  876. this.bufferLength = bufferLength;
  877. };
  878. return RunLengthStream;
  879. }();
  880. var LZWStream = function LZWStreamClosure() {
  881. function LZWStream(str, maybeLength, earlyChange) {
  882. this.str = str;
  883. this.dict = str.dict;
  884. this.cachedData = 0;
  885. this.bitsCached = 0;
  886. var maxLzwDictionarySize = 4096;
  887. var lzwState = {
  888. earlyChange: earlyChange,
  889. codeLength: 9,
  890. nextCode: 258,
  891. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  892. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  893. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  894. currentSequence: new Uint8Array(maxLzwDictionarySize),
  895. currentSequenceLength: 0
  896. };
  897. for (var i = 0; i < 256; ++i) {
  898. lzwState.dictionaryValues[i] = i;
  899. lzwState.dictionaryLengths[i] = 1;
  900. }
  901. this.lzwState = lzwState;
  902. DecodeStream.call(this, maybeLength);
  903. }
  904. LZWStream.prototype = Object.create(DecodeStream.prototype);
  905. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  906. var bitsCached = this.bitsCached;
  907. var cachedData = this.cachedData;
  908. while (bitsCached < n) {
  909. var c = this.str.getByte();
  910. if (c === -1) {
  911. this.eof = true;
  912. return null;
  913. }
  914. cachedData = cachedData << 8 | c;
  915. bitsCached += 8;
  916. }
  917. this.bitsCached = bitsCached -= n;
  918. this.cachedData = cachedData;
  919. this.lastCode = null;
  920. return cachedData >>> bitsCached & (1 << n) - 1;
  921. };
  922. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  923. var blockSize = 512;
  924. var estimatedDecodedSize = blockSize * 2,
  925. decodedSizeDelta = blockSize;
  926. var i, j, q;
  927. var lzwState = this.lzwState;
  928. if (!lzwState) {
  929. return;
  930. }
  931. var earlyChange = lzwState.earlyChange;
  932. var nextCode = lzwState.nextCode;
  933. var dictionaryValues = lzwState.dictionaryValues;
  934. var dictionaryLengths = lzwState.dictionaryLengths;
  935. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  936. var codeLength = lzwState.codeLength;
  937. var prevCode = lzwState.prevCode;
  938. var currentSequence = lzwState.currentSequence;
  939. var currentSequenceLength = lzwState.currentSequenceLength;
  940. var decodedLength = 0;
  941. var currentBufferLength = this.bufferLength;
  942. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  943. for (i = 0; i < blockSize; i++) {
  944. var code = this.readBits(codeLength);
  945. var hasPrev = currentSequenceLength > 0;
  946. if (code < 256) {
  947. currentSequence[0] = code;
  948. currentSequenceLength = 1;
  949. } else if (code >= 258) {
  950. if (code < nextCode) {
  951. currentSequenceLength = dictionaryLengths[code];
  952. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  953. currentSequence[j] = dictionaryValues[q];
  954. q = dictionaryPrevCodes[q];
  955. }
  956. } else {
  957. currentSequence[currentSequenceLength++] = currentSequence[0];
  958. }
  959. } else if (code === 256) {
  960. codeLength = 9;
  961. nextCode = 258;
  962. currentSequenceLength = 0;
  963. continue;
  964. } else {
  965. this.eof = true;
  966. delete this.lzwState;
  967. break;
  968. }
  969. if (hasPrev) {
  970. dictionaryPrevCodes[nextCode] = prevCode;
  971. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  972. dictionaryValues[nextCode] = currentSequence[0];
  973. nextCode++;
  974. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  975. }
  976. prevCode = code;
  977. decodedLength += currentSequenceLength;
  978. if (estimatedDecodedSize < decodedLength) {
  979. do {
  980. estimatedDecodedSize += decodedSizeDelta;
  981. } while (estimatedDecodedSize < decodedLength);
  982. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  983. }
  984. for (j = 0; j < currentSequenceLength; j++) {
  985. buffer[currentBufferLength++] = currentSequence[j];
  986. }
  987. }
  988. lzwState.nextCode = nextCode;
  989. lzwState.codeLength = codeLength;
  990. lzwState.prevCode = prevCode;
  991. lzwState.currentSequenceLength = currentSequenceLength;
  992. this.bufferLength = currentBufferLength;
  993. };
  994. return LZWStream;
  995. }();
  996. var NullStream = function NullStreamClosure() {
  997. function NullStream() {
  998. Stream.call(this, new Uint8Array(0));
  999. }
  1000. NullStream.prototype = Stream.prototype;
  1001. return NullStream;
  1002. }();
  1003. exports.Ascii85Stream = Ascii85Stream;
  1004. exports.AsciiHexStream = AsciiHexStream;
  1005. exports.DecryptStream = DecryptStream;
  1006. exports.DecodeStream = DecodeStream;
  1007. exports.FlateStream = FlateStream;
  1008. exports.NullStream = NullStream;
  1009. exports.PredictorStream = PredictorStream;
  1010. exports.RunLengthStream = RunLengthStream;
  1011. exports.Stream = Stream;
  1012. exports.StreamsSequenceStream = StreamsSequenceStream;
  1013. exports.StringStream = StringStream;
  1014. exports.LZWStream = LZWStream;