pdfjs-dist 2.3.200 → 2.4.456
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +6499 -17971
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +19303 -29896
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1333 -4839
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +683 -1066
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +196 -193
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +441 -569
- package/lib/core/cmap.js +220 -279
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +59 -80
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +564 -673
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +983 -889
- package/lib/core/font_renderer.js +128 -171
- package/lib/core/fonts.js +451 -400
- package/lib/core/function.js +289 -285
- package/lib/core/glyphlist.js +4527 -4527
- package/lib/core/image.js +138 -117
- package/lib/core/image_utils.js +46 -63
- package/lib/core/jbig2.js +324 -332
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +133 -24
- package/lib/core/jpg.js +238 -210
- package/lib/core/jpx.js +158 -157
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1111 -1302
- package/lib/core/operator_list.js +55 -42
- package/lib/core/parser.js +956 -987
- package/lib/core/pattern.js +69 -69
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +45 -77
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +83 -77
- package/lib/core/type1_parser.js +78 -68
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +148 -196
- package/lib/core/worker_stream.js +101 -210
- package/lib/display/annotation_layer.js +733 -1155
- package/lib/display/api.js +1539 -1928
- package/lib/display/api_compatibility.js +10 -8
- package/lib/display/canvas.js +159 -158
- package/lib/display/content_disposition.js +36 -55
- package/lib/display/display_utils.js +298 -551
- package/lib/display/fetch_stream.js +181 -305
- package/lib/display/font_loader.js +273 -416
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +376 -511
- package/lib/display/network_utils.js +20 -19
- package/lib/display/node_stream.js +276 -460
- package/lib/display/pattern_helper.js +76 -44
- package/lib/display/svg.js +1137 -1405
- package/lib/display/text_layer.js +75 -82
- package/lib/display/transport_stream.js +236 -374
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +22 -21
- package/lib/pdf.worker.js +5 -5
- package/lib/shared/compatibility.js +2 -251
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +222 -194
- package/lib/shared/util.js +269 -405
- package/lib/test/unit/annotation_spec.js +1089 -1014
- package/lib/test/unit/api_spec.js +617 -544
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +63 -62
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +84 -86
- package/lib/test/unit/colorspace_spec.js +154 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +22 -24
- package/lib/test/unit/display_svg_spec.js +35 -36
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +16 -16
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +81 -95
- package/lib/test/unit/fetch_stream_spec.js +30 -30
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +172 -162
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +12 -12
- package/lib/test/unit/network_utils_spec.js +152 -152
- package/lib/test/unit/node_stream_spec.js +74 -90
- package/lib/test/unit/parser_spec.js +107 -113
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +117 -115
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +119 -285
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +41 -41
- package/lib/test/unit/ui_utils_spec.js +318 -426
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +122 -143
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1166 -1196
- package/lib/web/app_options.js +61 -77
- package/lib/web/base_viewer.js +804 -850
- package/lib/web/chromecom.js +164 -249
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +38 -57
- package/lib/web/firefox_print_service.js +35 -30
- package/lib/web/firefoxcom.js +175 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -258
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +105 -130
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +227 -376
- package/lib/web/pdf_find_bar.js +137 -171
- package/lib/web/pdf_find_controller.js +492 -549
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +395 -406
- package/lib/web/pdf_link_service.js +302 -349
- package/lib/web/pdf_outline_viewer.js +148 -209
- package/lib/web/pdf_page_view.js +449 -507
- package/lib/web/pdf_presentation_mode.js +304 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +264 -304
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +66 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -317
- package/lib/web/toolbar.js +216 -211
- package/lib/web/ui_utils.js +303 -404
- package/lib/web/view_history.js +49 -222
- package/lib/web/viewer_compatibility.js +7 -5
- package/package.json +2 -9
- package/web/pdf_viewer.css +25 -18
- package/web/pdf_viewer.js +3481 -4764
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/lib/shared/streams_polyfill.js +0 -43
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -26,135 +26,94 @@ 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
|
+
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
|
-
|
42
|
-
|
43
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
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]:\//;
|
41
|
+
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
68
42
|
|
69
43
|
function parseUrl(sourceUrl) {
|
70
|
-
|
44
|
+
const parsedUrl = url.parse(sourceUrl);
|
71
45
|
|
72
|
-
if (parsedUrl.protocol ===
|
46
|
+
if (parsedUrl.protocol === "file:" || parsedUrl.host) {
|
73
47
|
return parsedUrl;
|
74
48
|
}
|
75
49
|
|
76
50
|
if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
|
77
|
-
return url.parse(
|
51
|
+
return url.parse(`file:///${sourceUrl}`);
|
78
52
|
}
|
79
53
|
|
80
54
|
if (!parsedUrl.host) {
|
81
|
-
parsedUrl.protocol =
|
55
|
+
parsedUrl.protocol = "file:";
|
82
56
|
}
|
83
57
|
|
84
58
|
return parsedUrl;
|
85
59
|
}
|
86
60
|
|
87
|
-
|
88
|
-
|
89
|
-
function () {
|
90
|
-
function PDFNodeStream(source) {
|
91
|
-
_classCallCheck(this, PDFNodeStream);
|
92
|
-
|
61
|
+
class PDFNodeStream {
|
62
|
+
constructor(source) {
|
93
63
|
this.source = source;
|
94
64
|
this.url = parseUrl(source.url);
|
95
|
-
this.isHttp = this.url.protocol ===
|
96
|
-
this.isFsUrl = this.url.protocol ===
|
65
|
+
this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
|
66
|
+
this.isFsUrl = this.url.protocol === "file:";
|
97
67
|
this.httpHeaders = this.isHttp && source.httpHeaders || {};
|
98
68
|
this._fullRequestReader = null;
|
99
69
|
this._rangeRequestReaders = [];
|
100
70
|
}
|
101
71
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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;
|
108
85
|
}
|
109
|
-
}, {
|
110
|
-
key: "getRangeReader",
|
111
|
-
value: function getRangeReader(start, end) {
|
112
|
-
if (end <= this._progressiveDataLength) {
|
113
|
-
return null;
|
114
|
-
}
|
115
86
|
|
116
|
-
|
87
|
+
const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
|
117
88
|
|
118
|
-
|
89
|
+
this._rangeRequestReaders.push(rangeReader);
|
90
|
+
|
91
|
+
return rangeReader;
|
92
|
+
}
|
119
93
|
|
120
|
-
|
94
|
+
cancelAllRequests(reason) {
|
95
|
+
if (this._fullRequestReader) {
|
96
|
+
this._fullRequestReader.cancel(reason);
|
121
97
|
}
|
122
|
-
}, {
|
123
|
-
key: "cancelAllRequests",
|
124
|
-
value: function cancelAllRequests(reason) {
|
125
|
-
if (this._fullRequestReader) {
|
126
|
-
this._fullRequestReader.cancel(reason);
|
127
|
-
}
|
128
98
|
|
129
|
-
|
99
|
+
const readers = this._rangeRequestReaders.slice(0);
|
130
100
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
}, {
|
136
|
-
key: "_progressiveDataLength",
|
137
|
-
get: function get() {
|
138
|
-
return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
|
139
|
-
}
|
140
|
-
}]);
|
101
|
+
readers.forEach(function (reader) {
|
102
|
+
reader.cancel(reason);
|
103
|
+
});
|
104
|
+
}
|
141
105
|
|
142
|
-
|
143
|
-
}();
|
106
|
+
}
|
144
107
|
|
145
108
|
exports.PDFNodeStream = PDFNodeStream;
|
146
109
|
|
147
|
-
|
148
|
-
|
149
|
-
function () {
|
150
|
-
function BaseFullReader(stream) {
|
151
|
-
_classCallCheck(this, BaseFullReader);
|
152
|
-
|
110
|
+
class BaseFullReader {
|
111
|
+
constructor(stream) {
|
153
112
|
this._url = stream.url;
|
154
113
|
this._done = false;
|
155
114
|
this._storedError = null;
|
156
115
|
this.onProgress = null;
|
157
|
-
|
116
|
+
const source = stream.source;
|
158
117
|
this._contentLength = source.length;
|
159
118
|
this._loaded = 0;
|
160
119
|
this._filename = null;
|
@@ -172,161 +131,107 @@ function () {
|
|
172
131
|
this._headersCapability = (0, _util.createPromiseCapability)();
|
173
132
|
}
|
174
133
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
var _read = _asyncToGenerator(
|
179
|
-
/*#__PURE__*/
|
180
|
-
_regenerator["default"].mark(function _callee() {
|
181
|
-
var chunk, buffer;
|
182
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
183
|
-
while (1) {
|
184
|
-
switch (_context.prev = _context.next) {
|
185
|
-
case 0:
|
186
|
-
_context.next = 2;
|
187
|
-
return this._readCapability.promise;
|
188
|
-
|
189
|
-
case 2:
|
190
|
-
if (!this._done) {
|
191
|
-
_context.next = 4;
|
192
|
-
break;
|
193
|
-
}
|
194
|
-
|
195
|
-
return _context.abrupt("return", {
|
196
|
-
value: undefined,
|
197
|
-
done: true
|
198
|
-
});
|
199
|
-
|
200
|
-
case 4:
|
201
|
-
if (!this._storedError) {
|
202
|
-
_context.next = 6;
|
203
|
-
break;
|
204
|
-
}
|
205
|
-
|
206
|
-
throw this._storedError;
|
207
|
-
|
208
|
-
case 6:
|
209
|
-
chunk = this._readableStream.read();
|
210
|
-
|
211
|
-
if (!(chunk === null)) {
|
212
|
-
_context.next = 10;
|
213
|
-
break;
|
214
|
-
}
|
215
|
-
|
216
|
-
this._readCapability = (0, _util.createPromiseCapability)();
|
217
|
-
return _context.abrupt("return", this.read());
|
218
|
-
|
219
|
-
case 10:
|
220
|
-
this._loaded += chunk.length;
|
221
|
-
|
222
|
-
if (this.onProgress) {
|
223
|
-
this.onProgress({
|
224
|
-
loaded: this._loaded,
|
225
|
-
total: this._contentLength
|
226
|
-
});
|
227
|
-
}
|
228
|
-
|
229
|
-
buffer = new Uint8Array(chunk).buffer;
|
230
|
-
return _context.abrupt("return", {
|
231
|
-
value: buffer,
|
232
|
-
done: false
|
233
|
-
});
|
234
|
-
|
235
|
-
case 14:
|
236
|
-
case "end":
|
237
|
-
return _context.stop();
|
238
|
-
}
|
239
|
-
}
|
240
|
-
}, _callee, this);
|
241
|
-
}));
|
242
|
-
|
243
|
-
function read() {
|
244
|
-
return _read.apply(this, arguments);
|
245
|
-
}
|
246
|
-
|
247
|
-
return read;
|
248
|
-
}()
|
249
|
-
}, {
|
250
|
-
key: "cancel",
|
251
|
-
value: function cancel(reason) {
|
252
|
-
if (!this._readableStream) {
|
253
|
-
this._error(reason);
|
134
|
+
get headersReady() {
|
135
|
+
return this._headersCapability.promise;
|
136
|
+
}
|
254
137
|
|
255
|
-
|
256
|
-
|
138
|
+
get filename() {
|
139
|
+
return this._filename;
|
140
|
+
}
|
257
141
|
|
258
|
-
|
259
|
-
|
260
|
-
}
|
261
|
-
key: "_error",
|
262
|
-
value: function _error(reason) {
|
263
|
-
this._storedError = reason;
|
142
|
+
get contentLength() {
|
143
|
+
return this._contentLength;
|
144
|
+
}
|
264
145
|
|
265
|
-
|
266
|
-
|
267
|
-
}
|
268
|
-
key: "_setReadableStream",
|
269
|
-
value: function _setReadableStream(readableStream) {
|
270
|
-
var _this = this;
|
271
|
-
|
272
|
-
this._readableStream = readableStream;
|
273
|
-
readableStream.on('readable', function () {
|
274
|
-
_this._readCapability.resolve();
|
275
|
-
});
|
276
|
-
readableStream.on('end', function () {
|
277
|
-
readableStream.destroy();
|
278
|
-
_this._done = true;
|
146
|
+
get isRangeSupported() {
|
147
|
+
return this._isRangeSupported;
|
148
|
+
}
|
279
149
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
_this._error(reason);
|
284
|
-
});
|
150
|
+
get isStreamingSupported() {
|
151
|
+
return this._isStreamingSupported;
|
152
|
+
}
|
285
153
|
|
286
|
-
|
287
|
-
|
288
|
-
}
|
154
|
+
async read() {
|
155
|
+
await this._readCapability.promise;
|
289
156
|
|
290
|
-
|
291
|
-
|
292
|
-
|
157
|
+
if (this._done) {
|
158
|
+
return {
|
159
|
+
value: undefined,
|
160
|
+
done: true
|
161
|
+
};
|
293
162
|
}
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
return this._headersCapability.promise;
|
163
|
+
|
164
|
+
if (this._storedError) {
|
165
|
+
throw this._storedError;
|
298
166
|
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
167
|
+
|
168
|
+
const chunk = this._readableStream.read();
|
169
|
+
|
170
|
+
if (chunk === null) {
|
171
|
+
this._readCapability = (0, _util.createPromiseCapability)();
|
172
|
+
return this.read();
|
303
173
|
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
174
|
+
|
175
|
+
this._loaded += chunk.length;
|
176
|
+
|
177
|
+
if (this.onProgress) {
|
178
|
+
this.onProgress({
|
179
|
+
loaded: this._loaded,
|
180
|
+
total: this._contentLength
|
181
|
+
});
|
308
182
|
}
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
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;
|
313
196
|
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
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"));
|
318
224
|
}
|
319
|
-
}]);
|
320
225
|
|
321
|
-
|
322
|
-
|
226
|
+
if (this._storedError) {
|
227
|
+
this._readableStream.destroy(this._storedError);
|
228
|
+
}
|
229
|
+
}
|
323
230
|
|
324
|
-
|
325
|
-
/*#__PURE__*/
|
326
|
-
function () {
|
327
|
-
function BaseRangeReader(stream) {
|
328
|
-
_classCallCheck(this, BaseRangeReader);
|
231
|
+
}
|
329
232
|
|
233
|
+
class BaseRangeReader {
|
234
|
+
constructor(stream) {
|
330
235
|
this._url = stream.url;
|
331
236
|
this._done = false;
|
332
237
|
this._storedError = null;
|
@@ -334,133 +239,87 @@ function () {
|
|
334
239
|
this._loaded = 0;
|
335
240
|
this._readableStream = null;
|
336
241
|
this._readCapability = (0, _util.createPromiseCapability)();
|
337
|
-
|
242
|
+
const source = stream.source;
|
338
243
|
this._isStreamingSupported = !source.disableStream;
|
339
244
|
}
|
340
245
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
var _read2 = _asyncToGenerator(
|
345
|
-
/*#__PURE__*/
|
346
|
-
_regenerator["default"].mark(function _callee2() {
|
347
|
-
var chunk, buffer;
|
348
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
349
|
-
while (1) {
|
350
|
-
switch (_context2.prev = _context2.next) {
|
351
|
-
case 0:
|
352
|
-
_context2.next = 2;
|
353
|
-
return this._readCapability.promise;
|
354
|
-
|
355
|
-
case 2:
|
356
|
-
if (!this._done) {
|
357
|
-
_context2.next = 4;
|
358
|
-
break;
|
359
|
-
}
|
360
|
-
|
361
|
-
return _context2.abrupt("return", {
|
362
|
-
value: undefined,
|
363
|
-
done: true
|
364
|
-
});
|
365
|
-
|
366
|
-
case 4:
|
367
|
-
if (!this._storedError) {
|
368
|
-
_context2.next = 6;
|
369
|
-
break;
|
370
|
-
}
|
371
|
-
|
372
|
-
throw this._storedError;
|
373
|
-
|
374
|
-
case 6:
|
375
|
-
chunk = this._readableStream.read();
|
376
|
-
|
377
|
-
if (!(chunk === null)) {
|
378
|
-
_context2.next = 10;
|
379
|
-
break;
|
380
|
-
}
|
381
|
-
|
382
|
-
this._readCapability = (0, _util.createPromiseCapability)();
|
383
|
-
return _context2.abrupt("return", this.read());
|
384
|
-
|
385
|
-
case 10:
|
386
|
-
this._loaded += chunk.length;
|
387
|
-
|
388
|
-
if (this.onProgress) {
|
389
|
-
this.onProgress({
|
390
|
-
loaded: this._loaded
|
391
|
-
});
|
392
|
-
}
|
393
|
-
|
394
|
-
buffer = new Uint8Array(chunk).buffer;
|
395
|
-
return _context2.abrupt("return", {
|
396
|
-
value: buffer,
|
397
|
-
done: false
|
398
|
-
});
|
399
|
-
|
400
|
-
case 14:
|
401
|
-
case "end":
|
402
|
-
return _context2.stop();
|
403
|
-
}
|
404
|
-
}
|
405
|
-
}, _callee2, this);
|
406
|
-
}));
|
407
|
-
|
408
|
-
function read() {
|
409
|
-
return _read2.apply(this, arguments);
|
410
|
-
}
|
246
|
+
get isStreamingSupported() {
|
247
|
+
return this._isStreamingSupported;
|
248
|
+
}
|
411
249
|
|
412
|
-
|
413
|
-
|
414
|
-
}, {
|
415
|
-
key: "cancel",
|
416
|
-
value: function cancel(reason) {
|
417
|
-
if (!this._readableStream) {
|
418
|
-
this._error(reason);
|
250
|
+
async read() {
|
251
|
+
await this._readCapability.promise;
|
419
252
|
|
420
|
-
|
421
|
-
|
253
|
+
if (this._done) {
|
254
|
+
return {
|
255
|
+
value: undefined,
|
256
|
+
done: true
|
257
|
+
};
|
258
|
+
}
|
422
259
|
|
423
|
-
|
260
|
+
if (this._storedError) {
|
261
|
+
throw this._storedError;
|
424
262
|
}
|
425
|
-
}, {
|
426
|
-
key: "_error",
|
427
|
-
value: function _error(reason) {
|
428
|
-
this._storedError = reason;
|
429
263
|
|
430
|
-
|
264
|
+
const chunk = this._readableStream.read();
|
265
|
+
|
266
|
+
if (chunk === null) {
|
267
|
+
this._readCapability = (0, _util.createPromiseCapability)();
|
268
|
+
return this.read();
|
431
269
|
}
|
432
|
-
}, {
|
433
|
-
key: "_setReadableStream",
|
434
|
-
value: function _setReadableStream(readableStream) {
|
435
|
-
var _this2 = this;
|
436
|
-
|
437
|
-
this._readableStream = readableStream;
|
438
|
-
readableStream.on('readable', function () {
|
439
|
-
_this2._readCapability.resolve();
|
440
|
-
});
|
441
|
-
readableStream.on('end', function () {
|
442
|
-
readableStream.destroy();
|
443
|
-
_this2._done = true;
|
444
270
|
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
271
|
+
this._loaded += chunk.length;
|
272
|
+
|
273
|
+
if (this.onProgress) {
|
274
|
+
this.onProgress({
|
275
|
+
loaded: this._loaded
|
449
276
|
});
|
277
|
+
}
|
450
278
|
|
451
|
-
|
452
|
-
|
453
|
-
|
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;
|
454
291
|
}
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
292
|
+
|
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);
|
459
319
|
}
|
460
|
-
}
|
320
|
+
}
|
461
321
|
|
462
|
-
|
463
|
-
}();
|
322
|
+
}
|
464
323
|
|
465
324
|
function createRequestOptions(url, headers) {
|
466
325
|
return {
|
@@ -469,198 +328,155 @@ function createRequestOptions(url, headers) {
|
|
469
328
|
host: url.hostname,
|
470
329
|
port: url.port,
|
471
330
|
path: url.path,
|
472
|
-
method:
|
473
|
-
headers
|
331
|
+
method: "GET",
|
332
|
+
headers
|
474
333
|
};
|
475
334
|
}
|
476
335
|
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
_inherits(PDFNodeStreamFullReader, _BaseFullReader);
|
481
|
-
|
482
|
-
function PDFNodeStreamFullReader(stream) {
|
483
|
-
var _this3;
|
336
|
+
class PDFNodeStreamFullReader extends BaseFullReader {
|
337
|
+
constructor(stream) {
|
338
|
+
super(stream);
|
484
339
|
|
485
|
-
|
486
|
-
|
487
|
-
_this3 = _possibleConstructorReturn(this, _getPrototypeOf(PDFNodeStreamFullReader).call(this, stream));
|
488
|
-
|
489
|
-
var handleResponse = function handleResponse(response) {
|
340
|
+
const handleResponse = response => {
|
490
341
|
if (response.statusCode === 404) {
|
491
|
-
|
492
|
-
|
342
|
+
const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
343
|
+
this._storedError = error;
|
493
344
|
|
494
|
-
|
345
|
+
this._headersCapability.reject(error);
|
495
346
|
|
496
347
|
return;
|
497
348
|
}
|
498
349
|
|
499
|
-
|
350
|
+
this._headersCapability.resolve();
|
500
351
|
|
501
|
-
|
352
|
+
this._setReadableStream(response);
|
502
353
|
|
503
|
-
|
504
|
-
return
|
354
|
+
const getResponseHeader = name => {
|
355
|
+
return this._readableStream.headers[name.toLowerCase()];
|
505
356
|
};
|
506
357
|
|
507
|
-
|
508
|
-
|
358
|
+
const {
|
359
|
+
allowRangeRequests,
|
360
|
+
suggestedLength
|
361
|
+
} = (0, _network_utils.validateRangeRequestCapabilities)({
|
362
|
+
getResponseHeader,
|
509
363
|
isHttp: stream.isHttp,
|
510
|
-
rangeChunkSize:
|
511
|
-
disableRange:
|
512
|
-
})
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
_this3._isRangeSupported = allowRangeRequests;
|
517
|
-
_this3._contentLength = suggestedLength || _this3._contentLength;
|
518
|
-
_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);
|
519
370
|
};
|
520
371
|
|
521
|
-
|
372
|
+
this._request = null;
|
522
373
|
|
523
|
-
if (
|
524
|
-
|
374
|
+
if (this._url.protocol === "http:") {
|
375
|
+
this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
525
376
|
} else {
|
526
|
-
|
377
|
+
this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
527
378
|
}
|
528
379
|
|
529
|
-
|
530
|
-
|
380
|
+
this._request.on("error", reason => {
|
381
|
+
this._storedError = reason;
|
531
382
|
|
532
|
-
|
383
|
+
this._headersCapability.reject(reason);
|
533
384
|
});
|
534
385
|
|
535
|
-
|
536
|
-
|
537
|
-
return _this3;
|
386
|
+
this._request.end();
|
538
387
|
}
|
539
388
|
|
540
|
-
|
541
|
-
}(BaseFullReader);
|
542
|
-
|
543
|
-
var PDFNodeStreamRangeReader =
|
544
|
-
/*#__PURE__*/
|
545
|
-
function (_BaseRangeReader) {
|
546
|
-
_inherits(PDFNodeStreamRangeReader, _BaseRangeReader);
|
547
|
-
|
548
|
-
function PDFNodeStreamRangeReader(stream, start, end) {
|
549
|
-
var _this4;
|
550
|
-
|
551
|
-
_classCallCheck(this, PDFNodeStreamRangeReader);
|
389
|
+
}
|
552
390
|
|
553
|
-
|
554
|
-
|
391
|
+
class PDFNodeStreamRangeReader extends BaseRangeReader {
|
392
|
+
constructor(stream, start, end) {
|
393
|
+
super(stream);
|
394
|
+
this._httpHeaders = {};
|
555
395
|
|
556
|
-
for (
|
557
|
-
|
396
|
+
for (const property in stream.httpHeaders) {
|
397
|
+
const value = stream.httpHeaders[property];
|
558
398
|
|
559
|
-
if (typeof value ===
|
399
|
+
if (typeof value === "undefined") {
|
560
400
|
continue;
|
561
401
|
}
|
562
402
|
|
563
|
-
|
403
|
+
this._httpHeaders[property] = value;
|
564
404
|
}
|
565
405
|
|
566
|
-
|
406
|
+
this._httpHeaders["Range"] = `bytes=${start}-${end - 1}`;
|
567
407
|
|
568
|
-
|
408
|
+
const handleResponse = response => {
|
569
409
|
if (response.statusCode === 404) {
|
570
|
-
|
571
|
-
|
410
|
+
const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
411
|
+
this._storedError = error;
|
572
412
|
return;
|
573
413
|
}
|
574
414
|
|
575
|
-
|
415
|
+
this._setReadableStream(response);
|
576
416
|
};
|
577
417
|
|
578
|
-
|
418
|
+
this._request = null;
|
579
419
|
|
580
|
-
if (
|
581
|
-
|
420
|
+
if (this._url.protocol === "http:") {
|
421
|
+
this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
582
422
|
} else {
|
583
|
-
|
423
|
+
this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
584
424
|
}
|
585
425
|
|
586
|
-
|
587
|
-
|
426
|
+
this._request.on("error", reason => {
|
427
|
+
this._storedError = reason;
|
588
428
|
});
|
589
429
|
|
590
|
-
|
591
|
-
|
592
|
-
return _this4;
|
430
|
+
this._request.end();
|
593
431
|
}
|
594
432
|
|
595
|
-
|
596
|
-
}(BaseRangeReader);
|
597
|
-
|
598
|
-
var PDFNodeStreamFsFullReader =
|
599
|
-
/*#__PURE__*/
|
600
|
-
function (_BaseFullReader2) {
|
601
|
-
_inherits(PDFNodeStreamFsFullReader, _BaseFullReader2);
|
602
|
-
|
603
|
-
function PDFNodeStreamFsFullReader(stream) {
|
604
|
-
var _this5;
|
605
|
-
|
606
|
-
_classCallCheck(this, PDFNodeStreamFsFullReader);
|
433
|
+
}
|
607
434
|
|
608
|
-
|
609
|
-
|
435
|
+
class PDFNodeStreamFsFullReader extends BaseFullReader {
|
436
|
+
constructor(stream) {
|
437
|
+
super(stream);
|
438
|
+
let path = decodeURIComponent(this._url.path);
|
610
439
|
|
611
|
-
if (fileUriRegex.test(
|
612
|
-
path = path.replace(/^\//,
|
440
|
+
if (fileUriRegex.test(this._url.href)) {
|
441
|
+
path = path.replace(/^\//, "");
|
613
442
|
}
|
614
443
|
|
615
|
-
fs.lstat(path,
|
444
|
+
fs.lstat(path, (error, stat) => {
|
616
445
|
if (error) {
|
617
|
-
if (error.code ===
|
618
|
-
error = new _util.MissingPDFException(
|
446
|
+
if (error.code === "ENOENT") {
|
447
|
+
error = new _util.MissingPDFException(`Missing PDF "${path}".`);
|
619
448
|
}
|
620
449
|
|
621
|
-
|
450
|
+
this._storedError = error;
|
622
451
|
|
623
|
-
|
452
|
+
this._headersCapability.reject(error);
|
624
453
|
|
625
454
|
return;
|
626
455
|
}
|
627
456
|
|
628
|
-
|
457
|
+
this._contentLength = stat.size;
|
629
458
|
|
630
|
-
|
459
|
+
this._setReadableStream(fs.createReadStream(path));
|
631
460
|
|
632
|
-
|
461
|
+
this._headersCapability.resolve();
|
633
462
|
});
|
634
|
-
return _this5;
|
635
463
|
}
|
636
464
|
|
637
|
-
|
638
|
-
}(BaseFullReader);
|
639
|
-
|
640
|
-
var PDFNodeStreamFsRangeReader =
|
641
|
-
/*#__PURE__*/
|
642
|
-
function (_BaseRangeReader2) {
|
643
|
-
_inherits(PDFNodeStreamFsRangeReader, _BaseRangeReader2);
|
644
|
-
|
645
|
-
function PDFNodeStreamFsRangeReader(stream, start, end) {
|
646
|
-
var _this6;
|
647
|
-
|
648
|
-
_classCallCheck(this, PDFNodeStreamFsRangeReader);
|
465
|
+
}
|
649
466
|
|
650
|
-
|
651
|
-
|
467
|
+
class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
468
|
+
constructor(stream, start, end) {
|
469
|
+
super(stream);
|
470
|
+
let path = decodeURIComponent(this._url.path);
|
652
471
|
|
653
|
-
if (fileUriRegex.test(
|
654
|
-
path = path.replace(/^\//,
|
472
|
+
if (fileUriRegex.test(this._url.href)) {
|
473
|
+
path = path.replace(/^\//, "");
|
655
474
|
}
|
656
475
|
|
657
|
-
|
658
|
-
start
|
476
|
+
this._setReadableStream(fs.createReadStream(path, {
|
477
|
+
start,
|
659
478
|
end: end - 1
|
660
479
|
}));
|
661
|
-
|
662
|
-
return _this6;
|
663
480
|
}
|
664
481
|
|
665
|
-
|
666
|
-
}(BaseRangeReader);
|
482
|
+
}
|