pdfjs-dist 2.2.228 → 2.6.347
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8816 -19300
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +1144 -927
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +289 -233
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +220 -58
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -26,318 +26,308 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.ChunkedStreamManager = exports.ChunkedStream = void 0;
|
28
28
|
|
29
|
-
var _util = require("../shared/util");
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var _core_utils = require("./core_utils");
|
32
|
-
|
33
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
34
|
-
|
35
|
-
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); } }
|
36
|
-
|
37
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
38
|
-
|
39
|
-
var ChunkedStream =
|
40
|
-
/*#__PURE__*/
|
41
|
-
function () {
|
42
|
-
function ChunkedStream(length, chunkSize, manager) {
|
43
|
-
_classCallCheck(this, ChunkedStream);
|
31
|
+
var _core_utils = require("./core_utils.js");
|
44
32
|
|
33
|
+
class ChunkedStream {
|
34
|
+
constructor(length, chunkSize, manager) {
|
45
35
|
this.bytes = new Uint8Array(length);
|
46
36
|
this.start = 0;
|
47
37
|
this.pos = 0;
|
48
38
|
this.end = length;
|
49
39
|
this.chunkSize = chunkSize;
|
50
|
-
this.
|
51
|
-
this.numChunksLoaded = 0;
|
40
|
+
this._loadedChunks = new Set();
|
52
41
|
this.numChunks = Math.ceil(length / chunkSize);
|
53
42
|
this.manager = manager;
|
54
43
|
this.progressiveDataLength = 0;
|
55
44
|
this.lastSuccessfulEnsureByteChunk = -1;
|
56
45
|
}
|
57
46
|
|
58
|
-
|
59
|
-
|
60
|
-
value: function getMissingChunks() {
|
61
|
-
var chunks = [];
|
47
|
+
getMissingChunks() {
|
48
|
+
const chunks = [];
|
62
49
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}
|
50
|
+
for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
|
51
|
+
if (!this._loadedChunks.has(chunk)) {
|
52
|
+
chunks.push(chunk);
|
67
53
|
}
|
68
|
-
|
69
|
-
return chunks;
|
70
54
|
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
55
|
+
|
56
|
+
return chunks;
|
57
|
+
}
|
58
|
+
|
59
|
+
getBaseStreams() {
|
60
|
+
return [this];
|
61
|
+
}
|
62
|
+
|
63
|
+
get numChunksLoaded() {
|
64
|
+
return this._loadedChunks.size;
|
65
|
+
}
|
66
|
+
|
67
|
+
allChunksLoaded() {
|
68
|
+
return this.numChunksLoaded === this.numChunks;
|
69
|
+
}
|
70
|
+
|
71
|
+
onReceiveData(begin, chunk) {
|
72
|
+
const chunkSize = this.chunkSize;
|
73
|
+
|
74
|
+
if (begin % chunkSize !== 0) {
|
75
|
+
throw new Error(`Bad begin offset: ${begin}`);
|
75
76
|
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
|
78
|
+
const end = begin + chunk.byteLength;
|
79
|
+
|
80
|
+
if (end % chunkSize !== 0 && end !== this.bytes.length) {
|
81
|
+
throw new Error(`Bad end offset: ${end}`);
|
80
82
|
}
|
81
|
-
}, {
|
82
|
-
key: "onReceiveData",
|
83
|
-
value: function onReceiveData(begin, chunk) {
|
84
|
-
var chunkSize = this.chunkSize;
|
85
83
|
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
this.bytes.set(new Uint8Array(chunk), begin);
|
85
|
+
const beginChunk = Math.floor(begin / chunkSize);
|
86
|
+
const endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
89
87
|
|
90
|
-
|
88
|
+
for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
89
|
+
this._loadedChunks.add(curChunk);
|
90
|
+
}
|
91
|
+
}
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
onReceiveProgressiveData(data) {
|
94
|
+
let position = this.progressiveDataLength;
|
95
|
+
const beginChunk = Math.floor(position / this.chunkSize);
|
96
|
+
this.bytes.set(new Uint8Array(data), position);
|
97
|
+
position += data.byteLength;
|
98
|
+
this.progressiveDataLength = position;
|
99
|
+
const endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
|
95
100
|
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
102
|
+
this._loadedChunks.add(curChunk);
|
103
|
+
}
|
104
|
+
}
|
99
105
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
++this.numChunksLoaded;
|
104
|
-
}
|
105
|
-
}
|
106
|
+
ensureByte(pos) {
|
107
|
+
if (pos < this.progressiveDataLength) {
|
108
|
+
return;
|
106
109
|
}
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
this.bytes.set(new Uint8Array(data), position);
|
113
|
-
position += data.byteLength;
|
114
|
-
this.progressiveDataLength = position;
|
115
|
-
var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
|
116
|
-
|
117
|
-
for (var curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
118
|
-
if (!this.loadedChunks[curChunk]) {
|
119
|
-
this.loadedChunks[curChunk] = true;
|
120
|
-
++this.numChunksLoaded;
|
121
|
-
}
|
122
|
-
}
|
110
|
+
|
111
|
+
const chunk = Math.floor(pos / this.chunkSize);
|
112
|
+
|
113
|
+
if (chunk === this.lastSuccessfulEnsureByteChunk) {
|
114
|
+
return;
|
123
115
|
}
|
124
|
-
}, {
|
125
|
-
key: "ensureByte",
|
126
|
-
value: function ensureByte(pos) {
|
127
|
-
if (pos < this.progressiveDataLength) {
|
128
|
-
return;
|
129
|
-
}
|
130
116
|
|
131
|
-
|
117
|
+
if (!this._loadedChunks.has(chunk)) {
|
118
|
+
throw new _core_utils.MissingDataException(pos, pos + 1);
|
119
|
+
}
|
132
120
|
|
133
|
-
|
134
|
-
|
135
|
-
}
|
121
|
+
this.lastSuccessfulEnsureByteChunk = chunk;
|
122
|
+
}
|
136
123
|
|
137
|
-
|
138
|
-
|
139
|
-
|
124
|
+
ensureRange(begin, end) {
|
125
|
+
if (begin >= end) {
|
126
|
+
return;
|
127
|
+
}
|
140
128
|
|
141
|
-
|
129
|
+
if (end <= this.progressiveDataLength) {
|
130
|
+
return;
|
142
131
|
}
|
143
|
-
}, {
|
144
|
-
key: "ensureRange",
|
145
|
-
value: function ensureRange(begin, end) {
|
146
|
-
if (begin >= end) {
|
147
|
-
return;
|
148
|
-
}
|
149
132
|
|
150
|
-
|
151
|
-
|
133
|
+
const chunkSize = this.chunkSize;
|
134
|
+
const beginChunk = Math.floor(begin / chunkSize);
|
135
|
+
const endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
136
|
+
|
137
|
+
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
|
138
|
+
if (!this._loadedChunks.has(chunk)) {
|
139
|
+
throw new _core_utils.MissingDataException(begin, end);
|
152
140
|
}
|
141
|
+
}
|
142
|
+
}
|
153
143
|
|
154
|
-
|
155
|
-
|
156
|
-
var endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
144
|
+
nextEmptyChunk(beginChunk) {
|
145
|
+
const numChunks = this.numChunks;
|
157
146
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
147
|
+
for (let i = 0; i < numChunks; ++i) {
|
148
|
+
const chunk = (beginChunk + i) % numChunks;
|
149
|
+
|
150
|
+
if (!this._loadedChunks.has(chunk)) {
|
151
|
+
return chunk;
|
162
152
|
}
|
163
153
|
}
|
164
|
-
}, {
|
165
|
-
key: "nextEmptyChunk",
|
166
|
-
value: function nextEmptyChunk(beginChunk) {
|
167
|
-
var numChunks = this.numChunks;
|
168
154
|
|
169
|
-
|
170
|
-
|
155
|
+
return null;
|
156
|
+
}
|
171
157
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
158
|
+
hasChunk(chunk) {
|
159
|
+
return this._loadedChunks.has(chunk);
|
160
|
+
}
|
161
|
+
|
162
|
+
get length() {
|
163
|
+
return this.end - this.start;
|
164
|
+
}
|
165
|
+
|
166
|
+
get isEmpty() {
|
167
|
+
return this.length === 0;
|
168
|
+
}
|
169
|
+
|
170
|
+
getByte() {
|
171
|
+
const pos = this.pos;
|
176
172
|
|
177
|
-
|
173
|
+
if (pos >= this.end) {
|
174
|
+
return -1;
|
178
175
|
}
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
return !!this.loadedChunks[chunk];
|
176
|
+
|
177
|
+
if (pos >= this.progressiveDataLength) {
|
178
|
+
this.ensureByte(pos);
|
183
179
|
}
|
184
|
-
}, {
|
185
|
-
key: "getByte",
|
186
|
-
value: function getByte() {
|
187
|
-
var pos = this.pos;
|
188
180
|
|
189
|
-
|
190
|
-
|
191
|
-
}
|
181
|
+
return this.bytes[this.pos++];
|
182
|
+
}
|
192
183
|
|
193
|
-
|
194
|
-
|
184
|
+
getUint16() {
|
185
|
+
const b0 = this.getByte();
|
186
|
+
const b1 = this.getByte();
|
187
|
+
|
188
|
+
if (b0 === -1 || b1 === -1) {
|
189
|
+
return -1;
|
195
190
|
}
|
196
|
-
}, {
|
197
|
-
key: "getUint16",
|
198
|
-
value: function getUint16() {
|
199
|
-
var b0 = this.getByte();
|
200
|
-
var b1 = this.getByte();
|
201
191
|
|
202
|
-
|
203
|
-
|
204
|
-
}
|
192
|
+
return (b0 << 8) + b1;
|
193
|
+
}
|
205
194
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
var b2 = this.getByte();
|
214
|
-
var b3 = this.getByte();
|
215
|
-
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
|
216
|
-
}
|
217
|
-
}, {
|
218
|
-
key: "getBytes",
|
219
|
-
value: function getBytes(length) {
|
220
|
-
var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
221
|
-
var bytes = this.bytes;
|
222
|
-
var pos = this.pos;
|
223
|
-
var strEnd = this.end;
|
224
|
-
|
225
|
-
if (!length) {
|
226
|
-
this.ensureRange(pos, strEnd);
|
195
|
+
getInt32() {
|
196
|
+
const b0 = this.getByte();
|
197
|
+
const b1 = this.getByte();
|
198
|
+
const b2 = this.getByte();
|
199
|
+
const b3 = this.getByte();
|
200
|
+
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
|
201
|
+
}
|
227
202
|
|
228
|
-
|
203
|
+
getBytes(length, forceClamped = false) {
|
204
|
+
const bytes = this.bytes;
|
205
|
+
const pos = this.pos;
|
206
|
+
const strEnd = this.end;
|
229
207
|
|
230
|
-
|
208
|
+
if (!length) {
|
209
|
+
if (strEnd > this.progressiveDataLength) {
|
210
|
+
this.ensureRange(pos, strEnd);
|
231
211
|
}
|
232
212
|
|
233
|
-
|
213
|
+
const subarray = bytes.subarray(pos, strEnd);
|
214
|
+
return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
|
215
|
+
}
|
234
216
|
|
235
|
-
|
236
|
-
end = strEnd;
|
237
|
-
}
|
217
|
+
let end = pos + length;
|
238
218
|
|
219
|
+
if (end > strEnd) {
|
220
|
+
end = strEnd;
|
221
|
+
}
|
222
|
+
|
223
|
+
if (end > this.progressiveDataLength) {
|
239
224
|
this.ensureRange(pos, end);
|
240
|
-
this.pos = end;
|
241
|
-
var subarray = bytes.subarray(pos, end);
|
242
|
-
return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
|
243
225
|
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
226
|
+
|
227
|
+
this.pos = end;
|
228
|
+
const subarray = bytes.subarray(pos, end);
|
229
|
+
return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
|
230
|
+
}
|
231
|
+
|
232
|
+
peekByte() {
|
233
|
+
const peekedByte = this.getByte();
|
234
|
+
|
235
|
+
if (peekedByte !== -1) {
|
248
236
|
this.pos--;
|
249
|
-
return peekedByte;
|
250
|
-
}
|
251
|
-
}, {
|
252
|
-
key: "peekBytes",
|
253
|
-
value: function peekBytes(length) {
|
254
|
-
var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
255
|
-
var bytes = this.getBytes(length, forceClamped);
|
256
|
-
this.pos -= bytes.length;
|
257
|
-
return bytes;
|
258
|
-
}
|
259
|
-
}, {
|
260
|
-
key: "getByteRange",
|
261
|
-
value: function getByteRange(begin, end) {
|
262
|
-
this.ensureRange(begin, end);
|
263
|
-
return this.bytes.subarray(begin, end);
|
264
237
|
}
|
265
|
-
}, {
|
266
|
-
key: "skip",
|
267
|
-
value: function skip(n) {
|
268
|
-
if (!n) {
|
269
|
-
n = 1;
|
270
|
-
}
|
271
238
|
|
272
|
-
|
239
|
+
return peekedByte;
|
240
|
+
}
|
241
|
+
|
242
|
+
peekBytes(length, forceClamped = false) {
|
243
|
+
const bytes = this.getBytes(length, forceClamped);
|
244
|
+
this.pos -= bytes.length;
|
245
|
+
return bytes;
|
246
|
+
}
|
247
|
+
|
248
|
+
getByteRange(begin, end) {
|
249
|
+
if (begin < 0) {
|
250
|
+
begin = 0;
|
251
|
+
}
|
252
|
+
|
253
|
+
if (end > this.end) {
|
254
|
+
end = this.end;
|
273
255
|
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
this.pos = this.start;
|
256
|
+
|
257
|
+
if (end > this.progressiveDataLength) {
|
258
|
+
this.ensureRange(begin, end);
|
278
259
|
}
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
260
|
+
|
261
|
+
return this.bytes.subarray(begin, end);
|
262
|
+
}
|
263
|
+
|
264
|
+
skip(n) {
|
265
|
+
if (!n) {
|
266
|
+
n = 1;
|
283
267
|
}
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
268
|
+
|
269
|
+
this.pos += n;
|
270
|
+
}
|
271
|
+
|
272
|
+
reset() {
|
273
|
+
this.pos = this.start;
|
274
|
+
}
|
275
|
+
|
276
|
+
moveStart() {
|
277
|
+
this.start = this.pos;
|
278
|
+
}
|
279
|
+
|
280
|
+
makeSubStream(start, length, dict) {
|
281
|
+
if (length) {
|
282
|
+
if (start + length > this.progressiveDataLength) {
|
288
283
|
this.ensureRange(start, start + length);
|
289
|
-
}
|
284
|
+
}
|
285
|
+
} else {
|
286
|
+
if (start >= this.progressiveDataLength) {
|
290
287
|
this.ensureByte(start);
|
291
288
|
}
|
289
|
+
}
|
292
290
|
|
293
|
-
|
291
|
+
function ChunkedStreamSubstream() {}
|
294
292
|
|
295
|
-
|
293
|
+
ChunkedStreamSubstream.prototype = Object.create(this);
|
296
294
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
295
|
+
ChunkedStreamSubstream.prototype.getMissingChunks = function () {
|
296
|
+
const chunkSize = this.chunkSize;
|
297
|
+
const beginChunk = Math.floor(this.start / chunkSize);
|
298
|
+
const endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
|
299
|
+
const missingChunks = [];
|
302
300
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
}
|
301
|
+
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
|
302
|
+
if (!this._loadedChunks.has(chunk)) {
|
303
|
+
missingChunks.push(chunk);
|
307
304
|
}
|
305
|
+
}
|
308
306
|
|
309
|
-
|
310
|
-
|
307
|
+
return missingChunks;
|
308
|
+
};
|
311
309
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
return subStream;
|
317
|
-
}
|
318
|
-
}, {
|
319
|
-
key: "length",
|
320
|
-
get: function get() {
|
321
|
-
return this.end - this.start;
|
322
|
-
}
|
323
|
-
}, {
|
324
|
-
key: "isEmpty",
|
325
|
-
get: function get() {
|
326
|
-
return this.length === 0;
|
327
|
-
}
|
328
|
-
}]);
|
310
|
+
ChunkedStreamSubstream.prototype.allChunksLoaded = function () {
|
311
|
+
if (this.numChunksLoaded === this.numChunks) {
|
312
|
+
return true;
|
313
|
+
}
|
329
314
|
|
330
|
-
|
331
|
-
}
|
315
|
+
return this.getMissingChunks().length === 0;
|
316
|
+
};
|
332
317
|
|
333
|
-
|
318
|
+
const subStream = new ChunkedStreamSubstream();
|
319
|
+
subStream.pos = subStream.start = start;
|
320
|
+
subStream.end = start + length || this.end;
|
321
|
+
subStream.dict = dict;
|
322
|
+
return subStream;
|
323
|
+
}
|
334
324
|
|
335
|
-
|
336
|
-
/*#__PURE__*/
|
337
|
-
function () {
|
338
|
-
function ChunkedStreamManager(pdfNetworkStream, args) {
|
339
|
-
_classCallCheck(this, ChunkedStreamManager);
|
325
|
+
}
|
340
326
|
|
327
|
+
exports.ChunkedStream = ChunkedStream;
|
328
|
+
|
329
|
+
class ChunkedStreamManager {
|
330
|
+
constructor(pdfNetworkStream, args) {
|
341
331
|
this.length = args.length;
|
342
332
|
this.chunkSize = args.rangeChunkSize;
|
343
333
|
this.stream = new ChunkedStream(this.length, this.chunkSize, this);
|
@@ -345,389 +335,308 @@ function () {
|
|
345
335
|
this.disableAutoFetch = args.disableAutoFetch;
|
346
336
|
this.msgHandler = args.msgHandler;
|
347
337
|
this.currRequestId = 0;
|
348
|
-
this.
|
349
|
-
this.
|
350
|
-
this.
|
338
|
+
this._chunksNeededByRequest = new Map();
|
339
|
+
this._requestsByChunk = new Map();
|
340
|
+
this._promisesByRequest = new Map();
|
351
341
|
this.progressiveDataLength = 0;
|
352
342
|
this.aborted = false;
|
353
343
|
this._loadedStreamCapability = (0, _util.createPromiseCapability)();
|
354
344
|
}
|
355
345
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
return this._loadedStreamCapability.promise;
|
360
|
-
}
|
361
|
-
}, {
|
362
|
-
key: "sendRequest",
|
363
|
-
value: function sendRequest(begin, end) {
|
364
|
-
var _this = this;
|
346
|
+
onLoadedStream() {
|
347
|
+
return this._loadedStreamCapability.promise;
|
348
|
+
}
|
365
349
|
|
366
|
-
|
350
|
+
sendRequest(begin, end) {
|
351
|
+
const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
|
367
352
|
|
368
|
-
|
369
|
-
|
370
|
-
|
353
|
+
if (!rangeReader.isStreamingSupported) {
|
354
|
+
rangeReader.onProgress = this.onProgress.bind(this);
|
355
|
+
}
|
371
356
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
}
|
387
|
-
|
388
|
-
rangeReader.read().then(readChunk, reject);
|
389
|
-
return;
|
357
|
+
let chunks = [],
|
358
|
+
loaded = 0;
|
359
|
+
const promise = new Promise((resolve, reject) => {
|
360
|
+
const readChunk = chunk => {
|
361
|
+
try {
|
362
|
+
if (!chunk.done) {
|
363
|
+
const data = chunk.value;
|
364
|
+
chunks.push(data);
|
365
|
+
loaded += (0, _util.arrayByteLength)(data);
|
366
|
+
|
367
|
+
if (rangeReader.isStreamingSupported) {
|
368
|
+
this.onProgress({
|
369
|
+
loaded
|
370
|
+
});
|
390
371
|
}
|
391
372
|
|
392
|
-
|
393
|
-
|
394
|
-
resolve(chunkData);
|
395
|
-
} catch (e) {
|
396
|
-
reject(e);
|
373
|
+
rangeReader.read().then(readChunk, reject);
|
374
|
+
return;
|
397
375
|
}
|
398
|
-
};
|
399
376
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
377
|
+
const chunkData = (0, _util.arraysToBytes)(chunks);
|
378
|
+
chunks = null;
|
379
|
+
resolve(chunkData);
|
380
|
+
} catch (e) {
|
381
|
+
reject(e);
|
405
382
|
}
|
383
|
+
};
|
406
384
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
385
|
+
rangeReader.read().then(readChunk, reject);
|
386
|
+
});
|
387
|
+
promise.then(data => {
|
388
|
+
if (this.aborted) {
|
389
|
+
return;
|
390
|
+
}
|
391
|
+
|
392
|
+
this.onReceiveData({
|
393
|
+
chunk: data,
|
394
|
+
begin
|
411
395
|
});
|
412
|
-
}
|
413
|
-
}
|
414
|
-
key: "requestAllChunks",
|
415
|
-
value: function requestAllChunks() {
|
416
|
-
var missingChunks = this.stream.getMissingChunks();
|
396
|
+
});
|
397
|
+
}
|
417
398
|
|
418
|
-
|
399
|
+
requestAllChunks() {
|
400
|
+
const missingChunks = this.stream.getMissingChunks();
|
419
401
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
value: function _requestChunks(chunks) {
|
425
|
-
var requestId = this.currRequestId++;
|
426
|
-
var chunksNeeded = Object.create(null);
|
427
|
-
this.chunksNeededByRequest[requestId] = chunksNeeded;
|
428
|
-
var _iteratorNormalCompletion = true;
|
429
|
-
var _didIteratorError = false;
|
430
|
-
var _iteratorError = undefined;
|
402
|
+
this._requestChunks(missingChunks);
|
403
|
+
|
404
|
+
return this._loadedStreamCapability.promise;
|
405
|
+
}
|
431
406
|
|
432
|
-
|
433
|
-
|
434
|
-
|
407
|
+
_requestChunks(chunks) {
|
408
|
+
const requestId = this.currRequestId++;
|
409
|
+
const chunksNeeded = new Set();
|
435
410
|
|
436
|
-
|
437
|
-
chunksNeeded[_chunk] = true;
|
438
|
-
}
|
439
|
-
}
|
440
|
-
} catch (err) {
|
441
|
-
_didIteratorError = true;
|
442
|
-
_iteratorError = err;
|
443
|
-
} finally {
|
444
|
-
try {
|
445
|
-
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
446
|
-
_iterator["return"]();
|
447
|
-
}
|
448
|
-
} finally {
|
449
|
-
if (_didIteratorError) {
|
450
|
-
throw _iteratorError;
|
451
|
-
}
|
452
|
-
}
|
453
|
-
}
|
411
|
+
this._chunksNeededByRequest.set(requestId, chunksNeeded);
|
454
412
|
|
455
|
-
|
456
|
-
|
413
|
+
for (const chunk of chunks) {
|
414
|
+
if (!this.stream.hasChunk(chunk)) {
|
415
|
+
chunksNeeded.add(chunk);
|
457
416
|
}
|
417
|
+
}
|
458
418
|
|
459
|
-
|
460
|
-
|
461
|
-
|
419
|
+
if (chunksNeeded.size === 0) {
|
420
|
+
return Promise.resolve();
|
421
|
+
}
|
462
422
|
|
463
|
-
|
464
|
-
chunk = chunk | 0;
|
423
|
+
const capability = (0, _util.createPromiseCapability)();
|
465
424
|
|
466
|
-
|
467
|
-
this.requestsByChunk[chunk] = [];
|
468
|
-
chunksToRequest.push(chunk);
|
469
|
-
}
|
425
|
+
this._promisesByRequest.set(requestId, capability);
|
470
426
|
|
471
|
-
|
472
|
-
}
|
427
|
+
const chunksToRequest = [];
|
473
428
|
|
474
|
-
|
475
|
-
|
476
|
-
}
|
429
|
+
for (const chunk of chunksNeeded) {
|
430
|
+
let requestIds = this._requestsByChunk.get(chunk);
|
477
431
|
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
for (var _iterator2 = groupedChunksToRequest[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
485
|
-
var groupedChunk = _step2.value;
|
486
|
-
var begin = groupedChunk.beginChunk * this.chunkSize;
|
487
|
-
var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
|
488
|
-
this.sendRequest(begin, end);
|
489
|
-
}
|
490
|
-
} catch (err) {
|
491
|
-
_didIteratorError2 = true;
|
492
|
-
_iteratorError2 = err;
|
493
|
-
} finally {
|
494
|
-
try {
|
495
|
-
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
496
|
-
_iterator2["return"]();
|
497
|
-
}
|
498
|
-
} finally {
|
499
|
-
if (_didIteratorError2) {
|
500
|
-
throw _iteratorError2;
|
501
|
-
}
|
502
|
-
}
|
432
|
+
if (!requestIds) {
|
433
|
+
requestIds = [];
|
434
|
+
|
435
|
+
this._requestsByChunk.set(chunk, requestIds);
|
436
|
+
|
437
|
+
chunksToRequest.push(chunk);
|
503
438
|
}
|
504
439
|
|
505
|
-
|
440
|
+
requestIds.push(requestId);
|
506
441
|
}
|
507
|
-
}, {
|
508
|
-
key: "getStream",
|
509
|
-
value: function getStream() {
|
510
|
-
return this.stream;
|
511
|
-
}
|
512
|
-
}, {
|
513
|
-
key: "requestRange",
|
514
|
-
value: function requestRange(begin, end) {
|
515
|
-
end = Math.min(end, this.length);
|
516
|
-
var beginChunk = this.getBeginChunk(begin);
|
517
|
-
var endChunk = this.getEndChunk(end);
|
518
|
-
var chunks = [];
|
519
442
|
|
520
|
-
|
521
|
-
|
443
|
+
if (chunksToRequest.length > 0) {
|
444
|
+
const groupedChunksToRequest = this.groupChunks(chunksToRequest);
|
445
|
+
|
446
|
+
for (const groupedChunk of groupedChunksToRequest) {
|
447
|
+
const begin = groupedChunk.beginChunk * this.chunkSize;
|
448
|
+
const end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
|
449
|
+
this.sendRequest(begin, end);
|
522
450
|
}
|
451
|
+
}
|
523
452
|
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
key: "requestRanges",
|
528
|
-
value: function requestRanges() {
|
529
|
-
var ranges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
530
|
-
var chunksToRequest = [];
|
531
|
-
var _iteratorNormalCompletion3 = true;
|
532
|
-
var _didIteratorError3 = false;
|
533
|
-
var _iteratorError3 = undefined;
|
534
|
-
|
535
|
-
try {
|
536
|
-
for (var _iterator3 = ranges[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
537
|
-
var range = _step3.value;
|
538
|
-
var beginChunk = this.getBeginChunk(range.begin);
|
539
|
-
var endChunk = this.getEndChunk(range.end);
|
540
|
-
|
541
|
-
for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
|
542
|
-
if (!chunksToRequest.includes(chunk)) {
|
543
|
-
chunksToRequest.push(chunk);
|
544
|
-
}
|
545
|
-
}
|
546
|
-
}
|
547
|
-
} catch (err) {
|
548
|
-
_didIteratorError3 = true;
|
549
|
-
_iteratorError3 = err;
|
550
|
-
} finally {
|
551
|
-
try {
|
552
|
-
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
553
|
-
_iterator3["return"]();
|
554
|
-
}
|
555
|
-
} finally {
|
556
|
-
if (_didIteratorError3) {
|
557
|
-
throw _iteratorError3;
|
558
|
-
}
|
559
|
-
}
|
453
|
+
return capability.promise.catch(reason => {
|
454
|
+
if (this.aborted) {
|
455
|
+
return;
|
560
456
|
}
|
561
457
|
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
458
|
+
throw reason;
|
459
|
+
});
|
460
|
+
}
|
461
|
+
|
462
|
+
getStream() {
|
463
|
+
return this.stream;
|
464
|
+
}
|
465
|
+
|
466
|
+
requestRange(begin, end) {
|
467
|
+
end = Math.min(end, this.length);
|
468
|
+
const beginChunk = this.getBeginChunk(begin);
|
469
|
+
const endChunk = this.getEndChunk(end);
|
470
|
+
const chunks = [];
|
471
|
+
|
472
|
+
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
|
473
|
+
chunks.push(chunk);
|
566
474
|
}
|
567
|
-
}, {
|
568
|
-
key: "groupChunks",
|
569
|
-
value: function groupChunks(chunks) {
|
570
|
-
var groupedChunks = [];
|
571
|
-
var beginChunk = -1;
|
572
|
-
var prevChunk = -1;
|
573
475
|
|
574
|
-
|
575
|
-
|
476
|
+
return this._requestChunks(chunks);
|
477
|
+
}
|
576
478
|
|
577
|
-
|
578
|
-
|
579
|
-
}
|
479
|
+
requestRanges(ranges = []) {
|
480
|
+
const chunksToRequest = [];
|
580
481
|
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
endChunk: prevChunk + 1
|
585
|
-
});
|
586
|
-
beginChunk = chunk;
|
587
|
-
}
|
482
|
+
for (const range of ranges) {
|
483
|
+
const beginChunk = this.getBeginChunk(range.begin);
|
484
|
+
const endChunk = this.getEndChunk(range.end);
|
588
485
|
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
endChunk: chunk + 1
|
593
|
-
});
|
486
|
+
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
|
487
|
+
if (!chunksToRequest.includes(chunk)) {
|
488
|
+
chunksToRequest.push(chunk);
|
594
489
|
}
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
chunksToRequest.sort(function (a, b) {
|
494
|
+
return a - b;
|
495
|
+
});
|
496
|
+
return this._requestChunks(chunksToRequest);
|
497
|
+
}
|
498
|
+
|
499
|
+
groupChunks(chunks) {
|
500
|
+
const groupedChunks = [];
|
501
|
+
let beginChunk = -1;
|
502
|
+
let prevChunk = -1;
|
503
|
+
|
504
|
+
for (let i = 0, ii = chunks.length; i < ii; ++i) {
|
505
|
+
const chunk = chunks[i];
|
595
506
|
|
596
|
-
|
507
|
+
if (beginChunk < 0) {
|
508
|
+
beginChunk = chunk;
|
597
509
|
}
|
598
510
|
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
|
606
|
-
total: this.length
|
607
|
-
});
|
608
|
-
}
|
609
|
-
}, {
|
610
|
-
key: "onReceiveData",
|
611
|
-
value: function onReceiveData(args) {
|
612
|
-
var chunk = args.chunk;
|
613
|
-
var isProgressive = args.begin === undefined;
|
614
|
-
var begin = isProgressive ? this.progressiveDataLength : args.begin;
|
615
|
-
var end = begin + chunk.byteLength;
|
616
|
-
var beginChunk = Math.floor(begin / this.chunkSize);
|
617
|
-
var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
|
618
|
-
|
619
|
-
if (isProgressive) {
|
620
|
-
this.stream.onReceiveProgressiveData(chunk);
|
621
|
-
this.progressiveDataLength = end;
|
622
|
-
} else {
|
623
|
-
this.stream.onReceiveData(begin, chunk);
|
511
|
+
if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
|
512
|
+
groupedChunks.push({
|
513
|
+
beginChunk,
|
514
|
+
endChunk: prevChunk + 1
|
515
|
+
});
|
516
|
+
beginChunk = chunk;
|
624
517
|
}
|
625
518
|
|
626
|
-
if (
|
627
|
-
|
519
|
+
if (i + 1 === chunks.length) {
|
520
|
+
groupedChunks.push({
|
521
|
+
beginChunk,
|
522
|
+
endChunk: chunk + 1
|
523
|
+
});
|
628
524
|
}
|
629
525
|
|
630
|
-
|
526
|
+
prevChunk = chunk;
|
527
|
+
}
|
528
|
+
|
529
|
+
return groupedChunks;
|
530
|
+
}
|
631
531
|
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
532
|
+
onProgress(args) {
|
533
|
+
this.msgHandler.send("DocProgress", {
|
534
|
+
loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
|
535
|
+
total: this.length
|
536
|
+
});
|
537
|
+
}
|
638
538
|
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
539
|
+
onReceiveData(args) {
|
540
|
+
const chunk = args.chunk;
|
541
|
+
const isProgressive = args.begin === undefined;
|
542
|
+
const begin = isProgressive ? this.progressiveDataLength : args.begin;
|
543
|
+
const end = begin + chunk.byteLength;
|
544
|
+
const beginChunk = Math.floor(begin / this.chunkSize);
|
545
|
+
const endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
|
643
546
|
|
644
|
-
|
645
|
-
|
646
|
-
|
547
|
+
if (isProgressive) {
|
548
|
+
this.stream.onReceiveProgressiveData(chunk);
|
549
|
+
this.progressiveDataLength = end;
|
550
|
+
} else {
|
551
|
+
this.stream.onReceiveData(begin, chunk);
|
552
|
+
}
|
647
553
|
|
648
|
-
|
649
|
-
|
650
|
-
|
554
|
+
if (this.stream.allChunksLoaded()) {
|
555
|
+
this._loadedStreamCapability.resolve(this.stream);
|
556
|
+
}
|
651
557
|
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
|
660
|
-
_iterator4["return"]();
|
661
|
-
}
|
662
|
-
} finally {
|
663
|
-
if (_didIteratorError4) {
|
664
|
-
throw _iteratorError4;
|
665
|
-
}
|
666
|
-
}
|
667
|
-
}
|
558
|
+
const loadedRequests = [];
|
559
|
+
|
560
|
+
for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
561
|
+
const requestIds = this._requestsByChunk.get(curChunk);
|
562
|
+
|
563
|
+
if (!requestIds) {
|
564
|
+
continue;
|
668
565
|
}
|
669
566
|
|
670
|
-
|
671
|
-
var nextEmptyChunk;
|
567
|
+
this._requestsByChunk.delete(curChunk);
|
672
568
|
|
673
|
-
|
674
|
-
|
569
|
+
for (const requestId of requestIds) {
|
570
|
+
const chunksNeeded = this._chunksNeededByRequest.get(requestId);
|
675
571
|
|
676
|
-
|
677
|
-
|
678
|
-
}
|
679
|
-
} else {
|
680
|
-
nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
|
572
|
+
if (chunksNeeded.has(curChunk)) {
|
573
|
+
chunksNeeded.delete(curChunk);
|
681
574
|
}
|
682
575
|
|
683
|
-
if (
|
684
|
-
|
576
|
+
if (chunksNeeded.size > 0) {
|
577
|
+
continue;
|
685
578
|
}
|
579
|
+
|
580
|
+
loadedRequests.push(requestId);
|
686
581
|
}
|
582
|
+
}
|
687
583
|
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
584
|
+
if (!this.disableAutoFetch && this._requestsByChunk.size === 0) {
|
585
|
+
let nextEmptyChunk;
|
586
|
+
|
587
|
+
if (this.stream.numChunksLoaded === 1) {
|
588
|
+
const lastChunk = this.stream.numChunks - 1;
|
589
|
+
|
590
|
+
if (!this.stream.hasChunk(lastChunk)) {
|
591
|
+
nextEmptyChunk = lastChunk;
|
592
|
+
}
|
593
|
+
} else {
|
594
|
+
nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
|
693
595
|
}
|
694
596
|
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
});
|
699
|
-
}
|
700
|
-
}, {
|
701
|
-
key: "onError",
|
702
|
-
value: function onError(err) {
|
703
|
-
this._loadedStreamCapability.reject(err);
|
704
|
-
}
|
705
|
-
}, {
|
706
|
-
key: "getBeginChunk",
|
707
|
-
value: function getBeginChunk(begin) {
|
708
|
-
return Math.floor(begin / this.chunkSize);
|
597
|
+
if (Number.isInteger(nextEmptyChunk)) {
|
598
|
+
this._requestChunks([nextEmptyChunk]);
|
599
|
+
}
|
709
600
|
}
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
601
|
+
|
602
|
+
for (const requestId of loadedRequests) {
|
603
|
+
const capability = this._promisesByRequest.get(requestId);
|
604
|
+
|
605
|
+
this._promisesByRequest.delete(requestId);
|
606
|
+
|
607
|
+
capability.resolve();
|
714
608
|
}
|
715
|
-
}, {
|
716
|
-
key: "abort",
|
717
|
-
value: function abort() {
|
718
|
-
this.aborted = true;
|
719
609
|
|
720
|
-
|
721
|
-
|
722
|
-
|
610
|
+
this.msgHandler.send("DocProgress", {
|
611
|
+
loaded: this.stream.numChunksLoaded * this.chunkSize,
|
612
|
+
total: this.length
|
613
|
+
});
|
614
|
+
}
|
723
615
|
|
724
|
-
|
725
|
-
|
726
|
-
|
616
|
+
onError(err) {
|
617
|
+
this._loadedStreamCapability.reject(err);
|
618
|
+
}
|
619
|
+
|
620
|
+
getBeginChunk(begin) {
|
621
|
+
return Math.floor(begin / this.chunkSize);
|
622
|
+
}
|
623
|
+
|
624
|
+
getEndChunk(end) {
|
625
|
+
return Math.floor((end - 1) / this.chunkSize) + 1;
|
626
|
+
}
|
627
|
+
|
628
|
+
abort(reason) {
|
629
|
+
this.aborted = true;
|
630
|
+
|
631
|
+
if (this.pdfNetworkStream) {
|
632
|
+
this.pdfNetworkStream.cancelAllRequests(reason);
|
727
633
|
}
|
728
|
-
}]);
|
729
634
|
|
730
|
-
|
731
|
-
|
635
|
+
for (const capability of this._promisesByRequest.values()) {
|
636
|
+
capability.reject(reason);
|
637
|
+
}
|
638
|
+
}
|
639
|
+
|
640
|
+
}
|
732
641
|
|
733
642
|
exports.ChunkedStreamManager = ChunkedStreamManager;
|