pdfjs-dist 2.0.943 → 2.4.456

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

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