stream.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. 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;
  20. var _util = require('../shared/util');
  21. var _primitives = require('./primitives');
  22. var Stream = function StreamClosure() {
  23. function Stream(arrayBuffer, start, length, dict) {
  24. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  25. this.start = start || 0;
  26. this.pos = this.start;
  27. this.end = start + length || this.bytes.length;
  28. this.dict = dict;
  29. }
  30. Stream.prototype = {
  31. get length() {
  32. return this.end - this.start;
  33. },
  34. get isEmpty() {
  35. return this.length === 0;
  36. },
  37. getByte: function Stream_getByte() {
  38. if (this.pos >= this.end) {
  39. return -1;
  40. }
  41. return this.bytes[this.pos++];
  42. },
  43. getUint16: function Stream_getUint16() {
  44. var b0 = this.getByte();
  45. var b1 = this.getByte();
  46. if (b0 === -1 || b1 === -1) {
  47. return -1;
  48. }
  49. return (b0 << 8) + b1;
  50. },
  51. getInt32: function Stream_getInt32() {
  52. var b0 = this.getByte();
  53. var b1 = this.getByte();
  54. var b2 = this.getByte();
  55. var b3 = this.getByte();
  56. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  57. },
  58. getBytes: function Stream_getBytes(length) {
  59. var bytes = this.bytes;
  60. var pos = this.pos;
  61. var strEnd = this.end;
  62. if (!length) {
  63. return bytes.subarray(pos, strEnd);
  64. }
  65. var end = pos + length;
  66. if (end > strEnd) {
  67. end = strEnd;
  68. }
  69. this.pos = end;
  70. return bytes.subarray(pos, end);
  71. },
  72. peekByte: function Stream_peekByte() {
  73. var peekedByte = this.getByte();
  74. this.pos--;
  75. return peekedByte;
  76. },
  77. peekBytes: function Stream_peekBytes(length) {
  78. var bytes = this.getBytes(length);
  79. this.pos -= bytes.length;
  80. return bytes;
  81. },
  82. skip: function Stream_skip(n) {
  83. if (!n) {
  84. n = 1;
  85. }
  86. this.pos += n;
  87. },
  88. reset: function Stream_reset() {
  89. this.pos = this.start;
  90. },
  91. moveStart: function Stream_moveStart() {
  92. this.start = this.pos;
  93. },
  94. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  95. return new Stream(this.bytes.buffer, start, length, dict);
  96. }
  97. };
  98. return Stream;
  99. }();
  100. var StringStream = function StringStreamClosure() {
  101. function StringStream(str) {
  102. var bytes = (0, _util.stringToBytes)(str);
  103. Stream.call(this, bytes);
  104. }
  105. StringStream.prototype = Stream.prototype;
  106. return StringStream;
  107. }();
  108. var DecodeStream = function DecodeStreamClosure() {
  109. var emptyBuffer = new Uint8Array(0);
  110. function DecodeStream(maybeMinBufferLength) {
  111. this.pos = 0;
  112. this.bufferLength = 0;
  113. this.eof = false;
  114. this.buffer = emptyBuffer;
  115. this.minBufferLength = 512;
  116. if (maybeMinBufferLength) {
  117. while (this.minBufferLength < maybeMinBufferLength) {
  118. this.minBufferLength *= 2;
  119. }
  120. }
  121. }
  122. DecodeStream.prototype = {
  123. get isEmpty() {
  124. while (!this.eof && this.bufferLength === 0) {
  125. this.readBlock();
  126. }
  127. return this.bufferLength === 0;
  128. },
  129. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  130. var buffer = this.buffer;
  131. if (requested <= buffer.byteLength) {
  132. return buffer;
  133. }
  134. var size = this.minBufferLength;
  135. while (size < requested) {
  136. size *= 2;
  137. }
  138. var buffer2 = new Uint8Array(size);
  139. buffer2.set(buffer);
  140. return this.buffer = buffer2;
  141. },
  142. getByte: function DecodeStream_getByte() {
  143. var pos = this.pos;
  144. while (this.bufferLength <= pos) {
  145. if (this.eof) {
  146. return -1;
  147. }
  148. this.readBlock();
  149. }
  150. return this.buffer[this.pos++];
  151. },
  152. getUint16: function DecodeStream_getUint16() {
  153. var b0 = this.getByte();
  154. var b1 = this.getByte();
  155. if (b0 === -1 || b1 === -1) {
  156. return -1;
  157. }
  158. return (b0 << 8) + b1;
  159. },
  160. getInt32: function DecodeStream_getInt32() {
  161. var b0 = this.getByte();
  162. var b1 = this.getByte();
  163. var b2 = this.getByte();
  164. var b3 = this.getByte();
  165. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  166. },
  167. getBytes: function DecodeStream_getBytes(length) {
  168. var end,
  169. pos = this.pos;
  170. if (length) {
  171. this.ensureBuffer(pos + length);
  172. end = pos + length;
  173. while (!this.eof && this.bufferLength < end) {
  174. this.readBlock();
  175. }
  176. var bufEnd = this.bufferLength;
  177. if (end > bufEnd) {
  178. end = bufEnd;
  179. }
  180. } else {
  181. while (!this.eof) {
  182. this.readBlock();
  183. }
  184. end = this.bufferLength;
  185. }
  186. this.pos = end;
  187. return this.buffer.subarray(pos, end);
  188. },
  189. peekByte: function DecodeStream_peekByte() {
  190. var peekedByte = this.getByte();
  191. this.pos--;
  192. return peekedByte;
  193. },
  194. peekBytes: function DecodeStream_peekBytes(length) {
  195. var bytes = this.getBytes(length);
  196. this.pos -= bytes.length;
  197. return bytes;
  198. },
  199. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  200. var end = start + length;
  201. while (this.bufferLength <= end && !this.eof) {
  202. this.readBlock();
  203. }
  204. return new Stream(this.buffer, start, length, dict);
  205. },
  206. skip: function DecodeStream_skip(n) {
  207. if (!n) {
  208. n = 1;
  209. }
  210. this.pos += n;
  211. },
  212. reset: function DecodeStream_reset() {
  213. this.pos = 0;
  214. },
  215. getBaseStreams: function DecodeStream_getBaseStreams() {
  216. if (this.str && this.str.getBaseStreams) {
  217. return this.str.getBaseStreams();
  218. }
  219. return [];
  220. }
  221. };
  222. return DecodeStream;
  223. }();
  224. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  225. function StreamsSequenceStream(streams) {
  226. this.streams = streams;
  227. DecodeStream.call(this, null);
  228. }
  229. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  230. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  231. var streams = this.streams;
  232. if (streams.length === 0) {
  233. this.eof = true;
  234. return;
  235. }
  236. var stream = streams.shift();
  237. var chunk = stream.getBytes();
  238. var bufferLength = this.bufferLength;
  239. var newLength = bufferLength + chunk.length;
  240. var buffer = this.ensureBuffer(newLength);
  241. buffer.set(chunk, bufferLength);
  242. this.bufferLength = newLength;
  243. };
  244. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  245. var baseStreams = [];
  246. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  247. var stream = this.streams[i];
  248. if (stream.getBaseStreams) {
  249. _util.Util.appendToArray(baseStreams, stream.getBaseStreams());
  250. }
  251. }
  252. return baseStreams;
  253. };
  254. return StreamsSequenceStream;
  255. }();
  256. var FlateStream = function FlateStreamClosure() {
  257. var codeLenCodeMap = new Int32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
  258. 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]);
  259. 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]);
  260. 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];
  261. 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];
  262. function FlateStream(str, maybeLength) {
  263. this.str = str;
  264. this.dict = str.dict;
  265. var cmf = str.getByte();
  266. var flg = str.getByte();
  267. if (cmf === -1 || flg === -1) {
  268. throw new _util.FormatError('Invalid header in flate stream: ' + cmf + ', ' + flg);
  269. }
  270. if ((cmf & 0x0f) !== 0x08) {
  271. throw new _util.FormatError('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  272. }
  273. if (((cmf << 8) + flg) % 31 !== 0) {
  274. throw new _util.FormatError('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  275. }
  276. if (flg & 0x20) {
  277. throw new _util.FormatError('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  278. }
  279. this.codeSize = 0;
  280. this.codeBuf = 0;
  281. DecodeStream.call(this, maybeLength);
  282. }
  283. FlateStream.prototype = Object.create(DecodeStream.prototype);
  284. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  285. var str = this.str;
  286. var codeSize = this.codeSize;
  287. var codeBuf = this.codeBuf;
  288. var b;
  289. while (codeSize < bits) {
  290. if ((b = str.getByte()) === -1) {
  291. throw new _util.FormatError('Bad encoding in flate stream');
  292. }
  293. codeBuf |= b << codeSize;
  294. codeSize += 8;
  295. }
  296. b = codeBuf & (1 << bits) - 1;
  297. this.codeBuf = codeBuf >> bits;
  298. this.codeSize = codeSize -= bits;
  299. return b;
  300. };
  301. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  302. var str = this.str;
  303. var codes = table[0];
  304. var maxLen = table[1];
  305. var codeSize = this.codeSize;
  306. var codeBuf = this.codeBuf;
  307. var b;
  308. while (codeSize < maxLen) {
  309. if ((b = str.getByte()) === -1) {
  310. break;
  311. }
  312. codeBuf |= b << codeSize;
  313. codeSize += 8;
  314. }
  315. var code = codes[codeBuf & (1 << maxLen) - 1];
  316. var codeLen = code >> 16;
  317. var codeVal = code & 0xffff;
  318. if (codeLen < 1 || codeSize < codeLen) {
  319. throw new _util.FormatError('Bad encoding in flate stream');
  320. }
  321. this.codeBuf = codeBuf >> codeLen;
  322. this.codeSize = codeSize - codeLen;
  323. return codeVal;
  324. };
  325. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  326. var n = lengths.length;
  327. var maxLen = 0;
  328. var i;
  329. for (i = 0; i < n; ++i) {
  330. if (lengths[i] > maxLen) {
  331. maxLen = lengths[i];
  332. }
  333. }
  334. var size = 1 << maxLen;
  335. var codes = new Int32Array(size);
  336. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  337. for (var val = 0; val < n; ++val) {
  338. if (lengths[val] === len) {
  339. var code2 = 0;
  340. var t = code;
  341. for (i = 0; i < len; ++i) {
  342. code2 = code2 << 1 | t & 1;
  343. t >>= 1;
  344. }
  345. for (i = code2; i < size; i += skip) {
  346. codes[i] = len << 16 | val;
  347. }
  348. ++code;
  349. }
  350. }
  351. }
  352. return [codes, maxLen];
  353. };
  354. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  355. var buffer, len;
  356. var str = this.str;
  357. var hdr = this.getBits(3);
  358. if (hdr & 1) {
  359. this.eof = true;
  360. }
  361. hdr >>= 1;
  362. if (hdr === 0) {
  363. var b;
  364. if ((b = str.getByte()) === -1) {
  365. throw new _util.FormatError('Bad block header in flate stream');
  366. }
  367. var blockLen = b;
  368. if ((b = str.getByte()) === -1) {
  369. throw new _util.FormatError('Bad block header in flate stream');
  370. }
  371. blockLen |= b << 8;
  372. if ((b = str.getByte()) === -1) {
  373. throw new _util.FormatError('Bad block header in flate stream');
  374. }
  375. var check = b;
  376. if ((b = str.getByte()) === -1) {
  377. throw new _util.FormatError('Bad block header in flate stream');
  378. }
  379. check |= b << 8;
  380. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  381. throw new _util.FormatError('Bad uncompressed block length in flate stream');
  382. }
  383. this.codeBuf = 0;
  384. this.codeSize = 0;
  385. var bufferLength = this.bufferLength;
  386. buffer = this.ensureBuffer(bufferLength + blockLen);
  387. var end = bufferLength + blockLen;
  388. this.bufferLength = end;
  389. if (blockLen === 0) {
  390. if (str.peekByte() === -1) {
  391. this.eof = true;
  392. }
  393. } else {
  394. for (var n = bufferLength; n < end; ++n) {
  395. if ((b = str.getByte()) === -1) {
  396. this.eof = true;
  397. break;
  398. }
  399. buffer[n] = b;
  400. }
  401. }
  402. return;
  403. }
  404. var litCodeTable;
  405. var distCodeTable;
  406. if (hdr === 1) {
  407. litCodeTable = fixedLitCodeTab;
  408. distCodeTable = fixedDistCodeTab;
  409. } else if (hdr === 2) {
  410. var numLitCodes = this.getBits(5) + 257;
  411. var numDistCodes = this.getBits(5) + 1;
  412. var numCodeLenCodes = this.getBits(4) + 4;
  413. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  414. var i;
  415. for (i = 0; i < numCodeLenCodes; ++i) {
  416. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  417. }
  418. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  419. len = 0;
  420. i = 0;
  421. var codes = numLitCodes + numDistCodes;
  422. var codeLengths = new Uint8Array(codes);
  423. var bitsLength, bitsOffset, what;
  424. while (i < codes) {
  425. var code = this.getCode(codeLenCodeTab);
  426. if (code === 16) {
  427. bitsLength = 2;
  428. bitsOffset = 3;
  429. what = len;
  430. } else if (code === 17) {
  431. bitsLength = 3;
  432. bitsOffset = 3;
  433. what = len = 0;
  434. } else if (code === 18) {
  435. bitsLength = 7;
  436. bitsOffset = 11;
  437. what = len = 0;
  438. } else {
  439. codeLengths[i++] = len = code;
  440. continue;
  441. }
  442. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  443. while (repeatLength-- > 0) {
  444. codeLengths[i++] = what;
  445. }
  446. }
  447. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  448. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  449. } else {
  450. throw new _util.FormatError('Unknown block type in flate stream');
  451. }
  452. buffer = this.buffer;
  453. var limit = buffer ? buffer.length : 0;
  454. var pos = this.bufferLength;
  455. while (true) {
  456. var code1 = this.getCode(litCodeTable);
  457. if (code1 < 256) {
  458. if (pos + 1 >= limit) {
  459. buffer = this.ensureBuffer(pos + 1);
  460. limit = buffer.length;
  461. }
  462. buffer[pos++] = code1;
  463. continue;
  464. }
  465. if (code1 === 256) {
  466. this.bufferLength = pos;
  467. return;
  468. }
  469. code1 -= 257;
  470. code1 = lengthDecode[code1];
  471. var code2 = code1 >> 16;
  472. if (code2 > 0) {
  473. code2 = this.getBits(code2);
  474. }
  475. len = (code1 & 0xffff) + code2;
  476. code1 = this.getCode(distCodeTable);
  477. code1 = distDecode[code1];
  478. code2 = code1 >> 16;
  479. if (code2 > 0) {
  480. code2 = this.getBits(code2);
  481. }
  482. var dist = (code1 & 0xffff) + code2;
  483. if (pos + len >= limit) {
  484. buffer = this.ensureBuffer(pos + len);
  485. limit = buffer.length;
  486. }
  487. for (var k = 0; k < len; ++k, ++pos) {
  488. buffer[pos] = buffer[pos - dist];
  489. }
  490. }
  491. };
  492. return FlateStream;
  493. }();
  494. var PredictorStream = function PredictorStreamClosure() {
  495. function PredictorStream(str, maybeLength, params) {
  496. if (!(0, _primitives.isDict)(params)) {
  497. return str;
  498. }
  499. var predictor = this.predictor = params.get('Predictor') || 1;
  500. if (predictor <= 1) {
  501. return str;
  502. }
  503. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  504. throw new _util.FormatError('Unsupported predictor: ' + predictor);
  505. }
  506. if (predictor === 2) {
  507. this.readBlock = this.readBlockTiff;
  508. } else {
  509. this.readBlock = this.readBlockPng;
  510. }
  511. this.str = str;
  512. this.dict = str.dict;
  513. var colors = this.colors = params.get('Colors') || 1;
  514. var bits = this.bits = params.get('BitsPerComponent') || 8;
  515. var columns = this.columns = params.get('Columns') || 1;
  516. this.pixBytes = colors * bits + 7 >> 3;
  517. this.rowBytes = columns * colors * bits + 7 >> 3;
  518. DecodeStream.call(this, maybeLength);
  519. return this;
  520. }
  521. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  522. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  523. var rowBytes = this.rowBytes;
  524. var bufferLength = this.bufferLength;
  525. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  526. var bits = this.bits;
  527. var colors = this.colors;
  528. var rawBytes = this.str.getBytes(rowBytes);
  529. this.eof = !rawBytes.length;
  530. if (this.eof) {
  531. return;
  532. }
  533. var inbuf = 0,
  534. outbuf = 0;
  535. var inbits = 0,
  536. outbits = 0;
  537. var pos = bufferLength;
  538. var i;
  539. if (bits === 1 && colors === 1) {
  540. for (i = 0; i < rowBytes; ++i) {
  541. var c = rawBytes[i] ^ inbuf;
  542. c ^= c >> 1;
  543. c ^= c >> 2;
  544. c ^= c >> 4;
  545. inbuf = (c & 1) << 7;
  546. buffer[pos++] = c;
  547. }
  548. } else if (bits === 8) {
  549. for (i = 0; i < colors; ++i) {
  550. buffer[pos++] = rawBytes[i];
  551. }
  552. for (; i < rowBytes; ++i) {
  553. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  554. pos++;
  555. }
  556. } else if (bits === 16) {
  557. var bytesPerPixel = colors * 2;
  558. for (i = 0; i < bytesPerPixel; ++i) {
  559. buffer[pos++] = rawBytes[i];
  560. }
  561. for (; i < rowBytes; i += 2) {
  562. var sum = ((rawBytes[i] & 0xFF) << 8) + (rawBytes[i + 1] & 0xFF) + ((buffer[pos - bytesPerPixel] & 0xFF) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xFF);
  563. buffer[pos++] = sum >> 8 & 0xFF;
  564. buffer[pos++] = sum & 0xFF;
  565. }
  566. } else {
  567. var compArray = new Uint8Array(colors + 1);
  568. var bitMask = (1 << bits) - 1;
  569. var j = 0,
  570. k = bufferLength;
  571. var columns = this.columns;
  572. for (i = 0; i < columns; ++i) {
  573. for (var kk = 0; kk < colors; ++kk) {
  574. if (inbits < bits) {
  575. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  576. inbits += 8;
  577. }
  578. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  579. inbits -= bits;
  580. outbuf = outbuf << bits | compArray[kk];
  581. outbits += bits;
  582. if (outbits >= 8) {
  583. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  584. outbits -= 8;
  585. }
  586. }
  587. }
  588. if (outbits > 0) {
  589. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  590. }
  591. }
  592. this.bufferLength += rowBytes;
  593. };
  594. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  595. var rowBytes = this.rowBytes;
  596. var pixBytes = this.pixBytes;
  597. var predictor = this.str.getByte();
  598. var rawBytes = this.str.getBytes(rowBytes);
  599. this.eof = !rawBytes.length;
  600. if (this.eof) {
  601. return;
  602. }
  603. var bufferLength = this.bufferLength;
  604. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  605. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  606. if (prevRow.length === 0) {
  607. prevRow = new Uint8Array(rowBytes);
  608. }
  609. var i,
  610. j = bufferLength,
  611. up,
  612. c;
  613. switch (predictor) {
  614. case 0:
  615. for (i = 0; i < rowBytes; ++i) {
  616. buffer[j++] = rawBytes[i];
  617. }
  618. break;
  619. case 1:
  620. for (i = 0; i < pixBytes; ++i) {
  621. buffer[j++] = rawBytes[i];
  622. }
  623. for (; i < rowBytes; ++i) {
  624. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  625. j++;
  626. }
  627. break;
  628. case 2:
  629. for (i = 0; i < rowBytes; ++i) {
  630. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  631. }
  632. break;
  633. case 3:
  634. for (i = 0; i < pixBytes; ++i) {
  635. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  636. }
  637. for (; i < rowBytes; ++i) {
  638. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  639. j++;
  640. }
  641. break;
  642. case 4:
  643. for (i = 0; i < pixBytes; ++i) {
  644. up = prevRow[i];
  645. c = rawBytes[i];
  646. buffer[j++] = up + c;
  647. }
  648. for (; i < rowBytes; ++i) {
  649. up = prevRow[i];
  650. var upLeft = prevRow[i - pixBytes];
  651. var left = buffer[j - pixBytes];
  652. var p = left + up - upLeft;
  653. var pa = p - left;
  654. if (pa < 0) {
  655. pa = -pa;
  656. }
  657. var pb = p - up;
  658. if (pb < 0) {
  659. pb = -pb;
  660. }
  661. var pc = p - upLeft;
  662. if (pc < 0) {
  663. pc = -pc;
  664. }
  665. c = rawBytes[i];
  666. if (pa <= pb && pa <= pc) {
  667. buffer[j++] = left + c;
  668. } else if (pb <= pc) {
  669. buffer[j++] = up + c;
  670. } else {
  671. buffer[j++] = upLeft + c;
  672. }
  673. }
  674. break;
  675. default:
  676. throw new _util.FormatError('Unsupported predictor: ' + predictor);
  677. }
  678. this.bufferLength += rowBytes;
  679. };
  680. return PredictorStream;
  681. }();
  682. var DecryptStream = function DecryptStreamClosure() {
  683. function DecryptStream(str, maybeLength, decrypt) {
  684. this.str = str;
  685. this.dict = str.dict;
  686. this.decrypt = decrypt;
  687. this.nextChunk = null;
  688. this.initialized = false;
  689. DecodeStream.call(this, maybeLength);
  690. }
  691. var chunkSize = 512;
  692. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  693. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  694. var chunk;
  695. if (this.initialized) {
  696. chunk = this.nextChunk;
  697. } else {
  698. chunk = this.str.getBytes(chunkSize);
  699. this.initialized = true;
  700. }
  701. if (!chunk || chunk.length === 0) {
  702. this.eof = true;
  703. return;
  704. }
  705. this.nextChunk = this.str.getBytes(chunkSize);
  706. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  707. var decrypt = this.decrypt;
  708. chunk = decrypt(chunk, !hasMoreData);
  709. var bufferLength = this.bufferLength;
  710. var i,
  711. n = chunk.length;
  712. var buffer = this.ensureBuffer(bufferLength + n);
  713. for (i = 0; i < n; i++) {
  714. buffer[bufferLength++] = chunk[i];
  715. }
  716. this.bufferLength = bufferLength;
  717. };
  718. return DecryptStream;
  719. }();
  720. var Ascii85Stream = function Ascii85StreamClosure() {
  721. function Ascii85Stream(str, maybeLength) {
  722. this.str = str;
  723. this.dict = str.dict;
  724. this.input = new Uint8Array(5);
  725. if (maybeLength) {
  726. maybeLength = 0.8 * maybeLength;
  727. }
  728. DecodeStream.call(this, maybeLength);
  729. }
  730. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  731. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  732. var TILDA_CHAR = 0x7E;
  733. var Z_LOWER_CHAR = 0x7A;
  734. var EOF = -1;
  735. var str = this.str;
  736. var c = str.getByte();
  737. while ((0, _util.isSpace)(c)) {
  738. c = str.getByte();
  739. }
  740. if (c === EOF || c === TILDA_CHAR) {
  741. this.eof = true;
  742. return;
  743. }
  744. var bufferLength = this.bufferLength,
  745. buffer;
  746. var i;
  747. if (c === Z_LOWER_CHAR) {
  748. buffer = this.ensureBuffer(bufferLength + 4);
  749. for (i = 0; i < 4; ++i) {
  750. buffer[bufferLength + i] = 0;
  751. }
  752. this.bufferLength += 4;
  753. } else {
  754. var input = this.input;
  755. input[0] = c;
  756. for (i = 1; i < 5; ++i) {
  757. c = str.getByte();
  758. while ((0, _util.isSpace)(c)) {
  759. c = str.getByte();
  760. }
  761. input[i] = c;
  762. if (c === EOF || c === TILDA_CHAR) {
  763. break;
  764. }
  765. }
  766. buffer = this.ensureBuffer(bufferLength + i - 1);
  767. this.bufferLength += i - 1;
  768. if (i < 5) {
  769. for (; i < 5; ++i) {
  770. input[i] = 0x21 + 84;
  771. }
  772. this.eof = true;
  773. }
  774. var t = 0;
  775. for (i = 0; i < 5; ++i) {
  776. t = t * 85 + (input[i] - 0x21);
  777. }
  778. for (i = 3; i >= 0; --i) {
  779. buffer[bufferLength + i] = t & 0xFF;
  780. t >>= 8;
  781. }
  782. }
  783. };
  784. return Ascii85Stream;
  785. }();
  786. var AsciiHexStream = function AsciiHexStreamClosure() {
  787. function AsciiHexStream(str, maybeLength) {
  788. this.str = str;
  789. this.dict = str.dict;
  790. this.firstDigit = -1;
  791. if (maybeLength) {
  792. maybeLength = 0.5 * maybeLength;
  793. }
  794. DecodeStream.call(this, maybeLength);
  795. }
  796. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  797. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  798. var UPSTREAM_BLOCK_SIZE = 8000;
  799. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  800. if (!bytes.length) {
  801. this.eof = true;
  802. return;
  803. }
  804. var maxDecodeLength = bytes.length + 1 >> 1;
  805. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  806. var bufferLength = this.bufferLength;
  807. var firstDigit = this.firstDigit;
  808. for (var i = 0, ii = bytes.length; i < ii; i++) {
  809. var ch = bytes[i],
  810. digit;
  811. if (ch >= 0x30 && ch <= 0x39) {
  812. digit = ch & 0x0F;
  813. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  814. digit = (ch & 0x0F) + 9;
  815. } else if (ch === 0x3E) {
  816. this.eof = true;
  817. break;
  818. } else {
  819. continue;
  820. }
  821. if (firstDigit < 0) {
  822. firstDigit = digit;
  823. } else {
  824. buffer[bufferLength++] = firstDigit << 4 | digit;
  825. firstDigit = -1;
  826. }
  827. }
  828. if (firstDigit >= 0 && this.eof) {
  829. buffer[bufferLength++] = firstDigit << 4;
  830. firstDigit = -1;
  831. }
  832. this.firstDigit = firstDigit;
  833. this.bufferLength = bufferLength;
  834. };
  835. return AsciiHexStream;
  836. }();
  837. var RunLengthStream = function RunLengthStreamClosure() {
  838. function RunLengthStream(str, maybeLength) {
  839. this.str = str;
  840. this.dict = str.dict;
  841. DecodeStream.call(this, maybeLength);
  842. }
  843. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  844. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  845. var repeatHeader = this.str.getBytes(2);
  846. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  847. this.eof = true;
  848. return;
  849. }
  850. var buffer;
  851. var bufferLength = this.bufferLength;
  852. var n = repeatHeader[0];
  853. if (n < 128) {
  854. buffer = this.ensureBuffer(bufferLength + n + 1);
  855. buffer[bufferLength++] = repeatHeader[1];
  856. if (n > 0) {
  857. var source = this.str.getBytes(n);
  858. buffer.set(source, bufferLength);
  859. bufferLength += n;
  860. }
  861. } else {
  862. n = 257 - n;
  863. var b = repeatHeader[1];
  864. buffer = this.ensureBuffer(bufferLength + n + 1);
  865. for (var i = 0; i < n; i++) {
  866. buffer[bufferLength++] = b;
  867. }
  868. }
  869. this.bufferLength = bufferLength;
  870. };
  871. return RunLengthStream;
  872. }();
  873. var LZWStream = function LZWStreamClosure() {
  874. function LZWStream(str, maybeLength, earlyChange) {
  875. this.str = str;
  876. this.dict = str.dict;
  877. this.cachedData = 0;
  878. this.bitsCached = 0;
  879. var maxLzwDictionarySize = 4096;
  880. var lzwState = {
  881. earlyChange: earlyChange,
  882. codeLength: 9,
  883. nextCode: 258,
  884. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  885. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  886. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  887. currentSequence: new Uint8Array(maxLzwDictionarySize),
  888. currentSequenceLength: 0
  889. };
  890. for (var i = 0; i < 256; ++i) {
  891. lzwState.dictionaryValues[i] = i;
  892. lzwState.dictionaryLengths[i] = 1;
  893. }
  894. this.lzwState = lzwState;
  895. DecodeStream.call(this, maybeLength);
  896. }
  897. LZWStream.prototype = Object.create(DecodeStream.prototype);
  898. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  899. var bitsCached = this.bitsCached;
  900. var cachedData = this.cachedData;
  901. while (bitsCached < n) {
  902. var c = this.str.getByte();
  903. if (c === -1) {
  904. this.eof = true;
  905. return null;
  906. }
  907. cachedData = cachedData << 8 | c;
  908. bitsCached += 8;
  909. }
  910. this.bitsCached = bitsCached -= n;
  911. this.cachedData = cachedData;
  912. this.lastCode = null;
  913. return cachedData >>> bitsCached & (1 << n) - 1;
  914. };
  915. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  916. var blockSize = 512;
  917. var estimatedDecodedSize = blockSize * 2,
  918. decodedSizeDelta = blockSize;
  919. var i, j, q;
  920. var lzwState = this.lzwState;
  921. if (!lzwState) {
  922. return;
  923. }
  924. var earlyChange = lzwState.earlyChange;
  925. var nextCode = lzwState.nextCode;
  926. var dictionaryValues = lzwState.dictionaryValues;
  927. var dictionaryLengths = lzwState.dictionaryLengths;
  928. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  929. var codeLength = lzwState.codeLength;
  930. var prevCode = lzwState.prevCode;
  931. var currentSequence = lzwState.currentSequence;
  932. var currentSequenceLength = lzwState.currentSequenceLength;
  933. var decodedLength = 0;
  934. var currentBufferLength = this.bufferLength;
  935. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  936. for (i = 0; i < blockSize; i++) {
  937. var code = this.readBits(codeLength);
  938. var hasPrev = currentSequenceLength > 0;
  939. if (code < 256) {
  940. currentSequence[0] = code;
  941. currentSequenceLength = 1;
  942. } else if (code >= 258) {
  943. if (code < nextCode) {
  944. currentSequenceLength = dictionaryLengths[code];
  945. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  946. currentSequence[j] = dictionaryValues[q];
  947. q = dictionaryPrevCodes[q];
  948. }
  949. } else {
  950. currentSequence[currentSequenceLength++] = currentSequence[0];
  951. }
  952. } else if (code === 256) {
  953. codeLength = 9;
  954. nextCode = 258;
  955. currentSequenceLength = 0;
  956. continue;
  957. } else {
  958. this.eof = true;
  959. delete this.lzwState;
  960. break;
  961. }
  962. if (hasPrev) {
  963. dictionaryPrevCodes[nextCode] = prevCode;
  964. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  965. dictionaryValues[nextCode] = currentSequence[0];
  966. nextCode++;
  967. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  968. }
  969. prevCode = code;
  970. decodedLength += currentSequenceLength;
  971. if (estimatedDecodedSize < decodedLength) {
  972. do {
  973. estimatedDecodedSize += decodedSizeDelta;
  974. } while (estimatedDecodedSize < decodedLength);
  975. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  976. }
  977. for (j = 0; j < currentSequenceLength; j++) {
  978. buffer[currentBufferLength++] = currentSequence[j];
  979. }
  980. }
  981. lzwState.nextCode = nextCode;
  982. lzwState.codeLength = codeLength;
  983. lzwState.prevCode = prevCode;
  984. lzwState.currentSequenceLength = currentSequenceLength;
  985. this.bufferLength = currentBufferLength;
  986. };
  987. return LZWStream;
  988. }();
  989. var NullStream = function NullStreamClosure() {
  990. function NullStream() {
  991. Stream.call(this, new Uint8Array(0));
  992. }
  993. NullStream.prototype = Stream.prototype;
  994. return NullStream;
  995. }();
  996. exports.Ascii85Stream = Ascii85Stream;
  997. exports.AsciiHexStream = AsciiHexStream;
  998. exports.DecryptStream = DecryptStream;
  999. exports.DecodeStream = DecodeStream;
  1000. exports.FlateStream = FlateStream;
  1001. exports.NullStream = NullStream;
  1002. exports.PredictorStream = PredictorStream;
  1003. exports.RunLengthStream = RunLengthStream;
  1004. exports.Stream = Stream;
  1005. exports.StreamsSequenceStream = StreamsSequenceStream;
  1006. exports.StringStream = StringStream;
  1007. exports.LZWStream = LZWStream;