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