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