chunked_stream.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2018 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.ChunkedStreamManager = exports.ChunkedStream = void 0;
  27. var _util = require("../shared/util");
  28. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  29. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  30. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  31. var ChunkedStream =
  32. /*#__PURE__*/
  33. function () {
  34. function ChunkedStream(length, chunkSize, manager) {
  35. _classCallCheck(this, ChunkedStream);
  36. this.bytes = new Uint8Array(length);
  37. this.start = 0;
  38. this.pos = 0;
  39. this.end = length;
  40. this.chunkSize = chunkSize;
  41. this.loadedChunks = [];
  42. this.numChunksLoaded = 0;
  43. this.numChunks = Math.ceil(length / chunkSize);
  44. this.manager = manager;
  45. this.progressiveDataLength = 0;
  46. this.lastSuccessfulEnsureByteChunk = -1;
  47. }
  48. _createClass(ChunkedStream, [{
  49. key: "getMissingChunks",
  50. value: function getMissingChunks() {
  51. var chunks = [];
  52. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  53. if (!this.loadedChunks[chunk]) {
  54. chunks.push(chunk);
  55. }
  56. }
  57. return chunks;
  58. }
  59. }, {
  60. key: "getBaseStreams",
  61. value: function getBaseStreams() {
  62. return [this];
  63. }
  64. }, {
  65. key: "allChunksLoaded",
  66. value: function allChunksLoaded() {
  67. return this.numChunksLoaded === this.numChunks;
  68. }
  69. }, {
  70. key: "onReceiveData",
  71. value: function onReceiveData(begin, chunk) {
  72. var chunkSize = this.chunkSize;
  73. if (begin % chunkSize !== 0) {
  74. throw new Error("Bad begin offset: ".concat(begin));
  75. }
  76. var end = begin + chunk.byteLength;
  77. if (end % chunkSize !== 0 && end !== this.bytes.length) {
  78. throw new Error("Bad end offset: ".concat(end));
  79. }
  80. this.bytes.set(new Uint8Array(chunk), begin);
  81. var beginChunk = Math.floor(begin / chunkSize);
  82. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  83. for (var curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  84. if (!this.loadedChunks[curChunk]) {
  85. this.loadedChunks[curChunk] = true;
  86. ++this.numChunksLoaded;
  87. }
  88. }
  89. }
  90. }, {
  91. key: "onReceiveProgressiveData",
  92. value: function onReceiveProgressiveData(data) {
  93. var position = this.progressiveDataLength;
  94. var beginChunk = Math.floor(position / this.chunkSize);
  95. this.bytes.set(new Uint8Array(data), position);
  96. position += data.byteLength;
  97. this.progressiveDataLength = position;
  98. var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  99. for (var curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  100. if (!this.loadedChunks[curChunk]) {
  101. this.loadedChunks[curChunk] = true;
  102. ++this.numChunksLoaded;
  103. }
  104. }
  105. }
  106. }, {
  107. key: "ensureByte",
  108. value: function ensureByte(pos) {
  109. var chunk = Math.floor(pos / this.chunkSize);
  110. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  111. return;
  112. }
  113. if (!this.loadedChunks[chunk]) {
  114. throw new _util.MissingDataException(pos, pos + 1);
  115. }
  116. this.lastSuccessfulEnsureByteChunk = chunk;
  117. }
  118. }, {
  119. key: "ensureRange",
  120. value: function ensureRange(begin, end) {
  121. if (begin >= end) {
  122. return;
  123. }
  124. if (end <= this.progressiveDataLength) {
  125. return;
  126. }
  127. var chunkSize = this.chunkSize;
  128. var beginChunk = Math.floor(begin / chunkSize);
  129. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  130. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  131. if (!this.loadedChunks[chunk]) {
  132. throw new _util.MissingDataException(begin, end);
  133. }
  134. }
  135. }
  136. }, {
  137. key: "nextEmptyChunk",
  138. value: function nextEmptyChunk(beginChunk) {
  139. var numChunks = this.numChunks;
  140. for (var i = 0; i < numChunks; ++i) {
  141. var chunk = (beginChunk + i) % numChunks;
  142. if (!this.loadedChunks[chunk]) {
  143. return chunk;
  144. }
  145. }
  146. return null;
  147. }
  148. }, {
  149. key: "hasChunk",
  150. value: function hasChunk(chunk) {
  151. return !!this.loadedChunks[chunk];
  152. }
  153. }, {
  154. key: "getByte",
  155. value: function getByte() {
  156. var pos = this.pos;
  157. if (pos >= this.end) {
  158. return -1;
  159. }
  160. this.ensureByte(pos);
  161. return this.bytes[this.pos++];
  162. }
  163. }, {
  164. key: "getUint16",
  165. value: function getUint16() {
  166. var b0 = this.getByte();
  167. var b1 = this.getByte();
  168. if (b0 === -1 || b1 === -1) {
  169. return -1;
  170. }
  171. return (b0 << 8) + b1;
  172. }
  173. }, {
  174. key: "getInt32",
  175. value: function getInt32() {
  176. var b0 = this.getByte();
  177. var b1 = this.getByte();
  178. var b2 = this.getByte();
  179. var b3 = this.getByte();
  180. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  181. }
  182. }, {
  183. key: "getBytes",
  184. value: function getBytes(length) {
  185. var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  186. var bytes = this.bytes;
  187. var pos = this.pos;
  188. var strEnd = this.end;
  189. if (!length) {
  190. this.ensureRange(pos, strEnd);
  191. var _subarray = bytes.subarray(pos, strEnd);
  192. return forceClamped ? new Uint8ClampedArray(_subarray) : _subarray;
  193. }
  194. var end = pos + length;
  195. if (end > strEnd) {
  196. end = strEnd;
  197. }
  198. this.ensureRange(pos, end);
  199. this.pos = end;
  200. var subarray = bytes.subarray(pos, end);
  201. return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
  202. }
  203. }, {
  204. key: "peekByte",
  205. value: function peekByte() {
  206. var peekedByte = this.getByte();
  207. this.pos--;
  208. return peekedByte;
  209. }
  210. }, {
  211. key: "peekBytes",
  212. value: function peekBytes(length) {
  213. var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  214. var bytes = this.getBytes(length, forceClamped);
  215. this.pos -= bytes.length;
  216. return bytes;
  217. }
  218. }, {
  219. key: "getByteRange",
  220. value: function getByteRange(begin, end) {
  221. this.ensureRange(begin, end);
  222. return this.bytes.subarray(begin, end);
  223. }
  224. }, {
  225. key: "skip",
  226. value: function skip(n) {
  227. if (!n) {
  228. n = 1;
  229. }
  230. this.pos += n;
  231. }
  232. }, {
  233. key: "reset",
  234. value: function reset() {
  235. this.pos = this.start;
  236. }
  237. }, {
  238. key: "moveStart",
  239. value: function moveStart() {
  240. this.start = this.pos;
  241. }
  242. }, {
  243. key: "makeSubStream",
  244. value: function makeSubStream(start, length, dict) {
  245. this.ensureRange(start, start + length);
  246. function ChunkedStreamSubstream() {}
  247. ChunkedStreamSubstream.prototype = Object.create(this);
  248. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  249. var chunkSize = this.chunkSize;
  250. var beginChunk = Math.floor(this.start / chunkSize);
  251. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  252. var missingChunks = [];
  253. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  254. if (!this.loadedChunks[chunk]) {
  255. missingChunks.push(chunk);
  256. }
  257. }
  258. return missingChunks;
  259. };
  260. var subStream = new ChunkedStreamSubstream();
  261. subStream.pos = subStream.start = start;
  262. subStream.end = start + length || this.end;
  263. subStream.dict = dict;
  264. return subStream;
  265. }
  266. }, {
  267. key: "length",
  268. get: function get() {
  269. return this.end - this.start;
  270. }
  271. }, {
  272. key: "isEmpty",
  273. get: function get() {
  274. return this.length === 0;
  275. }
  276. }]);
  277. return ChunkedStream;
  278. }();
  279. exports.ChunkedStream = ChunkedStream;
  280. var ChunkedStreamManager =
  281. /*#__PURE__*/
  282. function () {
  283. function ChunkedStreamManager(pdfNetworkStream, args) {
  284. _classCallCheck(this, ChunkedStreamManager);
  285. this.length = args.length;
  286. this.chunkSize = args.rangeChunkSize;
  287. this.stream = new ChunkedStream(this.length, this.chunkSize, this);
  288. this.pdfNetworkStream = pdfNetworkStream;
  289. this.disableAutoFetch = args.disableAutoFetch;
  290. this.msgHandler = args.msgHandler;
  291. this.currRequestId = 0;
  292. this.chunksNeededByRequest = Object.create(null);
  293. this.requestsByChunk = Object.create(null);
  294. this.promisesByRequest = Object.create(null);
  295. this.progressiveDataLength = 0;
  296. this.aborted = false;
  297. this._loadedStreamCapability = (0, _util.createPromiseCapability)();
  298. }
  299. _createClass(ChunkedStreamManager, [{
  300. key: "onLoadedStream",
  301. value: function onLoadedStream() {
  302. return this._loadedStreamCapability.promise;
  303. }
  304. }, {
  305. key: "sendRequest",
  306. value: function sendRequest(begin, end) {
  307. var _this = this;
  308. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  309. if (!rangeReader.isStreamingSupported) {
  310. rangeReader.onProgress = this.onProgress.bind(this);
  311. }
  312. var chunks = [],
  313. loaded = 0;
  314. var promise = new Promise(function (resolve, reject) {
  315. var readChunk = function readChunk(chunk) {
  316. try {
  317. if (!chunk.done) {
  318. var data = chunk.value;
  319. chunks.push(data);
  320. loaded += (0, _util.arrayByteLength)(data);
  321. if (rangeReader.isStreamingSupported) {
  322. _this.onProgress({
  323. loaded: loaded
  324. });
  325. }
  326. rangeReader.read().then(readChunk, reject);
  327. return;
  328. }
  329. var chunkData = (0, _util.arraysToBytes)(chunks);
  330. chunks = null;
  331. resolve(chunkData);
  332. } catch (e) {
  333. reject(e);
  334. }
  335. };
  336. rangeReader.read().then(readChunk, reject);
  337. });
  338. promise.then(function (data) {
  339. if (_this.aborted) {
  340. return;
  341. }
  342. _this.onReceiveData({
  343. chunk: data,
  344. begin: begin
  345. });
  346. });
  347. }
  348. }, {
  349. key: "requestAllChunks",
  350. value: function requestAllChunks() {
  351. var missingChunks = this.stream.getMissingChunks();
  352. this._requestChunks(missingChunks);
  353. return this._loadedStreamCapability.promise;
  354. }
  355. }, {
  356. key: "_requestChunks",
  357. value: function _requestChunks(chunks) {
  358. var requestId = this.currRequestId++;
  359. var chunksNeeded = Object.create(null);
  360. this.chunksNeededByRequest[requestId] = chunksNeeded;
  361. var _iteratorNormalCompletion = true;
  362. var _didIteratorError = false;
  363. var _iteratorError = undefined;
  364. try {
  365. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  366. var _chunk = _step.value;
  367. if (!this.stream.hasChunk(_chunk)) {
  368. chunksNeeded[_chunk] = true;
  369. }
  370. }
  371. } catch (err) {
  372. _didIteratorError = true;
  373. _iteratorError = err;
  374. } finally {
  375. try {
  376. if (!_iteratorNormalCompletion && _iterator.return != null) {
  377. _iterator.return();
  378. }
  379. } finally {
  380. if (_didIteratorError) {
  381. throw _iteratorError;
  382. }
  383. }
  384. }
  385. if ((0, _util.isEmptyObj)(chunksNeeded)) {
  386. return Promise.resolve();
  387. }
  388. var capability = (0, _util.createPromiseCapability)();
  389. this.promisesByRequest[requestId] = capability;
  390. var chunksToRequest = [];
  391. for (var chunk in chunksNeeded) {
  392. chunk = chunk | 0;
  393. if (!(chunk in this.requestsByChunk)) {
  394. this.requestsByChunk[chunk] = [];
  395. chunksToRequest.push(chunk);
  396. }
  397. this.requestsByChunk[chunk].push(requestId);
  398. }
  399. if (!chunksToRequest.length) {
  400. return capability.promise;
  401. }
  402. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  403. var _iteratorNormalCompletion2 = true;
  404. var _didIteratorError2 = false;
  405. var _iteratorError2 = undefined;
  406. try {
  407. for (var _iterator2 = groupedChunksToRequest[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  408. var groupedChunk = _step2.value;
  409. var begin = groupedChunk.beginChunk * this.chunkSize;
  410. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  411. this.sendRequest(begin, end);
  412. }
  413. } catch (err) {
  414. _didIteratorError2 = true;
  415. _iteratorError2 = err;
  416. } finally {
  417. try {
  418. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  419. _iterator2.return();
  420. }
  421. } finally {
  422. if (_didIteratorError2) {
  423. throw _iteratorError2;
  424. }
  425. }
  426. }
  427. return capability.promise;
  428. }
  429. }, {
  430. key: "getStream",
  431. value: function getStream() {
  432. return this.stream;
  433. }
  434. }, {
  435. key: "requestRange",
  436. value: function requestRange(begin, end) {
  437. end = Math.min(end, this.length);
  438. var beginChunk = this.getBeginChunk(begin);
  439. var endChunk = this.getEndChunk(end);
  440. var chunks = [];
  441. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  442. chunks.push(chunk);
  443. }
  444. return this._requestChunks(chunks);
  445. }
  446. }, {
  447. key: "requestRanges",
  448. value: function requestRanges() {
  449. var ranges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  450. var chunksToRequest = [];
  451. var _iteratorNormalCompletion3 = true;
  452. var _didIteratorError3 = false;
  453. var _iteratorError3 = undefined;
  454. try {
  455. for (var _iterator3 = ranges[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  456. var range = _step3.value;
  457. var beginChunk = this.getBeginChunk(range.begin);
  458. var endChunk = this.getEndChunk(range.end);
  459. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  460. if (!chunksToRequest.includes(chunk)) {
  461. chunksToRequest.push(chunk);
  462. }
  463. }
  464. }
  465. } catch (err) {
  466. _didIteratorError3 = true;
  467. _iteratorError3 = err;
  468. } finally {
  469. try {
  470. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  471. _iterator3.return();
  472. }
  473. } finally {
  474. if (_didIteratorError3) {
  475. throw _iteratorError3;
  476. }
  477. }
  478. }
  479. chunksToRequest.sort(function (a, b) {
  480. return a - b;
  481. });
  482. return this._requestChunks(chunksToRequest);
  483. }
  484. }, {
  485. key: "groupChunks",
  486. value: function groupChunks(chunks) {
  487. var groupedChunks = [];
  488. var beginChunk = -1;
  489. var prevChunk = -1;
  490. for (var i = 0, ii = chunks.length; i < ii; ++i) {
  491. var chunk = chunks[i];
  492. if (beginChunk < 0) {
  493. beginChunk = chunk;
  494. }
  495. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  496. groupedChunks.push({
  497. beginChunk: beginChunk,
  498. endChunk: prevChunk + 1
  499. });
  500. beginChunk = chunk;
  501. }
  502. if (i + 1 === chunks.length) {
  503. groupedChunks.push({
  504. beginChunk: beginChunk,
  505. endChunk: chunk + 1
  506. });
  507. }
  508. prevChunk = chunk;
  509. }
  510. return groupedChunks;
  511. }
  512. }, {
  513. key: "onProgress",
  514. value: function onProgress(args) {
  515. this.msgHandler.send('DocProgress', {
  516. loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
  517. total: this.length
  518. });
  519. }
  520. }, {
  521. key: "onReceiveData",
  522. value: function onReceiveData(args) {
  523. var chunk = args.chunk;
  524. var isProgressive = args.begin === undefined;
  525. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  526. var end = begin + chunk.byteLength;
  527. var beginChunk = Math.floor(begin / this.chunkSize);
  528. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  529. if (isProgressive) {
  530. this.stream.onReceiveProgressiveData(chunk);
  531. this.progressiveDataLength = end;
  532. } else {
  533. this.stream.onReceiveData(begin, chunk);
  534. }
  535. if (this.stream.allChunksLoaded()) {
  536. this._loadedStreamCapability.resolve(this.stream);
  537. }
  538. var loadedRequests = [];
  539. for (var _chunk2 = beginChunk; _chunk2 < endChunk; ++_chunk2) {
  540. var requestIds = this.requestsByChunk[_chunk2] || [];
  541. delete this.requestsByChunk[_chunk2];
  542. var _iteratorNormalCompletion4 = true;
  543. var _didIteratorError4 = false;
  544. var _iteratorError4 = undefined;
  545. try {
  546. for (var _iterator4 = requestIds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  547. var requestId = _step4.value;
  548. var chunksNeeded = this.chunksNeededByRequest[requestId];
  549. if (_chunk2 in chunksNeeded) {
  550. delete chunksNeeded[_chunk2];
  551. }
  552. if (!(0, _util.isEmptyObj)(chunksNeeded)) {
  553. continue;
  554. }
  555. loadedRequests.push(requestId);
  556. }
  557. } catch (err) {
  558. _didIteratorError4 = true;
  559. _iteratorError4 = err;
  560. } finally {
  561. try {
  562. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  563. _iterator4.return();
  564. }
  565. } finally {
  566. if (_didIteratorError4) {
  567. throw _iteratorError4;
  568. }
  569. }
  570. }
  571. }
  572. if (!this.disableAutoFetch && (0, _util.isEmptyObj)(this.requestsByChunk)) {
  573. var nextEmptyChunk;
  574. if (this.stream.numChunksLoaded === 1) {
  575. var lastChunk = this.stream.numChunks - 1;
  576. if (!this.stream.hasChunk(lastChunk)) {
  577. nextEmptyChunk = lastChunk;
  578. }
  579. } else {
  580. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  581. }
  582. if (Number.isInteger(nextEmptyChunk)) {
  583. this._requestChunks([nextEmptyChunk]);
  584. }
  585. }
  586. for (var _i = 0; _i < loadedRequests.length; _i++) {
  587. var _requestId = loadedRequests[_i];
  588. var capability = this.promisesByRequest[_requestId];
  589. delete this.promisesByRequest[_requestId];
  590. capability.resolve();
  591. }
  592. this.msgHandler.send('DocProgress', {
  593. loaded: this.stream.numChunksLoaded * this.chunkSize,
  594. total: this.length
  595. });
  596. }
  597. }, {
  598. key: "onError",
  599. value: function onError(err) {
  600. this._loadedStreamCapability.reject(err);
  601. }
  602. }, {
  603. key: "getBeginChunk",
  604. value: function getBeginChunk(begin) {
  605. return Math.floor(begin / this.chunkSize);
  606. }
  607. }, {
  608. key: "getEndChunk",
  609. value: function getEndChunk(end) {
  610. return Math.floor((end - 1) / this.chunkSize) + 1;
  611. }
  612. }, {
  613. key: "abort",
  614. value: function abort() {
  615. this.aborted = true;
  616. if (this.pdfNetworkStream) {
  617. this.pdfNetworkStream.cancelAllRequests('abort');
  618. }
  619. for (var requestId in this.promisesByRequest) {
  620. this.promisesByRequest[requestId].reject(new Error('Request was aborted'));
  621. }
  622. }
  623. }]);
  624. return ChunkedStreamManager;
  625. }();
  626. exports.ChunkedStreamManager = ChunkedStreamManager;