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,126 +26,96 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
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
|
+
;
|
34
34
|
|
35
|
-
|
35
|
+
const fs = require("fs");
|
36
36
|
|
37
|
-
|
37
|
+
const http = require("http");
|
38
38
|
|
39
|
-
|
39
|
+
const https = require("https");
|
40
40
|
|
41
|
-
|
41
|
+
const url = require("url");
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
46
|
-
|
47
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
48
|
-
|
49
|
-
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); } }
|
50
|
-
|
51
|
-
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); }); }; }
|
52
|
-
|
53
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
54
|
-
|
55
|
-
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); } }
|
56
|
-
|
57
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
58
|
-
|
59
|
-
var fs = require('fs');
|
60
|
-
|
61
|
-
var http = require('http');
|
62
|
-
|
63
|
-
var https = require('https');
|
64
|
-
|
65
|
-
var url = require('url');
|
66
|
-
|
67
|
-
var fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
43
|
+
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
68
44
|
|
69
45
|
function parseUrl(sourceUrl) {
|
70
|
-
|
46
|
+
const parsedUrl = url.parse(sourceUrl);
|
71
47
|
|
72
|
-
if (parsedUrl.protocol ===
|
48
|
+
if (parsedUrl.protocol === "file:" || parsedUrl.host) {
|
73
49
|
return parsedUrl;
|
74
50
|
}
|
75
51
|
|
76
52
|
if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
|
77
|
-
return url.parse(
|
53
|
+
return url.parse(`file:///${sourceUrl}`);
|
78
54
|
}
|
79
55
|
|
80
56
|
if (!parsedUrl.host) {
|
81
|
-
parsedUrl.protocol =
|
57
|
+
parsedUrl.protocol = "file:";
|
82
58
|
}
|
83
59
|
|
84
60
|
return parsedUrl;
|
85
61
|
}
|
86
62
|
|
87
|
-
|
88
|
-
|
89
|
-
function () {
|
90
|
-
function PDFNodeStream(source) {
|
91
|
-
_classCallCheck(this, PDFNodeStream);
|
92
|
-
|
63
|
+
class PDFNodeStream {
|
64
|
+
constructor(source) {
|
93
65
|
this.source = source;
|
94
66
|
this.url = parseUrl(source.url);
|
95
|
-
this.isHttp = this.url.protocol ===
|
96
|
-
this.isFsUrl = this.url.protocol ===
|
67
|
+
this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
|
68
|
+
this.isFsUrl = this.url.protocol === "file:";
|
97
69
|
this.httpHeaders = this.isHttp && source.httpHeaders || {};
|
98
|
-
this.
|
70
|
+
this._fullRequestReader = null;
|
99
71
|
this._rangeRequestReaders = [];
|
100
72
|
}
|
101
73
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
(0, _util.assert)(!this._fullRequest);
|
106
|
-
this._fullRequest = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
|
107
|
-
return this._fullRequest;
|
108
|
-
}
|
109
|
-
}, {
|
110
|
-
key: "getRangeReader",
|
111
|
-
value: function getRangeReader(start, end) {
|
112
|
-
var rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
|
74
|
+
get _progressiveDataLength() {
|
75
|
+
return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
|
76
|
+
}
|
113
77
|
|
114
|
-
|
78
|
+
getFullReader() {
|
79
|
+
(0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
|
80
|
+
this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
|
81
|
+
return this._fullRequestReader;
|
82
|
+
}
|
115
83
|
|
116
|
-
|
84
|
+
getRangeReader(start, end) {
|
85
|
+
if (end <= this._progressiveDataLength) {
|
86
|
+
return null;
|
117
87
|
}
|
118
|
-
}, {
|
119
|
-
key: "cancelAllRequests",
|
120
|
-
value: function cancelAllRequests(reason) {
|
121
|
-
if (this._fullRequest) {
|
122
|
-
this._fullRequest.cancel(reason);
|
123
|
-
}
|
124
88
|
|
125
|
-
|
89
|
+
const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
|
126
90
|
|
127
|
-
|
128
|
-
|
129
|
-
|
91
|
+
this._rangeRequestReaders.push(rangeReader);
|
92
|
+
|
93
|
+
return rangeReader;
|
94
|
+
}
|
95
|
+
|
96
|
+
cancelAllRequests(reason) {
|
97
|
+
if (this._fullRequestReader) {
|
98
|
+
this._fullRequestReader.cancel(reason);
|
130
99
|
}
|
131
|
-
}]);
|
132
100
|
|
133
|
-
|
134
|
-
}();
|
101
|
+
const readers = this._rangeRequestReaders.slice(0);
|
135
102
|
|
136
|
-
|
103
|
+
readers.forEach(function (reader) {
|
104
|
+
reader.cancel(reason);
|
105
|
+
});
|
106
|
+
}
|
137
107
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
function BaseFullReader(stream) {
|
142
|
-
_classCallCheck(this, BaseFullReader);
|
108
|
+
}
|
109
|
+
|
110
|
+
exports.PDFNodeStream = PDFNodeStream;
|
143
111
|
|
112
|
+
class BaseFullReader {
|
113
|
+
constructor(stream) {
|
144
114
|
this._url = stream.url;
|
145
115
|
this._done = false;
|
146
116
|
this._storedError = null;
|
147
117
|
this.onProgress = null;
|
148
|
-
|
118
|
+
const source = stream.source;
|
149
119
|
this._contentLength = source.length;
|
150
120
|
this._loaded = 0;
|
151
121
|
this._filename = null;
|
@@ -163,161 +133,107 @@ function () {
|
|
163
133
|
this._headersCapability = (0, _util.createPromiseCapability)();
|
164
134
|
}
|
165
135
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
var _read = _asyncToGenerator(
|
170
|
-
/*#__PURE__*/
|
171
|
-
_regenerator.default.mark(function _callee() {
|
172
|
-
var chunk, buffer;
|
173
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
174
|
-
while (1) {
|
175
|
-
switch (_context.prev = _context.next) {
|
176
|
-
case 0:
|
177
|
-
_context.next = 2;
|
178
|
-
return this._readCapability.promise;
|
179
|
-
|
180
|
-
case 2:
|
181
|
-
if (!this._done) {
|
182
|
-
_context.next = 4;
|
183
|
-
break;
|
184
|
-
}
|
185
|
-
|
186
|
-
return _context.abrupt("return", {
|
187
|
-
value: undefined,
|
188
|
-
done: true
|
189
|
-
});
|
190
|
-
|
191
|
-
case 4:
|
192
|
-
if (!this._storedError) {
|
193
|
-
_context.next = 6;
|
194
|
-
break;
|
195
|
-
}
|
196
|
-
|
197
|
-
throw this._storedError;
|
198
|
-
|
199
|
-
case 6:
|
200
|
-
chunk = this._readableStream.read();
|
201
|
-
|
202
|
-
if (!(chunk === null)) {
|
203
|
-
_context.next = 10;
|
204
|
-
break;
|
205
|
-
}
|
206
|
-
|
207
|
-
this._readCapability = (0, _util.createPromiseCapability)();
|
208
|
-
return _context.abrupt("return", this.read());
|
209
|
-
|
210
|
-
case 10:
|
211
|
-
this._loaded += chunk.length;
|
212
|
-
|
213
|
-
if (this.onProgress) {
|
214
|
-
this.onProgress({
|
215
|
-
loaded: this._loaded,
|
216
|
-
total: this._contentLength
|
217
|
-
});
|
218
|
-
}
|
219
|
-
|
220
|
-
buffer = new Uint8Array(chunk).buffer;
|
221
|
-
return _context.abrupt("return", {
|
222
|
-
value: buffer,
|
223
|
-
done: false
|
224
|
-
});
|
225
|
-
|
226
|
-
case 14:
|
227
|
-
case "end":
|
228
|
-
return _context.stop();
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}, _callee, this);
|
232
|
-
}));
|
233
|
-
|
234
|
-
function read() {
|
235
|
-
return _read.apply(this, arguments);
|
236
|
-
}
|
237
|
-
|
238
|
-
return read;
|
239
|
-
}()
|
240
|
-
}, {
|
241
|
-
key: "cancel",
|
242
|
-
value: function cancel(reason) {
|
243
|
-
if (!this._readableStream) {
|
244
|
-
this._error(reason);
|
136
|
+
get headersReady() {
|
137
|
+
return this._headersCapability.promise;
|
138
|
+
}
|
245
139
|
|
246
|
-
|
247
|
-
|
140
|
+
get filename() {
|
141
|
+
return this._filename;
|
142
|
+
}
|
248
143
|
|
249
|
-
|
250
|
-
|
251
|
-
}
|
252
|
-
key: "_error",
|
253
|
-
value: function _error(reason) {
|
254
|
-
this._storedError = reason;
|
144
|
+
get contentLength() {
|
145
|
+
return this._contentLength;
|
146
|
+
}
|
255
147
|
|
256
|
-
|
257
|
-
|
258
|
-
}
|
259
|
-
key: "_setReadableStream",
|
260
|
-
value: function _setReadableStream(readableStream) {
|
261
|
-
var _this = this;
|
262
|
-
|
263
|
-
this._readableStream = readableStream;
|
264
|
-
readableStream.on('readable', function () {
|
265
|
-
_this._readCapability.resolve();
|
266
|
-
});
|
267
|
-
readableStream.on('end', function () {
|
268
|
-
readableStream.destroy();
|
269
|
-
_this._done = true;
|
148
|
+
get isRangeSupported() {
|
149
|
+
return this._isRangeSupported;
|
150
|
+
}
|
270
151
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
_this._error(reason);
|
275
|
-
});
|
152
|
+
get isStreamingSupported() {
|
153
|
+
return this._isStreamingSupported;
|
154
|
+
}
|
276
155
|
|
277
|
-
|
278
|
-
|
279
|
-
}
|
156
|
+
async read() {
|
157
|
+
await this._readCapability.promise;
|
280
158
|
|
281
|
-
|
282
|
-
|
283
|
-
|
159
|
+
if (this._done) {
|
160
|
+
return {
|
161
|
+
value: undefined,
|
162
|
+
done: true
|
163
|
+
};
|
284
164
|
}
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
return this._headersCapability.promise;
|
165
|
+
|
166
|
+
if (this._storedError) {
|
167
|
+
throw this._storedError;
|
289
168
|
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
169
|
+
|
170
|
+
const chunk = this._readableStream.read();
|
171
|
+
|
172
|
+
if (chunk === null) {
|
173
|
+
this._readCapability = (0, _util.createPromiseCapability)();
|
174
|
+
return this.read();
|
294
175
|
}
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
176
|
+
|
177
|
+
this._loaded += chunk.length;
|
178
|
+
|
179
|
+
if (this.onProgress) {
|
180
|
+
this.onProgress({
|
181
|
+
loaded: this._loaded,
|
182
|
+
total: this._contentLength
|
183
|
+
});
|
299
184
|
}
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
185
|
+
|
186
|
+
const buffer = new Uint8Array(chunk).buffer;
|
187
|
+
return {
|
188
|
+
value: buffer,
|
189
|
+
done: false
|
190
|
+
};
|
191
|
+
}
|
192
|
+
|
193
|
+
cancel(reason) {
|
194
|
+
if (!this._readableStream) {
|
195
|
+
this._error(reason);
|
196
|
+
|
197
|
+
return;
|
304
198
|
}
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
199
|
+
|
200
|
+
this._readableStream.destroy(reason);
|
201
|
+
}
|
202
|
+
|
203
|
+
_error(reason) {
|
204
|
+
this._storedError = reason;
|
205
|
+
|
206
|
+
this._readCapability.resolve();
|
207
|
+
}
|
208
|
+
|
209
|
+
_setReadableStream(readableStream) {
|
210
|
+
this._readableStream = readableStream;
|
211
|
+
readableStream.on("readable", () => {
|
212
|
+
this._readCapability.resolve();
|
213
|
+
});
|
214
|
+
readableStream.on("end", () => {
|
215
|
+
readableStream.destroy();
|
216
|
+
this._done = true;
|
217
|
+
|
218
|
+
this._readCapability.resolve();
|
219
|
+
});
|
220
|
+
readableStream.on("error", reason => {
|
221
|
+
this._error(reason);
|
222
|
+
});
|
223
|
+
|
224
|
+
if (!this._isStreamingSupported && this._isRangeSupported) {
|
225
|
+
this._error(new _util.AbortException("streaming is disabled"));
|
309
226
|
}
|
310
|
-
}]);
|
311
227
|
|
312
|
-
|
313
|
-
|
228
|
+
if (this._storedError) {
|
229
|
+
this._readableStream.destroy(this._storedError);
|
230
|
+
}
|
231
|
+
}
|
314
232
|
|
315
|
-
|
316
|
-
/*#__PURE__*/
|
317
|
-
function () {
|
318
|
-
function BaseRangeReader(stream) {
|
319
|
-
_classCallCheck(this, BaseRangeReader);
|
233
|
+
}
|
320
234
|
|
235
|
+
class BaseRangeReader {
|
236
|
+
constructor(stream) {
|
321
237
|
this._url = stream.url;
|
322
238
|
this._done = false;
|
323
239
|
this._storedError = null;
|
@@ -325,333 +241,244 @@ function () {
|
|
325
241
|
this._loaded = 0;
|
326
242
|
this._readableStream = null;
|
327
243
|
this._readCapability = (0, _util.createPromiseCapability)();
|
328
|
-
|
244
|
+
const source = stream.source;
|
329
245
|
this._isStreamingSupported = !source.disableStream;
|
330
246
|
}
|
331
247
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
var _read2 = _asyncToGenerator(
|
336
|
-
/*#__PURE__*/
|
337
|
-
_regenerator.default.mark(function _callee2() {
|
338
|
-
var chunk, buffer;
|
339
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
340
|
-
while (1) {
|
341
|
-
switch (_context2.prev = _context2.next) {
|
342
|
-
case 0:
|
343
|
-
_context2.next = 2;
|
344
|
-
return this._readCapability.promise;
|
345
|
-
|
346
|
-
case 2:
|
347
|
-
if (!this._done) {
|
348
|
-
_context2.next = 4;
|
349
|
-
break;
|
350
|
-
}
|
351
|
-
|
352
|
-
return _context2.abrupt("return", {
|
353
|
-
value: undefined,
|
354
|
-
done: true
|
355
|
-
});
|
356
|
-
|
357
|
-
case 4:
|
358
|
-
if (!this._storedError) {
|
359
|
-
_context2.next = 6;
|
360
|
-
break;
|
361
|
-
}
|
362
|
-
|
363
|
-
throw this._storedError;
|
364
|
-
|
365
|
-
case 6:
|
366
|
-
chunk = this._readableStream.read();
|
367
|
-
|
368
|
-
if (!(chunk === null)) {
|
369
|
-
_context2.next = 10;
|
370
|
-
break;
|
371
|
-
}
|
372
|
-
|
373
|
-
this._readCapability = (0, _util.createPromiseCapability)();
|
374
|
-
return _context2.abrupt("return", this.read());
|
375
|
-
|
376
|
-
case 10:
|
377
|
-
this._loaded += chunk.length;
|
378
|
-
|
379
|
-
if (this.onProgress) {
|
380
|
-
this.onProgress({
|
381
|
-
loaded: this._loaded
|
382
|
-
});
|
383
|
-
}
|
384
|
-
|
385
|
-
buffer = new Uint8Array(chunk).buffer;
|
386
|
-
return _context2.abrupt("return", {
|
387
|
-
value: buffer,
|
388
|
-
done: false
|
389
|
-
});
|
390
|
-
|
391
|
-
case 14:
|
392
|
-
case "end":
|
393
|
-
return _context2.stop();
|
394
|
-
}
|
395
|
-
}
|
396
|
-
}, _callee2, this);
|
397
|
-
}));
|
398
|
-
|
399
|
-
function read() {
|
400
|
-
return _read2.apply(this, arguments);
|
401
|
-
}
|
248
|
+
get isStreamingSupported() {
|
249
|
+
return this._isStreamingSupported;
|
250
|
+
}
|
402
251
|
|
403
|
-
|
404
|
-
|
405
|
-
}, {
|
406
|
-
key: "cancel",
|
407
|
-
value: function cancel(reason) {
|
408
|
-
if (!this._readableStream) {
|
409
|
-
this._error(reason);
|
252
|
+
async read() {
|
253
|
+
await this._readCapability.promise;
|
410
254
|
|
411
|
-
|
412
|
-
|
255
|
+
if (this._done) {
|
256
|
+
return {
|
257
|
+
value: undefined,
|
258
|
+
done: true
|
259
|
+
};
|
260
|
+
}
|
413
261
|
|
414
|
-
|
262
|
+
if (this._storedError) {
|
263
|
+
throw this._storedError;
|
415
264
|
}
|
416
|
-
}, {
|
417
|
-
key: "_error",
|
418
|
-
value: function _error(reason) {
|
419
|
-
this._storedError = reason;
|
420
265
|
|
421
|
-
|
266
|
+
const chunk = this._readableStream.read();
|
267
|
+
|
268
|
+
if (chunk === null) {
|
269
|
+
this._readCapability = (0, _util.createPromiseCapability)();
|
270
|
+
return this.read();
|
422
271
|
}
|
423
|
-
}, {
|
424
|
-
key: "_setReadableStream",
|
425
|
-
value: function _setReadableStream(readableStream) {
|
426
|
-
var _this2 = this;
|
427
|
-
|
428
|
-
this._readableStream = readableStream;
|
429
|
-
readableStream.on('readable', function () {
|
430
|
-
_this2._readCapability.resolve();
|
431
|
-
});
|
432
|
-
readableStream.on('end', function () {
|
433
|
-
readableStream.destroy();
|
434
|
-
_this2._done = true;
|
435
272
|
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
273
|
+
this._loaded += chunk.length;
|
274
|
+
|
275
|
+
if (this.onProgress) {
|
276
|
+
this.onProgress({
|
277
|
+
loaded: this._loaded
|
440
278
|
});
|
279
|
+
}
|
441
280
|
|
442
|
-
|
443
|
-
|
444
|
-
|
281
|
+
const buffer = new Uint8Array(chunk).buffer;
|
282
|
+
return {
|
283
|
+
value: buffer,
|
284
|
+
done: false
|
285
|
+
};
|
286
|
+
}
|
287
|
+
|
288
|
+
cancel(reason) {
|
289
|
+
if (!this._readableStream) {
|
290
|
+
this._error(reason);
|
291
|
+
|
292
|
+
return;
|
445
293
|
}
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
294
|
+
|
295
|
+
this._readableStream.destroy(reason);
|
296
|
+
}
|
297
|
+
|
298
|
+
_error(reason) {
|
299
|
+
this._storedError = reason;
|
300
|
+
|
301
|
+
this._readCapability.resolve();
|
302
|
+
}
|
303
|
+
|
304
|
+
_setReadableStream(readableStream) {
|
305
|
+
this._readableStream = readableStream;
|
306
|
+
readableStream.on("readable", () => {
|
307
|
+
this._readCapability.resolve();
|
308
|
+
});
|
309
|
+
readableStream.on("end", () => {
|
310
|
+
readableStream.destroy();
|
311
|
+
this._done = true;
|
312
|
+
|
313
|
+
this._readCapability.resolve();
|
314
|
+
});
|
315
|
+
readableStream.on("error", reason => {
|
316
|
+
this._error(reason);
|
317
|
+
});
|
318
|
+
|
319
|
+
if (this._storedError) {
|
320
|
+
this._readableStream.destroy(this._storedError);
|
450
321
|
}
|
451
|
-
}
|
322
|
+
}
|
452
323
|
|
453
|
-
|
454
|
-
}();
|
324
|
+
}
|
455
325
|
|
456
|
-
function createRequestOptions(
|
326
|
+
function createRequestOptions(parsedUrl, headers) {
|
457
327
|
return {
|
458
|
-
protocol:
|
459
|
-
auth:
|
460
|
-
host:
|
461
|
-
port:
|
462
|
-
path:
|
463
|
-
method:
|
464
|
-
headers
|
328
|
+
protocol: parsedUrl.protocol,
|
329
|
+
auth: parsedUrl.auth,
|
330
|
+
host: parsedUrl.hostname,
|
331
|
+
port: parsedUrl.port,
|
332
|
+
path: parsedUrl.path,
|
333
|
+
method: "GET",
|
334
|
+
headers
|
465
335
|
};
|
466
336
|
}
|
467
337
|
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
_inherits(PDFNodeStreamFullReader, _BaseFullReader);
|
472
|
-
|
473
|
-
function PDFNodeStreamFullReader(stream) {
|
474
|
-
var _this3;
|
475
|
-
|
476
|
-
_classCallCheck(this, PDFNodeStreamFullReader);
|
338
|
+
class PDFNodeStreamFullReader extends BaseFullReader {
|
339
|
+
constructor(stream) {
|
340
|
+
super(stream);
|
477
341
|
|
478
|
-
|
479
|
-
|
480
|
-
var handleResponse = function handleResponse(response) {
|
342
|
+
const handleResponse = response => {
|
481
343
|
if (response.statusCode === 404) {
|
482
|
-
|
483
|
-
|
344
|
+
const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
345
|
+
this._storedError = error;
|
484
346
|
|
485
|
-
|
347
|
+
this._headersCapability.reject(error);
|
486
348
|
|
487
349
|
return;
|
488
350
|
}
|
489
351
|
|
490
|
-
|
352
|
+
this._headersCapability.resolve();
|
491
353
|
|
492
|
-
|
354
|
+
this._setReadableStream(response);
|
493
355
|
|
494
|
-
|
495
|
-
return
|
356
|
+
const getResponseHeader = name => {
|
357
|
+
return this._readableStream.headers[name.toLowerCase()];
|
496
358
|
};
|
497
359
|
|
498
|
-
|
499
|
-
|
360
|
+
const {
|
361
|
+
allowRangeRequests,
|
362
|
+
suggestedLength
|
363
|
+
} = (0, _network_utils.validateRangeRequestCapabilities)({
|
364
|
+
getResponseHeader,
|
500
365
|
isHttp: stream.isHttp,
|
501
|
-
rangeChunkSize:
|
502
|
-
disableRange:
|
503
|
-
})
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
_this3._isRangeSupported = allowRangeRequests;
|
508
|
-
_this3._contentLength = suggestedLength || _this3._contentLength;
|
509
|
-
_this3._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
366
|
+
rangeChunkSize: this._rangeChunkSize,
|
367
|
+
disableRange: this._disableRange
|
368
|
+
});
|
369
|
+
this._isRangeSupported = allowRangeRequests;
|
370
|
+
this._contentLength = suggestedLength || this._contentLength;
|
371
|
+
this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
510
372
|
};
|
511
373
|
|
512
|
-
|
374
|
+
this._request = null;
|
513
375
|
|
514
|
-
if (
|
515
|
-
|
376
|
+
if (this._url.protocol === "http:") {
|
377
|
+
this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
516
378
|
} else {
|
517
|
-
|
379
|
+
this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
518
380
|
}
|
519
381
|
|
520
|
-
|
521
|
-
|
382
|
+
this._request.on("error", reason => {
|
383
|
+
this._storedError = reason;
|
522
384
|
|
523
|
-
|
385
|
+
this._headersCapability.reject(reason);
|
524
386
|
});
|
525
387
|
|
526
|
-
|
527
|
-
|
528
|
-
return _this3;
|
388
|
+
this._request.end();
|
529
389
|
}
|
530
390
|
|
531
|
-
|
532
|
-
}(BaseFullReader);
|
533
|
-
|
534
|
-
var PDFNodeStreamRangeReader =
|
535
|
-
/*#__PURE__*/
|
536
|
-
function (_BaseRangeReader) {
|
537
|
-
_inherits(PDFNodeStreamRangeReader, _BaseRangeReader);
|
538
|
-
|
539
|
-
function PDFNodeStreamRangeReader(stream, start, end) {
|
540
|
-
var _this4;
|
541
|
-
|
542
|
-
_classCallCheck(this, PDFNodeStreamRangeReader);
|
391
|
+
}
|
543
392
|
|
544
|
-
|
545
|
-
|
393
|
+
class PDFNodeStreamRangeReader extends BaseRangeReader {
|
394
|
+
constructor(stream, start, end) {
|
395
|
+
super(stream);
|
396
|
+
this._httpHeaders = {};
|
546
397
|
|
547
|
-
for (
|
548
|
-
|
398
|
+
for (const property in stream.httpHeaders) {
|
399
|
+
const value = stream.httpHeaders[property];
|
549
400
|
|
550
|
-
if (typeof value ===
|
401
|
+
if (typeof value === "undefined") {
|
551
402
|
continue;
|
552
403
|
}
|
553
404
|
|
554
|
-
|
405
|
+
this._httpHeaders[property] = value;
|
555
406
|
}
|
556
407
|
|
557
|
-
|
408
|
+
this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
|
558
409
|
|
559
|
-
|
410
|
+
const handleResponse = response => {
|
560
411
|
if (response.statusCode === 404) {
|
561
|
-
|
562
|
-
|
412
|
+
const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
413
|
+
this._storedError = error;
|
563
414
|
return;
|
564
415
|
}
|
565
416
|
|
566
|
-
|
417
|
+
this._setReadableStream(response);
|
567
418
|
};
|
568
419
|
|
569
|
-
|
420
|
+
this._request = null;
|
570
421
|
|
571
|
-
if (
|
572
|
-
|
422
|
+
if (this._url.protocol === "http:") {
|
423
|
+
this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
573
424
|
} else {
|
574
|
-
|
425
|
+
this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
575
426
|
}
|
576
427
|
|
577
|
-
|
578
|
-
|
428
|
+
this._request.on("error", reason => {
|
429
|
+
this._storedError = reason;
|
579
430
|
});
|
580
431
|
|
581
|
-
|
582
|
-
|
583
|
-
return _this4;
|
432
|
+
this._request.end();
|
584
433
|
}
|
585
434
|
|
586
|
-
|
587
|
-
}(BaseRangeReader);
|
588
|
-
|
589
|
-
var PDFNodeStreamFsFullReader =
|
590
|
-
/*#__PURE__*/
|
591
|
-
function (_BaseFullReader2) {
|
592
|
-
_inherits(PDFNodeStreamFsFullReader, _BaseFullReader2);
|
593
|
-
|
594
|
-
function PDFNodeStreamFsFullReader(stream) {
|
595
|
-
var _this5;
|
596
|
-
|
597
|
-
_classCallCheck(this, PDFNodeStreamFsFullReader);
|
435
|
+
}
|
598
436
|
|
599
|
-
|
600
|
-
|
437
|
+
class PDFNodeStreamFsFullReader extends BaseFullReader {
|
438
|
+
constructor(stream) {
|
439
|
+
super(stream);
|
440
|
+
let path = decodeURIComponent(this._url.path);
|
601
441
|
|
602
|
-
if (fileUriRegex.test(
|
603
|
-
path = path.replace(/^\//,
|
442
|
+
if (fileUriRegex.test(this._url.href)) {
|
443
|
+
path = path.replace(/^\//, "");
|
604
444
|
}
|
605
445
|
|
606
|
-
fs.lstat(path,
|
446
|
+
fs.lstat(path, (error, stat) => {
|
607
447
|
if (error) {
|
608
|
-
if (error.code ===
|
609
|
-
error = new _util.MissingPDFException(
|
448
|
+
if (error.code === "ENOENT") {
|
449
|
+
error = new _util.MissingPDFException(`Missing PDF "${path}".`);
|
610
450
|
}
|
611
451
|
|
612
|
-
|
452
|
+
this._storedError = error;
|
613
453
|
|
614
|
-
|
454
|
+
this._headersCapability.reject(error);
|
615
455
|
|
616
456
|
return;
|
617
457
|
}
|
618
458
|
|
619
|
-
|
459
|
+
this._contentLength = stat.size;
|
620
460
|
|
621
|
-
|
461
|
+
this._setReadableStream(fs.createReadStream(path));
|
622
462
|
|
623
|
-
|
463
|
+
this._headersCapability.resolve();
|
624
464
|
});
|
625
|
-
return _this5;
|
626
465
|
}
|
627
466
|
|
628
|
-
|
629
|
-
}(BaseFullReader);
|
630
|
-
|
631
|
-
var PDFNodeStreamFsRangeReader =
|
632
|
-
/*#__PURE__*/
|
633
|
-
function (_BaseRangeReader2) {
|
634
|
-
_inherits(PDFNodeStreamFsRangeReader, _BaseRangeReader2);
|
635
|
-
|
636
|
-
function PDFNodeStreamFsRangeReader(stream, start, end) {
|
637
|
-
var _this6;
|
638
|
-
|
639
|
-
_classCallCheck(this, PDFNodeStreamFsRangeReader);
|
467
|
+
}
|
640
468
|
|
641
|
-
|
642
|
-
|
469
|
+
class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
470
|
+
constructor(stream, start, end) {
|
471
|
+
super(stream);
|
472
|
+
let path = decodeURIComponent(this._url.path);
|
643
473
|
|
644
|
-
if (fileUriRegex.test(
|
645
|
-
path = path.replace(/^\//,
|
474
|
+
if (fileUriRegex.test(this._url.href)) {
|
475
|
+
path = path.replace(/^\//, "");
|
646
476
|
}
|
647
477
|
|
648
|
-
|
649
|
-
start
|
478
|
+
this._setReadableStream(fs.createReadStream(path, {
|
479
|
+
start,
|
650
480
|
end: end - 1
|
651
481
|
}));
|
652
|
-
|
653
|
-
return _this6;
|
654
482
|
}
|
655
483
|
|
656
|
-
|
657
|
-
}(BaseRangeReader);
|
484
|
+
}
|