pdfjs-dist 2.2.228 → 2.6.347
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 +8816 -19300
- 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 +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -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/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- 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 +1144 -927
- 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 +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- 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 +289 -233
- package/lib/core/jpx.js +161 -143
- 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 +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- 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 +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- 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 +220 -58
- 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 +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- 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 +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -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 +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -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 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- 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 +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
@@ -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,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
70
|
this._fullRequestReader = null;
|
99
71
|
this._rangeRequestReaders = [];
|
100
72
|
}
|
101
73
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
74
|
+
get _progressiveDataLength() {
|
75
|
+
return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
|
76
|
+
}
|
77
|
+
|
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
|
+
}
|
83
|
+
|
84
|
+
getRangeReader(start, end) {
|
85
|
+
if (end <= this._progressiveDataLength) {
|
86
|
+
return null;
|
108
87
|
}
|
109
|
-
}, {
|
110
|
-
key: "getRangeReader",
|
111
|
-
value: function getRangeReader(start, end) {
|
112
|
-
if (end <= this._progressiveDataLength) {
|
113
|
-
return null;
|
114
|
-
}
|
115
88
|
|
116
|
-
|
89
|
+
const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
|
117
90
|
|
118
|
-
|
91
|
+
this._rangeRequestReaders.push(rangeReader);
|
92
|
+
|
93
|
+
return rangeReader;
|
94
|
+
}
|
119
95
|
|
120
|
-
|
96
|
+
cancelAllRequests(reason) {
|
97
|
+
if (this._fullRequestReader) {
|
98
|
+
this._fullRequestReader.cancel(reason);
|
121
99
|
}
|
122
|
-
}, {
|
123
|
-
key: "cancelAllRequests",
|
124
|
-
value: function cancelAllRequests(reason) {
|
125
|
-
if (this._fullRequestReader) {
|
126
|
-
this._fullRequestReader.cancel(reason);
|
127
|
-
}
|
128
100
|
|
129
|
-
|
101
|
+
const readers = this._rangeRequestReaders.slice(0);
|
130
102
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
}, {
|
136
|
-
key: "_progressiveDataLength",
|
137
|
-
get: function get() {
|
138
|
-
return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
|
139
|
-
}
|
140
|
-
}]);
|
103
|
+
readers.forEach(function (reader) {
|
104
|
+
reader.cancel(reason);
|
105
|
+
});
|
106
|
+
}
|
141
107
|
|
142
|
-
|
143
|
-
}();
|
108
|
+
}
|
144
109
|
|
145
110
|
exports.PDFNodeStream = PDFNodeStream;
|
146
111
|
|
147
|
-
|
148
|
-
|
149
|
-
function () {
|
150
|
-
function BaseFullReader(stream) {
|
151
|
-
_classCallCheck(this, BaseFullReader);
|
152
|
-
|
112
|
+
class BaseFullReader {
|
113
|
+
constructor(stream) {
|
153
114
|
this._url = stream.url;
|
154
115
|
this._done = false;
|
155
116
|
this._storedError = null;
|
156
117
|
this.onProgress = null;
|
157
|
-
|
118
|
+
const source = stream.source;
|
158
119
|
this._contentLength = source.length;
|
159
120
|
this._loaded = 0;
|
160
121
|
this._filename = null;
|
@@ -172,161 +133,107 @@ function () {
|
|
172
133
|
this._headersCapability = (0, _util.createPromiseCapability)();
|
173
134
|
}
|
174
135
|
|
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);
|
136
|
+
get headersReady() {
|
137
|
+
return this._headersCapability.promise;
|
138
|
+
}
|
254
139
|
|
255
|
-
|
256
|
-
|
140
|
+
get filename() {
|
141
|
+
return this._filename;
|
142
|
+
}
|
257
143
|
|
258
|
-
|
259
|
-
|
260
|
-
}
|
261
|
-
key: "_error",
|
262
|
-
value: function _error(reason) {
|
263
|
-
this._storedError = reason;
|
144
|
+
get contentLength() {
|
145
|
+
return this._contentLength;
|
146
|
+
}
|
264
147
|
|
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;
|
148
|
+
get isRangeSupported() {
|
149
|
+
return this._isRangeSupported;
|
150
|
+
}
|
279
151
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
_this._error(reason);
|
284
|
-
});
|
152
|
+
get isStreamingSupported() {
|
153
|
+
return this._isStreamingSupported;
|
154
|
+
}
|
285
155
|
|
286
|
-
|
287
|
-
|
288
|
-
}
|
156
|
+
async read() {
|
157
|
+
await this._readCapability.promise;
|
289
158
|
|
290
|
-
|
291
|
-
|
292
|
-
|
159
|
+
if (this._done) {
|
160
|
+
return {
|
161
|
+
value: undefined,
|
162
|
+
done: true
|
163
|
+
};
|
293
164
|
}
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
return this._headersCapability.promise;
|
165
|
+
|
166
|
+
if (this._storedError) {
|
167
|
+
throw this._storedError;
|
298
168
|
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
169
|
+
|
170
|
+
const chunk = this._readableStream.read();
|
171
|
+
|
172
|
+
if (chunk === null) {
|
173
|
+
this._readCapability = (0, _util.createPromiseCapability)();
|
174
|
+
return this.read();
|
303
175
|
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
176
|
+
|
177
|
+
this._loaded += chunk.length;
|
178
|
+
|
179
|
+
if (this.onProgress) {
|
180
|
+
this.onProgress({
|
181
|
+
loaded: this._loaded,
|
182
|
+
total: this._contentLength
|
183
|
+
});
|
308
184
|
}
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
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;
|
313
198
|
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
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"));
|
318
226
|
}
|
319
|
-
}]);
|
320
227
|
|
321
|
-
|
322
|
-
|
228
|
+
if (this._storedError) {
|
229
|
+
this._readableStream.destroy(this._storedError);
|
230
|
+
}
|
231
|
+
}
|
323
232
|
|
324
|
-
|
325
|
-
/*#__PURE__*/
|
326
|
-
function () {
|
327
|
-
function BaseRangeReader(stream) {
|
328
|
-
_classCallCheck(this, BaseRangeReader);
|
233
|
+
}
|
329
234
|
|
235
|
+
class BaseRangeReader {
|
236
|
+
constructor(stream) {
|
330
237
|
this._url = stream.url;
|
331
238
|
this._done = false;
|
332
239
|
this._storedError = null;
|
@@ -334,333 +241,244 @@ function () {
|
|
334
241
|
this._loaded = 0;
|
335
242
|
this._readableStream = null;
|
336
243
|
this._readCapability = (0, _util.createPromiseCapability)();
|
337
|
-
|
244
|
+
const source = stream.source;
|
338
245
|
this._isStreamingSupported = !source.disableStream;
|
339
246
|
}
|
340
247
|
|
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
|
-
}
|
248
|
+
get isStreamingSupported() {
|
249
|
+
return this._isStreamingSupported;
|
250
|
+
}
|
411
251
|
|
412
|
-
|
413
|
-
|
414
|
-
}, {
|
415
|
-
key: "cancel",
|
416
|
-
value: function cancel(reason) {
|
417
|
-
if (!this._readableStream) {
|
418
|
-
this._error(reason);
|
252
|
+
async read() {
|
253
|
+
await this._readCapability.promise;
|
419
254
|
|
420
|
-
|
421
|
-
|
255
|
+
if (this._done) {
|
256
|
+
return {
|
257
|
+
value: undefined,
|
258
|
+
done: true
|
259
|
+
};
|
260
|
+
}
|
422
261
|
|
423
|
-
|
262
|
+
if (this._storedError) {
|
263
|
+
throw this._storedError;
|
424
264
|
}
|
425
|
-
}, {
|
426
|
-
key: "_error",
|
427
|
-
value: function _error(reason) {
|
428
|
-
this._storedError = reason;
|
429
265
|
|
430
|
-
|
266
|
+
const chunk = this._readableStream.read();
|
267
|
+
|
268
|
+
if (chunk === null) {
|
269
|
+
this._readCapability = (0, _util.createPromiseCapability)();
|
270
|
+
return this.read();
|
431
271
|
}
|
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
272
|
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
273
|
+
this._loaded += chunk.length;
|
274
|
+
|
275
|
+
if (this.onProgress) {
|
276
|
+
this.onProgress({
|
277
|
+
loaded: this._loaded
|
449
278
|
});
|
279
|
+
}
|
450
280
|
|
451
|
-
|
452
|
-
|
453
|
-
|
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;
|
454
293
|
}
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
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);
|
459
321
|
}
|
460
|
-
}
|
322
|
+
}
|
461
323
|
|
462
|
-
|
463
|
-
}();
|
324
|
+
}
|
464
325
|
|
465
|
-
function createRequestOptions(
|
326
|
+
function createRequestOptions(parsedUrl, headers) {
|
466
327
|
return {
|
467
|
-
protocol:
|
468
|
-
auth:
|
469
|
-
host:
|
470
|
-
port:
|
471
|
-
path:
|
472
|
-
method:
|
473
|
-
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
|
474
335
|
};
|
475
336
|
}
|
476
337
|
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
_inherits(PDFNodeStreamFullReader, _BaseFullReader);
|
481
|
-
|
482
|
-
function PDFNodeStreamFullReader(stream) {
|
483
|
-
var _this3;
|
338
|
+
class PDFNodeStreamFullReader extends BaseFullReader {
|
339
|
+
constructor(stream) {
|
340
|
+
super(stream);
|
484
341
|
|
485
|
-
|
486
|
-
|
487
|
-
_this3 = _possibleConstructorReturn(this, _getPrototypeOf(PDFNodeStreamFullReader).call(this, stream));
|
488
|
-
|
489
|
-
var handleResponse = function handleResponse(response) {
|
342
|
+
const handleResponse = response => {
|
490
343
|
if (response.statusCode === 404) {
|
491
|
-
|
492
|
-
|
344
|
+
const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
345
|
+
this._storedError = error;
|
493
346
|
|
494
|
-
|
347
|
+
this._headersCapability.reject(error);
|
495
348
|
|
496
349
|
return;
|
497
350
|
}
|
498
351
|
|
499
|
-
|
352
|
+
this._headersCapability.resolve();
|
500
353
|
|
501
|
-
|
354
|
+
this._setReadableStream(response);
|
502
355
|
|
503
|
-
|
504
|
-
return
|
356
|
+
const getResponseHeader = name => {
|
357
|
+
return this._readableStream.headers[name.toLowerCase()];
|
505
358
|
};
|
506
359
|
|
507
|
-
|
508
|
-
|
360
|
+
const {
|
361
|
+
allowRangeRequests,
|
362
|
+
suggestedLength
|
363
|
+
} = (0, _network_utils.validateRangeRequestCapabilities)({
|
364
|
+
getResponseHeader,
|
509
365
|
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);
|
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);
|
519
372
|
};
|
520
373
|
|
521
|
-
|
374
|
+
this._request = null;
|
522
375
|
|
523
|
-
if (
|
524
|
-
|
376
|
+
if (this._url.protocol === "http:") {
|
377
|
+
this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
525
378
|
} else {
|
526
|
-
|
379
|
+
this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
527
380
|
}
|
528
381
|
|
529
|
-
|
530
|
-
|
382
|
+
this._request.on("error", reason => {
|
383
|
+
this._storedError = reason;
|
531
384
|
|
532
|
-
|
385
|
+
this._headersCapability.reject(reason);
|
533
386
|
});
|
534
387
|
|
535
|
-
|
536
|
-
|
537
|
-
return _this3;
|
388
|
+
this._request.end();
|
538
389
|
}
|
539
390
|
|
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);
|
391
|
+
}
|
552
392
|
|
553
|
-
|
554
|
-
|
393
|
+
class PDFNodeStreamRangeReader extends BaseRangeReader {
|
394
|
+
constructor(stream, start, end) {
|
395
|
+
super(stream);
|
396
|
+
this._httpHeaders = {};
|
555
397
|
|
556
|
-
for (
|
557
|
-
|
398
|
+
for (const property in stream.httpHeaders) {
|
399
|
+
const value = stream.httpHeaders[property];
|
558
400
|
|
559
|
-
if (typeof value ===
|
401
|
+
if (typeof value === "undefined") {
|
560
402
|
continue;
|
561
403
|
}
|
562
404
|
|
563
|
-
|
405
|
+
this._httpHeaders[property] = value;
|
564
406
|
}
|
565
407
|
|
566
|
-
|
408
|
+
this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
|
567
409
|
|
568
|
-
|
410
|
+
const handleResponse = response => {
|
569
411
|
if (response.statusCode === 404) {
|
570
|
-
|
571
|
-
|
412
|
+
const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
413
|
+
this._storedError = error;
|
572
414
|
return;
|
573
415
|
}
|
574
416
|
|
575
|
-
|
417
|
+
this._setReadableStream(response);
|
576
418
|
};
|
577
419
|
|
578
|
-
|
420
|
+
this._request = null;
|
579
421
|
|
580
|
-
if (
|
581
|
-
|
422
|
+
if (this._url.protocol === "http:") {
|
423
|
+
this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
582
424
|
} else {
|
583
|
-
|
425
|
+
this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
584
426
|
}
|
585
427
|
|
586
|
-
|
587
|
-
|
428
|
+
this._request.on("error", reason => {
|
429
|
+
this._storedError = reason;
|
588
430
|
});
|
589
431
|
|
590
|
-
|
591
|
-
|
592
|
-
return _this4;
|
432
|
+
this._request.end();
|
593
433
|
}
|
594
434
|
|
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);
|
435
|
+
}
|
607
436
|
|
608
|
-
|
609
|
-
|
437
|
+
class PDFNodeStreamFsFullReader extends BaseFullReader {
|
438
|
+
constructor(stream) {
|
439
|
+
super(stream);
|
440
|
+
let path = decodeURIComponent(this._url.path);
|
610
441
|
|
611
|
-
if (fileUriRegex.test(
|
612
|
-
path = path.replace(/^\//,
|
442
|
+
if (fileUriRegex.test(this._url.href)) {
|
443
|
+
path = path.replace(/^\//, "");
|
613
444
|
}
|
614
445
|
|
615
|
-
fs.lstat(path,
|
446
|
+
fs.lstat(path, (error, stat) => {
|
616
447
|
if (error) {
|
617
|
-
if (error.code ===
|
618
|
-
error = new _util.MissingPDFException(
|
448
|
+
if (error.code === "ENOENT") {
|
449
|
+
error = new _util.MissingPDFException(`Missing PDF "${path}".`);
|
619
450
|
}
|
620
451
|
|
621
|
-
|
452
|
+
this._storedError = error;
|
622
453
|
|
623
|
-
|
454
|
+
this._headersCapability.reject(error);
|
624
455
|
|
625
456
|
return;
|
626
457
|
}
|
627
458
|
|
628
|
-
|
459
|
+
this._contentLength = stat.size;
|
629
460
|
|
630
|
-
|
461
|
+
this._setReadableStream(fs.createReadStream(path));
|
631
462
|
|
632
|
-
|
463
|
+
this._headersCapability.resolve();
|
633
464
|
});
|
634
|
-
return _this5;
|
635
465
|
}
|
636
466
|
|
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);
|
467
|
+
}
|
649
468
|
|
650
|
-
|
651
|
-
|
469
|
+
class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
470
|
+
constructor(stream, start, end) {
|
471
|
+
super(stream);
|
472
|
+
let path = decodeURIComponent(this._url.path);
|
652
473
|
|
653
|
-
if (fileUriRegex.test(
|
654
|
-
path = path.replace(/^\//,
|
474
|
+
if (fileUriRegex.test(this._url.href)) {
|
475
|
+
path = path.replace(/^\//, "");
|
655
476
|
}
|
656
477
|
|
657
|
-
|
658
|
-
start
|
478
|
+
this._setReadableStream(fs.createReadStream(path, {
|
479
|
+
start,
|
659
480
|
end: end - 1
|
660
481
|
}));
|
661
|
-
|
662
|
-
return _this6;
|
663
482
|
}
|
664
483
|
|
665
|
-
|
666
|
-
}(BaseRangeReader);
|
484
|
+
}
|