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