pdfjs-dist 2.0.487 → 2.1.266

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