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
package/lib/display/network.js
CHANGED
@@ -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.
|
@@ -24,117 +24,87 @@
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.PDFNetworkStream =
|
28
|
-
exports.NetworkManager = NetworkManager;
|
29
|
-
|
30
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
31
|
-
|
32
|
-
var _util = require("../shared/util");
|
33
|
-
|
34
|
-
var _network_utils = require("./network_utils");
|
27
|
+
exports.PDFNetworkStream = void 0;
|
35
28
|
|
36
|
-
var
|
29
|
+
var _util = require("../shared/util.js");
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
41
|
-
|
42
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
31
|
+
var _network_utils = require("./network_utils.js");
|
43
32
|
|
44
33
|
;
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
function NetworkManager(url, args) {
|
49
|
-
this.url = url;
|
50
|
-
args = args || {};
|
51
|
-
this.isHttp = /^https?:/i.test(url);
|
52
|
-
this.httpHeaders = this.isHttp && args.httpHeaders || {};
|
53
|
-
this.withCredentials = args.withCredentials || false;
|
54
|
-
|
55
|
-
this.getXhr = args.getXhr || function NetworkManager_getXhr() {
|
56
|
-
return new XMLHttpRequest();
|
57
|
-
};
|
58
|
-
|
59
|
-
this.currXhrId = 0;
|
60
|
-
this.pendingRequests = Object.create(null);
|
61
|
-
this.loadedRequests = Object.create(null);
|
62
|
-
}
|
34
|
+
const OK_RESPONSE = 200;
|
35
|
+
const PARTIAL_CONTENT_RESPONSE = 206;
|
63
36
|
|
64
37
|
function getArrayBuffer(xhr) {
|
65
|
-
|
38
|
+
const data = xhr.response;
|
66
39
|
|
67
|
-
if (typeof data !==
|
40
|
+
if (typeof data !== "string") {
|
68
41
|
return data;
|
69
42
|
}
|
70
43
|
|
71
|
-
|
44
|
+
const array = (0, _util.stringToBytes)(data);
|
72
45
|
return array.buffer;
|
73
46
|
}
|
74
47
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
48
|
+
class NetworkManager {
|
49
|
+
constructor(url, args) {
|
50
|
+
this.url = url;
|
51
|
+
args = args || {};
|
52
|
+
this.isHttp = /^https?:/i.test(url);
|
53
|
+
this.httpHeaders = this.isHttp && args.httpHeaders || {};
|
54
|
+
this.withCredentials = args.withCredentials || false;
|
55
|
+
|
56
|
+
this.getXhr = args.getXhr || function NetworkManager_getXhr() {
|
57
|
+
return new XMLHttpRequest();
|
58
|
+
};
|
59
|
+
|
60
|
+
this.currXhrId = 0;
|
61
|
+
this.pendingRequests = Object.create(null);
|
83
62
|
}
|
84
|
-
}();
|
85
63
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end: end
|
64
|
+
requestRange(begin, end, listeners) {
|
65
|
+
const args = {
|
66
|
+
begin,
|
67
|
+
end
|
91
68
|
};
|
92
69
|
|
93
|
-
for (
|
70
|
+
for (const prop in listeners) {
|
94
71
|
args[prop] = listeners[prop];
|
95
72
|
}
|
96
73
|
|
97
74
|
return this.request(args);
|
98
|
-
}
|
99
|
-
|
75
|
+
}
|
76
|
+
|
77
|
+
requestFull(listeners) {
|
100
78
|
return this.request(listeners);
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
79
|
+
}
|
80
|
+
|
81
|
+
request(args) {
|
82
|
+
const xhr = this.getXhr();
|
83
|
+
const xhrId = this.currXhrId++;
|
84
|
+
const pendingRequest = this.pendingRequests[xhrId] = {
|
85
|
+
xhr
|
107
86
|
};
|
108
|
-
xhr.open(
|
87
|
+
xhr.open("GET", this.url);
|
109
88
|
xhr.withCredentials = this.withCredentials;
|
110
89
|
|
111
|
-
for (
|
112
|
-
|
90
|
+
for (const property in this.httpHeaders) {
|
91
|
+
const value = this.httpHeaders[property];
|
113
92
|
|
114
|
-
if (typeof value ===
|
93
|
+
if (typeof value === "undefined") {
|
115
94
|
continue;
|
116
95
|
}
|
117
96
|
|
118
97
|
xhr.setRequestHeader(property, value);
|
119
98
|
}
|
120
99
|
|
121
|
-
if (this.isHttp &&
|
122
|
-
|
123
|
-
|
124
|
-
pendingRequest.expectedStatus = 206;
|
100
|
+
if (this.isHttp && "begin" in args && "end" in args) {
|
101
|
+
xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
|
102
|
+
pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
|
125
103
|
} else {
|
126
|
-
pendingRequest.expectedStatus =
|
104
|
+
pendingRequest.expectedStatus = OK_RESPONSE;
|
127
105
|
}
|
128
106
|
|
129
|
-
|
130
|
-
|
131
|
-
if (useMozChunkedLoading) {
|
132
|
-
xhr.responseType = 'moz-chunked-arraybuffer';
|
133
|
-
pendingRequest.onProgressiveData = args.onProgressiveData;
|
134
|
-
pendingRequest.mozChunked = true;
|
135
|
-
} else {
|
136
|
-
xhr.responseType = 'arraybuffer';
|
137
|
-
}
|
107
|
+
xhr.responseType = "arraybuffer";
|
138
108
|
|
139
109
|
if (args.onError) {
|
140
110
|
xhr.onerror = function (evt) {
|
@@ -150,33 +120,28 @@ NetworkManager.prototype = {
|
|
150
120
|
pendingRequest.onProgress = args.onProgress;
|
151
121
|
xhr.send(null);
|
152
122
|
return xhrId;
|
153
|
-
}
|
154
|
-
|
155
|
-
|
123
|
+
}
|
124
|
+
|
125
|
+
onProgress(xhrId, evt) {
|
126
|
+
const pendingRequest = this.pendingRequests[xhrId];
|
156
127
|
|
157
128
|
if (!pendingRequest) {
|
158
129
|
return;
|
159
130
|
}
|
160
131
|
|
161
|
-
if (pendingRequest.
|
162
|
-
|
163
|
-
pendingRequest.onProgressiveData(chunk);
|
132
|
+
if (pendingRequest.onProgress) {
|
133
|
+
pendingRequest.onProgress(evt);
|
164
134
|
}
|
135
|
+
}
|
165
136
|
|
166
|
-
|
167
|
-
|
168
|
-
if (onProgress) {
|
169
|
-
onProgress(evt);
|
170
|
-
}
|
171
|
-
},
|
172
|
-
onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
|
173
|
-
var pendingRequest = this.pendingRequests[xhrId];
|
137
|
+
onStateChange(xhrId, evt) {
|
138
|
+
const pendingRequest = this.pendingRequests[xhrId];
|
174
139
|
|
175
140
|
if (!pendingRequest) {
|
176
141
|
return;
|
177
142
|
}
|
178
143
|
|
179
|
-
|
144
|
+
const xhr = pendingRequest.xhr;
|
180
145
|
|
181
146
|
if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
|
182
147
|
pendingRequest.onHeadersReceived();
|
@@ -201,8 +166,8 @@ NetworkManager.prototype = {
|
|
201
166
|
return;
|
202
167
|
}
|
203
168
|
|
204
|
-
|
205
|
-
|
169
|
+
const xhrStatus = xhr.status || OK_RESPONSE;
|
170
|
+
const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
|
206
171
|
|
207
172
|
if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
|
208
173
|
if (pendingRequest.onError) {
|
@@ -212,152 +177,154 @@ NetworkManager.prototype = {
|
|
212
177
|
return;
|
213
178
|
}
|
214
179
|
|
215
|
-
|
216
|
-
var chunk = getArrayBuffer(xhr);
|
180
|
+
const chunk = getArrayBuffer(xhr);
|
217
181
|
|
218
182
|
if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
|
219
|
-
|
220
|
-
|
221
|
-
var begin = parseInt(matches[1], 10);
|
183
|
+
const rangeHeader = xhr.getResponseHeader("Content-Range");
|
184
|
+
const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
|
222
185
|
pendingRequest.onDone({
|
223
|
-
begin:
|
224
|
-
chunk
|
186
|
+
begin: parseInt(matches[1], 10),
|
187
|
+
chunk
|
225
188
|
});
|
226
|
-
} else if (pendingRequest.onProgressiveData) {
|
227
|
-
pendingRequest.onDone(null);
|
228
189
|
} else if (chunk) {
|
229
190
|
pendingRequest.onDone({
|
230
191
|
begin: 0,
|
231
|
-
chunk
|
192
|
+
chunk
|
232
193
|
});
|
233
194
|
} else if (pendingRequest.onError) {
|
234
195
|
pendingRequest.onError(xhr.status);
|
235
196
|
}
|
236
|
-
}
|
237
|
-
|
238
|
-
|
197
|
+
}
|
198
|
+
|
199
|
+
hasPendingRequests() {
|
200
|
+
for (const xhrId in this.pendingRequests) {
|
239
201
|
return true;
|
240
202
|
}
|
241
203
|
|
242
204
|
return false;
|
243
|
-
}
|
244
|
-
|
205
|
+
}
|
206
|
+
|
207
|
+
getRequestXhr(xhrId) {
|
245
208
|
return this.pendingRequests[xhrId].xhr;
|
246
|
-
}
|
247
|
-
|
248
|
-
|
249
|
-
},
|
250
|
-
isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
|
209
|
+
}
|
210
|
+
|
211
|
+
isPendingRequest(xhrId) {
|
251
212
|
return xhrId in this.pendingRequests;
|
252
|
-
}
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
abortAllRequests: function NetworkManager_abortAllRequests() {
|
257
|
-
for (var xhrId in this.pendingRequests) {
|
213
|
+
}
|
214
|
+
|
215
|
+
abortAllRequests() {
|
216
|
+
for (const xhrId in this.pendingRequests) {
|
258
217
|
this.abortRequest(xhrId | 0);
|
259
218
|
}
|
260
|
-
}
|
261
|
-
|
262
|
-
|
219
|
+
}
|
220
|
+
|
221
|
+
abortRequest(xhrId) {
|
222
|
+
const xhr = this.pendingRequests[xhrId].xhr;
|
263
223
|
delete this.pendingRequests[xhrId];
|
264
224
|
xhr.abort();
|
265
225
|
}
|
266
|
-
|
267
|
-
|
268
|
-
function PDFNetworkStream(source) {
|
269
|
-
this._source = source;
|
270
|
-
this._manager = new NetworkManager(source.url, {
|
271
|
-
httpHeaders: source.httpHeaders,
|
272
|
-
withCredentials: source.withCredentials
|
273
|
-
});
|
274
|
-
this._rangeChunkSize = source.rangeChunkSize;
|
275
|
-
this._fullRequestReader = null;
|
276
|
-
this._rangeRequestReaders = [];
|
226
|
+
|
277
227
|
}
|
278
228
|
|
279
|
-
PDFNetworkStream
|
280
|
-
|
281
|
-
|
229
|
+
class PDFNetworkStream {
|
230
|
+
constructor(source) {
|
231
|
+
this._source = source;
|
232
|
+
this._manager = new NetworkManager(source.url, {
|
233
|
+
httpHeaders: source.httpHeaders,
|
234
|
+
withCredentials: source.withCredentials
|
235
|
+
});
|
236
|
+
this._rangeChunkSize = source.rangeChunkSize;
|
237
|
+
this._fullRequestReader = null;
|
238
|
+
this._rangeRequestReaders = [];
|
239
|
+
}
|
240
|
+
|
241
|
+
_onRangeRequestReaderClosed(reader) {
|
242
|
+
const i = this._rangeRequestReaders.indexOf(reader);
|
282
243
|
|
283
244
|
if (i >= 0) {
|
284
245
|
this._rangeRequestReaders.splice(i, 1);
|
285
246
|
}
|
286
|
-
}
|
287
|
-
|
288
|
-
|
247
|
+
}
|
248
|
+
|
249
|
+
getFullReader() {
|
250
|
+
(0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
|
289
251
|
this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
|
290
252
|
return this._fullRequestReader;
|
291
|
-
}
|
292
|
-
|
293
|
-
|
253
|
+
}
|
254
|
+
|
255
|
+
getRangeReader(begin, end) {
|
256
|
+
const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
|
294
257
|
reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
|
295
258
|
|
296
259
|
this._rangeRequestReaders.push(reader);
|
297
260
|
|
298
261
|
return reader;
|
299
|
-
}
|
300
|
-
|
262
|
+
}
|
263
|
+
|
264
|
+
cancelAllRequests(reason) {
|
301
265
|
if (this._fullRequestReader) {
|
302
266
|
this._fullRequestReader.cancel(reason);
|
303
267
|
}
|
304
268
|
|
305
|
-
|
269
|
+
const readers = this._rangeRequestReaders.slice(0);
|
306
270
|
|
307
271
|
readers.forEach(function (reader) {
|
308
272
|
reader.cancel(reason);
|
309
273
|
});
|
310
274
|
}
|
311
|
-
|
312
|
-
|
313
|
-
function PDFNetworkStreamFullRequestReader(manager, source) {
|
314
|
-
this._manager = manager;
|
315
|
-
var args = {
|
316
|
-
onHeadersReceived: this._onHeadersReceived.bind(this),
|
317
|
-
onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
|
318
|
-
onDone: this._onDone.bind(this),
|
319
|
-
onError: this._onError.bind(this),
|
320
|
-
onProgress: this._onProgress.bind(this)
|
321
|
-
};
|
322
|
-
this._url = source.url;
|
323
|
-
this._fullRequestId = manager.requestFull(args);
|
324
|
-
this._headersReceivedCapability = (0, _util.createPromiseCapability)();
|
325
|
-
this._disableRange = source.disableRange || false;
|
326
|
-
this._contentLength = source.length;
|
327
|
-
this._rangeChunkSize = source.rangeChunkSize;
|
328
|
-
|
329
|
-
if (!this._rangeChunkSize && !this._disableRange) {
|
330
|
-
this._disableRange = true;
|
331
|
-
}
|
332
|
-
|
333
|
-
this._isStreamingSupported = false;
|
334
|
-
this._isRangeSupported = false;
|
335
|
-
this._cachedChunks = [];
|
336
|
-
this._requests = [];
|
337
|
-
this._done = false;
|
338
|
-
this._storedError = undefined;
|
339
|
-
this._filename = null;
|
340
|
-
this.onProgress = null;
|
275
|
+
|
341
276
|
}
|
342
277
|
|
343
|
-
|
344
|
-
|
345
|
-
|
278
|
+
exports.PDFNetworkStream = PDFNetworkStream;
|
279
|
+
|
280
|
+
class PDFNetworkStreamFullRequestReader {
|
281
|
+
constructor(manager, source) {
|
282
|
+
this._manager = manager;
|
283
|
+
const args = {
|
284
|
+
onHeadersReceived: this._onHeadersReceived.bind(this),
|
285
|
+
onDone: this._onDone.bind(this),
|
286
|
+
onError: this._onError.bind(this),
|
287
|
+
onProgress: this._onProgress.bind(this)
|
288
|
+
};
|
289
|
+
this._url = source.url;
|
290
|
+
this._fullRequestId = manager.requestFull(args);
|
291
|
+
this._headersReceivedCapability = (0, _util.createPromiseCapability)();
|
292
|
+
this._disableRange = source.disableRange || false;
|
293
|
+
this._contentLength = source.length;
|
294
|
+
this._rangeChunkSize = source.rangeChunkSize;
|
295
|
+
|
296
|
+
if (!this._rangeChunkSize && !this._disableRange) {
|
297
|
+
this._disableRange = true;
|
298
|
+
}
|
299
|
+
|
300
|
+
this._isStreamingSupported = false;
|
301
|
+
this._isRangeSupported = false;
|
302
|
+
this._cachedChunks = [];
|
303
|
+
this._requests = [];
|
304
|
+
this._done = false;
|
305
|
+
this._storedError = undefined;
|
306
|
+
this._filename = null;
|
307
|
+
this.onProgress = null;
|
308
|
+
}
|
346
309
|
|
347
|
-
|
310
|
+
_onHeadersReceived() {
|
311
|
+
const fullRequestXhrId = this._fullRequestId;
|
348
312
|
|
349
|
-
|
313
|
+
const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
|
314
|
+
|
315
|
+
const getResponseHeader = name => {
|
350
316
|
return fullRequestXhr.getResponseHeader(name);
|
351
317
|
};
|
352
318
|
|
353
|
-
|
354
|
-
|
319
|
+
const {
|
320
|
+
allowRangeRequests,
|
321
|
+
suggestedLength
|
322
|
+
} = (0, _network_utils.validateRangeRequestCapabilities)({
|
323
|
+
getResponseHeader,
|
355
324
|
isHttp: this._manager.isHttp,
|
356
325
|
rangeChunkSize: this._rangeChunkSize,
|
357
326
|
disableRange: this._disableRange
|
358
|
-
})
|
359
|
-
allowRangeRequests = _validateRangeRequest.allowRangeRequests,
|
360
|
-
suggestedLength = _validateRangeRequest.suggestedLength;
|
327
|
+
});
|
361
328
|
|
362
329
|
if (allowRangeRequests) {
|
363
330
|
this._isRangeSupported = true;
|
@@ -365,31 +332,26 @@ PDFNetworkStreamFullRequestReader.prototype = {
|
|
365
332
|
|
366
333
|
this._contentLength = suggestedLength || this._contentLength;
|
367
334
|
this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
368
|
-
var networkManager = this._manager;
|
369
335
|
|
370
|
-
if (
|
371
|
-
this.
|
372
|
-
} else if (this._isRangeSupported) {
|
373
|
-
networkManager.abortRequest(fullRequestXhrId);
|
336
|
+
if (this._isRangeSupported) {
|
337
|
+
this._manager.abortRequest(fullRequestXhrId);
|
374
338
|
}
|
375
339
|
|
376
340
|
this._headersReceivedCapability.resolve();
|
377
|
-
}
|
378
|
-
_onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
|
379
|
-
if (this._requests.length > 0) {
|
380
|
-
var requestCapability = this._requests.shift();
|
341
|
+
}
|
381
342
|
|
382
|
-
|
383
|
-
value: chunk,
|
384
|
-
done: false
|
385
|
-
});
|
386
|
-
} else {
|
387
|
-
this._cachedChunks.push(chunk);
|
388
|
-
}
|
389
|
-
},
|
390
|
-
_onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
|
343
|
+
_onDone(args) {
|
391
344
|
if (args) {
|
392
|
-
this.
|
345
|
+
if (this._requests.length > 0) {
|
346
|
+
const requestCapability = this._requests.shift();
|
347
|
+
|
348
|
+
requestCapability.resolve({
|
349
|
+
value: args.chunk,
|
350
|
+
done: false
|
351
|
+
});
|
352
|
+
} else {
|
353
|
+
this._cachedChunks.push(args.chunk);
|
354
|
+
}
|
393
355
|
}
|
394
356
|
|
395
357
|
this._done = true;
|
@@ -406,10 +368,11 @@ PDFNetworkStreamFullRequestReader.prototype = {
|
|
406
368
|
});
|
407
369
|
|
408
370
|
this._requests = [];
|
409
|
-
}
|
410
|
-
|
411
|
-
|
412
|
-
|
371
|
+
}
|
372
|
+
|
373
|
+
_onError(status) {
|
374
|
+
const url = this._url;
|
375
|
+
const exception = (0, _network_utils.createResponseStatusError)(status, url);
|
413
376
|
this._storedError = exception;
|
414
377
|
|
415
378
|
this._headersReceivedCapability.reject(exception);
|
@@ -420,97 +383,66 @@ PDFNetworkStreamFullRequestReader.prototype = {
|
|
420
383
|
|
421
384
|
this._requests = [];
|
422
385
|
this._cachedChunks = [];
|
423
|
-
}
|
424
|
-
|
386
|
+
}
|
387
|
+
|
388
|
+
_onProgress(data) {
|
425
389
|
if (this.onProgress) {
|
426
390
|
this.onProgress({
|
427
391
|
loaded: data.loaded,
|
428
392
|
total: data.lengthComputable ? data.total : this._contentLength
|
429
393
|
});
|
430
394
|
}
|
431
|
-
}
|
395
|
+
}
|
432
396
|
|
433
397
|
get filename() {
|
434
398
|
return this._filename;
|
435
|
-
}
|
399
|
+
}
|
436
400
|
|
437
401
|
get isRangeSupported() {
|
438
402
|
return this._isRangeSupported;
|
439
|
-
}
|
403
|
+
}
|
440
404
|
|
441
405
|
get isStreamingSupported() {
|
442
406
|
return this._isStreamingSupported;
|
443
|
-
}
|
407
|
+
}
|
444
408
|
|
445
409
|
get contentLength() {
|
446
410
|
return this._contentLength;
|
447
|
-
}
|
411
|
+
}
|
448
412
|
|
449
413
|
get headersReady() {
|
450
414
|
return this._headersReceivedCapability.promise;
|
451
|
-
}
|
452
|
-
|
453
|
-
read
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
if (!this._done) {
|
483
|
-
_context.next = 7;
|
484
|
-
break;
|
485
|
-
}
|
486
|
-
|
487
|
-
return _context.abrupt("return", {
|
488
|
-
value: undefined,
|
489
|
-
done: true
|
490
|
-
});
|
491
|
-
|
492
|
-
case 7:
|
493
|
-
requestCapability = (0, _util.createPromiseCapability)();
|
494
|
-
|
495
|
-
this._requests.push(requestCapability);
|
496
|
-
|
497
|
-
return _context.abrupt("return", requestCapability.promise);
|
498
|
-
|
499
|
-
case 10:
|
500
|
-
case "end":
|
501
|
-
return _context.stop();
|
502
|
-
}
|
503
|
-
}
|
504
|
-
}, _callee, this);
|
505
|
-
}));
|
506
|
-
|
507
|
-
function read() {
|
508
|
-
return _read.apply(this, arguments);
|
509
|
-
}
|
510
|
-
|
511
|
-
return read;
|
512
|
-
}(),
|
513
|
-
cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
|
415
|
+
}
|
416
|
+
|
417
|
+
async read() {
|
418
|
+
if (this._storedError) {
|
419
|
+
throw this._storedError;
|
420
|
+
}
|
421
|
+
|
422
|
+
if (this._cachedChunks.length > 0) {
|
423
|
+
const chunk = this._cachedChunks.shift();
|
424
|
+
|
425
|
+
return {
|
426
|
+
value: chunk,
|
427
|
+
done: false
|
428
|
+
};
|
429
|
+
}
|
430
|
+
|
431
|
+
if (this._done) {
|
432
|
+
return {
|
433
|
+
value: undefined,
|
434
|
+
done: true
|
435
|
+
};
|
436
|
+
}
|
437
|
+
|
438
|
+
const requestCapability = (0, _util.createPromiseCapability)();
|
439
|
+
|
440
|
+
this._requests.push(requestCapability);
|
441
|
+
|
442
|
+
return requestCapability.promise;
|
443
|
+
}
|
444
|
+
|
445
|
+
cancel(reason) {
|
514
446
|
this._done = true;
|
515
447
|
|
516
448
|
this._headersReceivedCapability.reject(reason);
|
@@ -530,33 +462,35 @@ PDFNetworkStreamFullRequestReader.prototype = {
|
|
530
462
|
|
531
463
|
this._fullRequestReader = null;
|
532
464
|
}
|
533
|
-
|
534
|
-
|
535
|
-
function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
|
536
|
-
this._manager = manager;
|
537
|
-
var args = {
|
538
|
-
onDone: this._onDone.bind(this),
|
539
|
-
onProgress: this._onProgress.bind(this)
|
540
|
-
};
|
541
|
-
this._requestId = manager.requestRange(begin, end, args);
|
542
|
-
this._requests = [];
|
543
|
-
this._queuedChunk = null;
|
544
|
-
this._done = false;
|
545
|
-
this.onProgress = null;
|
546
|
-
this.onClosed = null;
|
465
|
+
|
547
466
|
}
|
548
467
|
|
549
|
-
PDFNetworkStreamRangeRequestReader
|
550
|
-
|
468
|
+
class PDFNetworkStreamRangeRequestReader {
|
469
|
+
constructor(manager, begin, end) {
|
470
|
+
this._manager = manager;
|
471
|
+
const args = {
|
472
|
+
onDone: this._onDone.bind(this),
|
473
|
+
onProgress: this._onProgress.bind(this)
|
474
|
+
};
|
475
|
+
this._requestId = manager.requestRange(begin, end, args);
|
476
|
+
this._requests = [];
|
477
|
+
this._queuedChunk = null;
|
478
|
+
this._done = false;
|
479
|
+
this.onProgress = null;
|
480
|
+
this.onClosed = null;
|
481
|
+
}
|
482
|
+
|
483
|
+
_close() {
|
551
484
|
if (this.onClosed) {
|
552
485
|
this.onClosed(this);
|
553
486
|
}
|
554
|
-
}
|
555
|
-
|
556
|
-
|
487
|
+
}
|
488
|
+
|
489
|
+
_onDone(data) {
|
490
|
+
const chunk = data.chunk;
|
557
491
|
|
558
492
|
if (this._requests.length > 0) {
|
559
|
-
|
493
|
+
const requestCapability = this._requests.shift();
|
560
494
|
|
561
495
|
requestCapability.resolve({
|
562
496
|
value: chunk,
|
@@ -578,73 +512,45 @@ PDFNetworkStreamRangeRequestReader.prototype = {
|
|
578
512
|
this._requests = [];
|
579
513
|
|
580
514
|
this._close();
|
581
|
-
}
|
582
|
-
|
515
|
+
}
|
516
|
+
|
517
|
+
_onProgress(evt) {
|
583
518
|
if (!this.isStreamingSupported && this.onProgress) {
|
584
519
|
this.onProgress({
|
585
520
|
loaded: evt.loaded
|
586
521
|
});
|
587
522
|
}
|
588
|
-
}
|
523
|
+
}
|
589
524
|
|
590
525
|
get isStreamingSupported() {
|
591
526
|
return false;
|
592
|
-
}
|
593
|
-
|
594
|
-
read
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
}
|
620
|
-
|
621
|
-
return _context2.abrupt("return", {
|
622
|
-
value: undefined,
|
623
|
-
done: true
|
624
|
-
});
|
625
|
-
|
626
|
-
case 6:
|
627
|
-
requestCapability = (0, _util.createPromiseCapability)();
|
628
|
-
|
629
|
-
this._requests.push(requestCapability);
|
630
|
-
|
631
|
-
return _context2.abrupt("return", requestCapability.promise);
|
632
|
-
|
633
|
-
case 9:
|
634
|
-
case "end":
|
635
|
-
return _context2.stop();
|
636
|
-
}
|
637
|
-
}
|
638
|
-
}, _callee2, this);
|
639
|
-
}));
|
640
|
-
|
641
|
-
function read() {
|
642
|
-
return _read2.apply(this, arguments);
|
643
|
-
}
|
644
|
-
|
645
|
-
return read;
|
646
|
-
}(),
|
647
|
-
cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
|
527
|
+
}
|
528
|
+
|
529
|
+
async read() {
|
530
|
+
if (this._queuedChunk !== null) {
|
531
|
+
const chunk = this._queuedChunk;
|
532
|
+
this._queuedChunk = null;
|
533
|
+
return {
|
534
|
+
value: chunk,
|
535
|
+
done: false
|
536
|
+
};
|
537
|
+
}
|
538
|
+
|
539
|
+
if (this._done) {
|
540
|
+
return {
|
541
|
+
value: undefined,
|
542
|
+
done: true
|
543
|
+
};
|
544
|
+
}
|
545
|
+
|
546
|
+
const requestCapability = (0, _util.createPromiseCapability)();
|
547
|
+
|
548
|
+
this._requests.push(requestCapability);
|
549
|
+
|
550
|
+
return requestCapability.promise;
|
551
|
+
}
|
552
|
+
|
553
|
+
cancel(reason) {
|
648
554
|
this._done = true;
|
649
555
|
|
650
556
|
this._requests.forEach(function (requestCapability) {
|
@@ -662,4 +568,5 @@ PDFNetworkStreamRangeRequestReader.prototype = {
|
|
662
568
|
|
663
569
|
this._close();
|
664
570
|
}
|
665
|
-
|
571
|
+
|
572
|
+
}
|