pdfjs-dist 2.0.943 → 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/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- 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 +25500 -26628
- 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 +2887 -4094
- 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 +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- 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 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
@@ -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.
|
@@ -19,113 +19,111 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.PDFNodeStream =
|
27
|
+
exports.PDFNodeStream = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var
|
31
|
+
var _network_utils = require("./network_utils.js");
|
32
32
|
|
33
|
-
|
33
|
+
const fs = require("fs");
|
34
34
|
|
35
|
-
|
35
|
+
const http = require("http");
|
36
36
|
|
37
|
-
|
37
|
+
const https = require("https");
|
38
38
|
|
39
|
-
|
39
|
+
const url = require("url");
|
40
40
|
|
41
|
-
|
41
|
+
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
42
42
|
|
43
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
44
|
-
|
45
|
-
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
46
|
-
|
47
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
48
|
-
|
49
|
-
var fs = require('fs');
|
50
|
-
var http = require('http');
|
51
|
-
var https = require('https');
|
52
|
-
var url = require('url');
|
53
|
-
|
54
|
-
var fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
55
43
|
function parseUrl(sourceUrl) {
|
56
|
-
|
57
|
-
|
44
|
+
const parsedUrl = url.parse(sourceUrl);
|
45
|
+
|
46
|
+
if (parsedUrl.protocol === "file:" || parsedUrl.host) {
|
58
47
|
return parsedUrl;
|
59
48
|
}
|
49
|
+
|
60
50
|
if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
|
61
|
-
return url.parse(
|
51
|
+
return url.parse(`file:///${sourceUrl}`);
|
62
52
|
}
|
53
|
+
|
63
54
|
if (!parsedUrl.host) {
|
64
|
-
parsedUrl.protocol =
|
55
|
+
parsedUrl.protocol = "file:";
|
65
56
|
}
|
57
|
+
|
66
58
|
return parsedUrl;
|
67
59
|
}
|
68
60
|
|
69
|
-
|
70
|
-
|
71
|
-
_classCallCheck(this, PDFNodeStream);
|
72
|
-
|
61
|
+
class PDFNodeStream {
|
62
|
+
constructor(source) {
|
73
63
|
this.source = source;
|
74
64
|
this.url = parseUrl(source.url);
|
75
|
-
this.isHttp = this.url.protocol ===
|
76
|
-
this.isFsUrl = this.url.protocol ===
|
65
|
+
this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
|
66
|
+
this.isFsUrl = this.url.protocol === "file:";
|
77
67
|
this.httpHeaders = this.isHttp && source.httpHeaders || {};
|
78
|
-
this.
|
68
|
+
this._fullRequestReader = null;
|
79
69
|
this._rangeRequestReaders = [];
|
80
70
|
}
|
81
71
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
return
|
72
|
+
get _progressiveDataLength() {
|
73
|
+
return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
getFullReader() {
|
77
|
+
(0, _util.assert)(!this._fullRequestReader);
|
78
|
+
this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
|
79
|
+
return this._fullRequestReader;
|
80
|
+
}
|
81
|
+
|
82
|
+
getRangeReader(start, end) {
|
83
|
+
if (end <= this._progressiveDataLength) {
|
84
|
+
return null;
|
95
85
|
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
86
|
+
|
87
|
+
const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
|
88
|
+
|
89
|
+
this._rangeRequestReaders.push(rangeReader);
|
90
|
+
|
91
|
+
return rangeReader;
|
92
|
+
}
|
93
|
+
|
94
|
+
cancelAllRequests(reason) {
|
95
|
+
if (this._fullRequestReader) {
|
96
|
+
this._fullRequestReader.cancel(reason);
|
106
97
|
}
|
107
|
-
}]);
|
108
98
|
|
109
|
-
|
110
|
-
|
99
|
+
const readers = this._rangeRequestReaders.slice(0);
|
100
|
+
|
101
|
+
readers.forEach(function (reader) {
|
102
|
+
reader.cancel(reason);
|
103
|
+
});
|
104
|
+
}
|
105
|
+
|
106
|
+
}
|
111
107
|
|
112
|
-
|
113
|
-
function BaseFullReader(stream) {
|
114
|
-
_classCallCheck(this, BaseFullReader);
|
108
|
+
exports.PDFNodeStream = PDFNodeStream;
|
115
109
|
|
110
|
+
class BaseFullReader {
|
111
|
+
constructor(stream) {
|
116
112
|
this._url = stream.url;
|
117
113
|
this._done = false;
|
118
114
|
this._storedError = null;
|
119
115
|
this.onProgress = null;
|
120
|
-
|
116
|
+
const source = stream.source;
|
121
117
|
this._contentLength = source.length;
|
122
118
|
this._loaded = 0;
|
123
119
|
this._filename = null;
|
124
120
|
this._disableRange = source.disableRange || false;
|
125
121
|
this._rangeChunkSize = source.rangeChunkSize;
|
122
|
+
|
126
123
|
if (!this._rangeChunkSize && !this._disableRange) {
|
127
124
|
this._disableRange = true;
|
128
125
|
}
|
126
|
+
|
129
127
|
this._isStreamingSupported = !source.disableStream;
|
130
128
|
this._isRangeSupported = !source.disableRange;
|
131
129
|
this._readableStream = null;
|
@@ -133,149 +131,107 @@ var BaseFullReader = function () {
|
|
133
131
|
this._headersCapability = (0, _util.createPromiseCapability)();
|
134
132
|
}
|
135
133
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
|
140
|
-
var chunk, buffer;
|
141
|
-
return _regenerator2.default.wrap(function _callee$(_context) {
|
142
|
-
while (1) {
|
143
|
-
switch (_context.prev = _context.next) {
|
144
|
-
case 0:
|
145
|
-
_context.next = 2;
|
146
|
-
return this._readCapability.promise;
|
147
|
-
|
148
|
-
case 2:
|
149
|
-
if (!this._done) {
|
150
|
-
_context.next = 4;
|
151
|
-
break;
|
152
|
-
}
|
153
|
-
|
154
|
-
return _context.abrupt('return', {
|
155
|
-
value: undefined,
|
156
|
-
done: true
|
157
|
-
});
|
158
|
-
|
159
|
-
case 4:
|
160
|
-
if (!this._storedError) {
|
161
|
-
_context.next = 6;
|
162
|
-
break;
|
163
|
-
}
|
164
|
-
|
165
|
-
throw this._storedError;
|
166
|
-
|
167
|
-
case 6:
|
168
|
-
chunk = this._readableStream.read();
|
169
|
-
|
170
|
-
if (!(chunk === null)) {
|
171
|
-
_context.next = 10;
|
172
|
-
break;
|
173
|
-
}
|
174
|
-
|
175
|
-
this._readCapability = (0, _util.createPromiseCapability)();
|
176
|
-
return _context.abrupt('return', this.read());
|
177
|
-
|
178
|
-
case 10:
|
179
|
-
this._loaded += chunk.length;
|
180
|
-
if (this.onProgress) {
|
181
|
-
this.onProgress({
|
182
|
-
loaded: this._loaded,
|
183
|
-
total: this._contentLength
|
184
|
-
});
|
185
|
-
}
|
186
|
-
buffer = new Uint8Array(chunk).buffer;
|
187
|
-
return _context.abrupt('return', {
|
188
|
-
value: buffer,
|
189
|
-
done: false
|
190
|
-
});
|
191
|
-
|
192
|
-
case 14:
|
193
|
-
case 'end':
|
194
|
-
return _context.stop();
|
195
|
-
}
|
196
|
-
}
|
197
|
-
}, _callee, this);
|
198
|
-
}));
|
199
|
-
|
200
|
-
function read() {
|
201
|
-
return _ref.apply(this, arguments);
|
202
|
-
}
|
134
|
+
get headersReady() {
|
135
|
+
return this._headersCapability.promise;
|
136
|
+
}
|
203
137
|
|
204
|
-
|
205
|
-
|
206
|
-
}
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
_this._readCapability.resolve();
|
229
|
-
});
|
230
|
-
readableStream.on('end', function () {
|
231
|
-
readableStream.destroy();
|
232
|
-
_this._done = true;
|
233
|
-
_this._readCapability.resolve();
|
234
|
-
});
|
235
|
-
readableStream.on('error', function (reason) {
|
236
|
-
_this._error(reason);
|
237
|
-
});
|
238
|
-
if (!this._isStreamingSupported && this._isRangeSupported) {
|
239
|
-
this._error(new _util.AbortException('streaming is disabled'));
|
240
|
-
}
|
241
|
-
if (this._storedError) {
|
242
|
-
this._readableStream.destroy(this._storedError);
|
243
|
-
}
|
138
|
+
get filename() {
|
139
|
+
return this._filename;
|
140
|
+
}
|
141
|
+
|
142
|
+
get contentLength() {
|
143
|
+
return this._contentLength;
|
144
|
+
}
|
145
|
+
|
146
|
+
get isRangeSupported() {
|
147
|
+
return this._isRangeSupported;
|
148
|
+
}
|
149
|
+
|
150
|
+
get isStreamingSupported() {
|
151
|
+
return this._isStreamingSupported;
|
152
|
+
}
|
153
|
+
|
154
|
+
async read() {
|
155
|
+
await this._readCapability.promise;
|
156
|
+
|
157
|
+
if (this._done) {
|
158
|
+
return {
|
159
|
+
value: undefined,
|
160
|
+
done: true
|
161
|
+
};
|
244
162
|
}
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
return this._headersCapability.promise;
|
163
|
+
|
164
|
+
if (this._storedError) {
|
165
|
+
throw this._storedError;
|
249
166
|
}
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
167
|
+
|
168
|
+
const chunk = this._readableStream.read();
|
169
|
+
|
170
|
+
if (chunk === null) {
|
171
|
+
this._readCapability = (0, _util.createPromiseCapability)();
|
172
|
+
return this.read();
|
254
173
|
}
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
174
|
+
|
175
|
+
this._loaded += chunk.length;
|
176
|
+
|
177
|
+
if (this.onProgress) {
|
178
|
+
this.onProgress({
|
179
|
+
loaded: this._loaded,
|
180
|
+
total: this._contentLength
|
181
|
+
});
|
259
182
|
}
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
183
|
+
|
184
|
+
const buffer = new Uint8Array(chunk).buffer;
|
185
|
+
return {
|
186
|
+
value: buffer,
|
187
|
+
done: false
|
188
|
+
};
|
189
|
+
}
|
190
|
+
|
191
|
+
cancel(reason) {
|
192
|
+
if (!this._readableStream) {
|
193
|
+
this._error(reason);
|
194
|
+
|
195
|
+
return;
|
264
196
|
}
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
197
|
+
|
198
|
+
this._readableStream.destroy(reason);
|
199
|
+
}
|
200
|
+
|
201
|
+
_error(reason) {
|
202
|
+
this._storedError = reason;
|
203
|
+
|
204
|
+
this._readCapability.resolve();
|
205
|
+
}
|
206
|
+
|
207
|
+
_setReadableStream(readableStream) {
|
208
|
+
this._readableStream = readableStream;
|
209
|
+
readableStream.on("readable", () => {
|
210
|
+
this._readCapability.resolve();
|
211
|
+
});
|
212
|
+
readableStream.on("end", () => {
|
213
|
+
readableStream.destroy();
|
214
|
+
this._done = true;
|
215
|
+
|
216
|
+
this._readCapability.resolve();
|
217
|
+
});
|
218
|
+
readableStream.on("error", reason => {
|
219
|
+
this._error(reason);
|
220
|
+
});
|
221
|
+
|
222
|
+
if (!this._isStreamingSupported && this._isRangeSupported) {
|
223
|
+
this._error(new _util.AbortException("streaming is disabled"));
|
269
224
|
}
|
270
|
-
}]);
|
271
225
|
|
272
|
-
|
273
|
-
|
226
|
+
if (this._storedError) {
|
227
|
+
this._readableStream.destroy(this._storedError);
|
228
|
+
}
|
229
|
+
}
|
274
230
|
|
275
|
-
|
276
|
-
function BaseRangeReader(stream) {
|
277
|
-
_classCallCheck(this, BaseRangeReader);
|
231
|
+
}
|
278
232
|
|
233
|
+
class BaseRangeReader {
|
234
|
+
constructor(stream) {
|
279
235
|
this._url = stream.url;
|
280
236
|
this._done = false;
|
281
237
|
this._storedError = null;
|
@@ -283,122 +239,87 @@ var BaseRangeReader = function () {
|
|
283
239
|
this._loaded = 0;
|
284
240
|
this._readableStream = null;
|
285
241
|
this._readCapability = (0, _util.createPromiseCapability)();
|
286
|
-
|
242
|
+
const source = stream.source;
|
287
243
|
this._isStreamingSupported = !source.disableStream;
|
288
244
|
}
|
289
245
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
|
294
|
-
var chunk, buffer;
|
295
|
-
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
296
|
-
while (1) {
|
297
|
-
switch (_context2.prev = _context2.next) {
|
298
|
-
case 0:
|
299
|
-
_context2.next = 2;
|
300
|
-
return this._readCapability.promise;
|
301
|
-
|
302
|
-
case 2:
|
303
|
-
if (!this._done) {
|
304
|
-
_context2.next = 4;
|
305
|
-
break;
|
306
|
-
}
|
307
|
-
|
308
|
-
return _context2.abrupt('return', {
|
309
|
-
value: undefined,
|
310
|
-
done: true
|
311
|
-
});
|
312
|
-
|
313
|
-
case 4:
|
314
|
-
if (!this._storedError) {
|
315
|
-
_context2.next = 6;
|
316
|
-
break;
|
317
|
-
}
|
318
|
-
|
319
|
-
throw this._storedError;
|
320
|
-
|
321
|
-
case 6:
|
322
|
-
chunk = this._readableStream.read();
|
323
|
-
|
324
|
-
if (!(chunk === null)) {
|
325
|
-
_context2.next = 10;
|
326
|
-
break;
|
327
|
-
}
|
328
|
-
|
329
|
-
this._readCapability = (0, _util.createPromiseCapability)();
|
330
|
-
return _context2.abrupt('return', this.read());
|
331
|
-
|
332
|
-
case 10:
|
333
|
-
this._loaded += chunk.length;
|
334
|
-
if (this.onProgress) {
|
335
|
-
this.onProgress({ loaded: this._loaded });
|
336
|
-
}
|
337
|
-
buffer = new Uint8Array(chunk).buffer;
|
338
|
-
return _context2.abrupt('return', {
|
339
|
-
value: buffer,
|
340
|
-
done: false
|
341
|
-
});
|
342
|
-
|
343
|
-
case 14:
|
344
|
-
case 'end':
|
345
|
-
return _context2.stop();
|
346
|
-
}
|
347
|
-
}
|
348
|
-
}, _callee2, this);
|
349
|
-
}));
|
350
|
-
|
351
|
-
function read() {
|
352
|
-
return _ref2.apply(this, arguments);
|
353
|
-
}
|
246
|
+
get isStreamingSupported() {
|
247
|
+
return this._isStreamingSupported;
|
248
|
+
}
|
354
249
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
}
|
364
|
-
this._readableStream.destroy(reason);
|
250
|
+
async read() {
|
251
|
+
await this._readCapability.promise;
|
252
|
+
|
253
|
+
if (this._done) {
|
254
|
+
return {
|
255
|
+
value: undefined,
|
256
|
+
done: true
|
257
|
+
};
|
365
258
|
}
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
this._storedError = reason;
|
370
|
-
this._readCapability.resolve();
|
259
|
+
|
260
|
+
if (this._storedError) {
|
261
|
+
throw this._storedError;
|
371
262
|
}
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
this.
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
});
|
386
|
-
readableStream.on('error', function (reason) {
|
387
|
-
_this2._error(reason);
|
263
|
+
|
264
|
+
const chunk = this._readableStream.read();
|
265
|
+
|
266
|
+
if (chunk === null) {
|
267
|
+
this._readCapability = (0, _util.createPromiseCapability)();
|
268
|
+
return this.read();
|
269
|
+
}
|
270
|
+
|
271
|
+
this._loaded += chunk.length;
|
272
|
+
|
273
|
+
if (this.onProgress) {
|
274
|
+
this.onProgress({
|
275
|
+
loaded: this._loaded
|
388
276
|
});
|
389
|
-
if (this._storedError) {
|
390
|
-
this._readableStream.destroy(this._storedError);
|
391
|
-
}
|
392
277
|
}
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
278
|
+
|
279
|
+
const buffer = new Uint8Array(chunk).buffer;
|
280
|
+
return {
|
281
|
+
value: buffer,
|
282
|
+
done: false
|
283
|
+
};
|
284
|
+
}
|
285
|
+
|
286
|
+
cancel(reason) {
|
287
|
+
if (!this._readableStream) {
|
288
|
+
this._error(reason);
|
289
|
+
|
290
|
+
return;
|
397
291
|
}
|
398
|
-
}]);
|
399
292
|
|
400
|
-
|
401
|
-
}
|
293
|
+
this._readableStream.destroy(reason);
|
294
|
+
}
|
295
|
+
|
296
|
+
_error(reason) {
|
297
|
+
this._storedError = reason;
|
298
|
+
|
299
|
+
this._readCapability.resolve();
|
300
|
+
}
|
301
|
+
|
302
|
+
_setReadableStream(readableStream) {
|
303
|
+
this._readableStream = readableStream;
|
304
|
+
readableStream.on("readable", () => {
|
305
|
+
this._readCapability.resolve();
|
306
|
+
});
|
307
|
+
readableStream.on("end", () => {
|
308
|
+
readableStream.destroy();
|
309
|
+
this._done = true;
|
310
|
+
|
311
|
+
this._readCapability.resolve();
|
312
|
+
});
|
313
|
+
readableStream.on("error", reason => {
|
314
|
+
this._error(reason);
|
315
|
+
});
|
316
|
+
|
317
|
+
if (this._storedError) {
|
318
|
+
this._readableStream.destroy(this._storedError);
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
}
|
402
323
|
|
403
324
|
function createRequestOptions(url, headers) {
|
404
325
|
return {
|
@@ -407,154 +328,155 @@ function createRequestOptions(url, headers) {
|
|
407
328
|
host: url.hostname,
|
408
329
|
port: url.port,
|
409
330
|
path: url.path,
|
410
|
-
method:
|
411
|
-
headers
|
331
|
+
method: "GET",
|
332
|
+
headers
|
412
333
|
};
|
413
334
|
}
|
414
335
|
|
415
|
-
|
416
|
-
|
336
|
+
class PDFNodeStreamFullReader extends BaseFullReader {
|
337
|
+
constructor(stream) {
|
338
|
+
super(stream);
|
417
339
|
|
418
|
-
|
419
|
-
|
340
|
+
const handleResponse = response => {
|
341
|
+
if (response.statusCode === 404) {
|
342
|
+
const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
343
|
+
this._storedError = error;
|
420
344
|
|
421
|
-
|
345
|
+
this._headersCapability.reject(error);
|
422
346
|
|
423
|
-
var handleResponse = function handleResponse(response) {
|
424
|
-
if (response.statusCode === 404) {
|
425
|
-
var error = new _util.MissingPDFException('Missing PDF "' + _this3._url + '".');
|
426
|
-
_this3._storedError = error;
|
427
|
-
_this3._headersCapability.reject(error);
|
428
347
|
return;
|
429
348
|
}
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
349
|
+
|
350
|
+
this._headersCapability.resolve();
|
351
|
+
|
352
|
+
this._setReadableStream(response);
|
353
|
+
|
354
|
+
const getResponseHeader = name => {
|
355
|
+
return this._readableStream.headers[name.toLowerCase()];
|
434
356
|
};
|
435
357
|
|
436
|
-
|
437
|
-
|
358
|
+
const {
|
359
|
+
allowRangeRequests,
|
360
|
+
suggestedLength
|
361
|
+
} = (0, _network_utils.validateRangeRequestCapabilities)({
|
362
|
+
getResponseHeader,
|
438
363
|
isHttp: stream.isHttp,
|
439
|
-
rangeChunkSize:
|
440
|
-
disableRange:
|
441
|
-
})
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
_this3._isRangeSupported = allowRangeRequests;
|
446
|
-
_this3._contentLength = suggestedLength || _this3._contentLength;
|
447
|
-
_this3._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
364
|
+
rangeChunkSize: this._rangeChunkSize,
|
365
|
+
disableRange: this._disableRange
|
366
|
+
});
|
367
|
+
this._isRangeSupported = allowRangeRequests;
|
368
|
+
this._contentLength = suggestedLength || this._contentLength;
|
369
|
+
this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
448
370
|
};
|
449
|
-
|
450
|
-
|
451
|
-
|
371
|
+
|
372
|
+
this._request = null;
|
373
|
+
|
374
|
+
if (this._url.protocol === "http:") {
|
375
|
+
this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
452
376
|
} else {
|
453
|
-
|
377
|
+
this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
454
378
|
}
|
455
|
-
|
456
|
-
|
457
|
-
|
379
|
+
|
380
|
+
this._request.on("error", reason => {
|
381
|
+
this._storedError = reason;
|
382
|
+
|
383
|
+
this._headersCapability.reject(reason);
|
458
384
|
});
|
459
|
-
_this3._request.end();
|
460
|
-
return _this3;
|
461
|
-
}
|
462
385
|
|
463
|
-
|
464
|
-
}
|
386
|
+
this._request.end();
|
387
|
+
}
|
465
388
|
|
466
|
-
|
467
|
-
_inherits(PDFNodeStreamRangeReader, _BaseRangeReader);
|
389
|
+
}
|
468
390
|
|
469
|
-
|
470
|
-
|
391
|
+
class PDFNodeStreamRangeReader extends BaseRangeReader {
|
392
|
+
constructor(stream, start, end) {
|
393
|
+
super(stream);
|
394
|
+
this._httpHeaders = {};
|
471
395
|
|
472
|
-
|
396
|
+
for (const property in stream.httpHeaders) {
|
397
|
+
const value = stream.httpHeaders[property];
|
473
398
|
|
474
|
-
|
475
|
-
for (var property in stream.httpHeaders) {
|
476
|
-
var value = stream.httpHeaders[property];
|
477
|
-
if (typeof value === 'undefined') {
|
399
|
+
if (typeof value === "undefined") {
|
478
400
|
continue;
|
479
401
|
}
|
480
|
-
|
402
|
+
|
403
|
+
this._httpHeaders[property] = value;
|
481
404
|
}
|
482
|
-
|
483
|
-
|
405
|
+
|
406
|
+
this._httpHeaders["Range"] = `bytes=${start}-${end - 1}`;
|
407
|
+
|
408
|
+
const handleResponse = response => {
|
484
409
|
if (response.statusCode === 404) {
|
485
|
-
|
486
|
-
|
410
|
+
const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
411
|
+
this._storedError = error;
|
487
412
|
return;
|
488
413
|
}
|
489
|
-
|
414
|
+
|
415
|
+
this._setReadableStream(response);
|
490
416
|
};
|
491
|
-
|
492
|
-
|
493
|
-
|
417
|
+
|
418
|
+
this._request = null;
|
419
|
+
|
420
|
+
if (this._url.protocol === "http:") {
|
421
|
+
this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
494
422
|
} else {
|
495
|
-
|
423
|
+
this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
496
424
|
}
|
497
|
-
_this4._request.on('error', function (reason) {
|
498
|
-
_this4._storedError = reason;
|
499
|
-
});
|
500
|
-
_this4._request.end();
|
501
|
-
return _this4;
|
502
|
-
}
|
503
425
|
|
504
|
-
|
505
|
-
|
426
|
+
this._request.on("error", reason => {
|
427
|
+
this._storedError = reason;
|
428
|
+
});
|
506
429
|
|
507
|
-
|
508
|
-
|
430
|
+
this._request.end();
|
431
|
+
}
|
509
432
|
|
510
|
-
|
511
|
-
_classCallCheck(this, PDFNodeStreamFsFullReader);
|
433
|
+
}
|
512
434
|
|
513
|
-
|
435
|
+
class PDFNodeStreamFsFullReader extends BaseFullReader {
|
436
|
+
constructor(stream) {
|
437
|
+
super(stream);
|
438
|
+
let path = decodeURIComponent(this._url.path);
|
514
439
|
|
515
|
-
|
516
|
-
|
517
|
-
path = path.replace(/^\//, '');
|
440
|
+
if (fileUriRegex.test(this._url.href)) {
|
441
|
+
path = path.replace(/^\//, "");
|
518
442
|
}
|
519
|
-
|
443
|
+
|
444
|
+
fs.lstat(path, (error, stat) => {
|
520
445
|
if (error) {
|
521
|
-
if (error.code ===
|
522
|
-
error = new _util.MissingPDFException(
|
446
|
+
if (error.code === "ENOENT") {
|
447
|
+
error = new _util.MissingPDFException(`Missing PDF "${path}".`);
|
523
448
|
}
|
524
|
-
|
525
|
-
|
449
|
+
|
450
|
+
this._storedError = error;
|
451
|
+
|
452
|
+
this._headersCapability.reject(error);
|
453
|
+
|
526
454
|
return;
|
527
455
|
}
|
528
|
-
_this5._contentLength = stat.size;
|
529
|
-
_this5._setReadableStream(fs.createReadStream(path));
|
530
|
-
_this5._headersCapability.resolve();
|
531
|
-
});
|
532
|
-
return _this5;
|
533
|
-
}
|
534
456
|
|
535
|
-
|
536
|
-
}(BaseFullReader);
|
457
|
+
this._contentLength = stat.size;
|
537
458
|
|
538
|
-
|
539
|
-
_inherits(PDFNodeStreamFsRangeReader, _BaseRangeReader2);
|
459
|
+
this._setReadableStream(fs.createReadStream(path));
|
540
460
|
|
541
|
-
|
542
|
-
|
461
|
+
this._headersCapability.resolve();
|
462
|
+
});
|
463
|
+
}
|
543
464
|
|
544
|
-
|
465
|
+
}
|
466
|
+
|
467
|
+
class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
468
|
+
constructor(stream, start, end) {
|
469
|
+
super(stream);
|
470
|
+
let path = decodeURIComponent(this._url.path);
|
545
471
|
|
546
|
-
|
547
|
-
|
548
|
-
path = path.replace(/^\//, '');
|
472
|
+
if (fileUriRegex.test(this._url.href)) {
|
473
|
+
path = path.replace(/^\//, "");
|
549
474
|
}
|
550
|
-
|
551
|
-
|
475
|
+
|
476
|
+
this._setReadableStream(fs.createReadStream(path, {
|
477
|
+
start,
|
552
478
|
end: end - 1
|
553
479
|
}));
|
554
|
-
return _this6;
|
555
480
|
}
|
556
481
|
|
557
|
-
|
558
|
-
}(BaseRangeReader);
|
559
|
-
|
560
|
-
exports.PDFNodeStream = PDFNodeStream;
|
482
|
+
}
|