@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.4
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.
- package/README.md +1 -1
- package/package.json +33 -18
- package/{src/display → pdfjs/dist}/display_utils.js +344 -139
- package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
- package/pdfjs/dist/get.js +1857 -0
- package/pdfjs/dist/index.js +767 -0
- package/pdfjs/dist/l10n_utils.js +140 -0
- package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
- package/{src/display → pdfjs/dist}/network.js +149 -87
- package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
- package/{src/display → pdfjs/dist}/node_stream.js +133 -98
- package/pdfjs/dist/pdf.js +12778 -0
- package/pdfjs/dist/pdf_link_service.js +638 -0
- package/pdfjs/dist/pdf_rendering_queue.js +199 -0
- package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
- package/pdfjs/dist/pdf_viewer.js +3598 -0
- package/pdfjs/dist/typeof.js +100 -0
- package/pdfjs/dist/ui_utils.js +1033 -0
- package/{src/shared → pdfjs/dist}/util.js +301 -287
- package/pdfjs/dist/worker.js +62813 -0
- package/src/vcf-pdf-viewer.js +77 -27
- package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
- package/theme/material/vcf-pdf-viewer.js +2 -2
- package/src/core/.eslintrc +0 -13
- package/src/core/annotation.js +0 -2948
- package/src/core/arithmetic_decoder.js +0 -182
- package/src/core/ascii_85_stream.js +0 -98
- package/src/core/ascii_hex_stream.js +0 -79
- package/src/core/base_stream.js +0 -110
- package/src/core/bidi.js +0 -438
- package/src/core/calibri_factors.js +0 -308
- package/src/core/catalog.js +0 -1459
- package/src/core/ccitt.js +0 -1062
- package/src/core/ccitt_stream.js +0 -60
- package/src/core/cff_font.js +0 -116
- package/src/core/cff_parser.js +0 -1949
- package/src/core/charsets.js +0 -119
- package/src/core/chunked_stream.js +0 -557
- package/src/core/cmap.js +0 -1039
- package/src/core/colorspace.js +0 -1533
- package/src/core/core_utils.js +0 -464
- package/src/core/crypto.js +0 -1900
- package/src/core/decode_stream.js +0 -170
- package/src/core/decrypt_stream.js +0 -59
- package/src/core/default_appearance.js +0 -99
- package/src/core/document.js +0 -1456
- package/src/core/encodings.js +0 -301
- package/src/core/evaluator.js +0 -4601
- package/src/core/file_spec.js +0 -108
- package/src/core/flate_stream.js +0 -402
- package/src/core/font_renderer.js +0 -882
- package/src/core/fonts.js +0 -3260
- package/src/core/fonts_utils.js +0 -221
- package/src/core/function.js +0 -1257
- package/src/core/glyf.js +0 -706
- package/src/core/glyphlist.js +0 -4558
- package/src/core/helvetica_factors.js +0 -353
- package/src/core/image.js +0 -802
- package/src/core/image_utils.js +0 -291
- package/src/core/jbig2.js +0 -2572
- package/src/core/jbig2_stream.js +0 -73
- package/src/core/jpeg_stream.js +0 -105
- package/src/core/jpg.js +0 -1416
- package/src/core/jpx.js +0 -2343
- package/src/core/jpx_stream.js +0 -87
- package/src/core/liberationsans_widths.js +0 -221
- package/src/core/lzw_stream.js +0 -150
- package/src/core/metadata_parser.js +0 -146
- package/src/core/metrics.js +0 -2970
- package/src/core/murmurhash3.js +0 -139
- package/src/core/myriadpro_factors.js +0 -290
- package/src/core/name_number_tree.js +0 -153
- package/src/core/object_loader.js +0 -149
- package/src/core/opentype_file_builder.js +0 -154
- package/src/core/operator_list.js +0 -734
- package/src/core/parser.js +0 -1416
- package/src/core/pattern.js +0 -985
- package/src/core/pdf_manager.js +0 -217
- package/src/core/predictor_stream.js +0 -238
- package/src/core/primitives.js +0 -402
- package/src/core/ps_parser.js +0 -272
- package/src/core/run_length_stream.js +0 -61
- package/src/core/segoeui_factors.js +0 -308
- package/src/core/standard_fonts.js +0 -817
- package/src/core/stream.js +0 -103
- package/src/core/struct_tree.js +0 -335
- package/src/core/to_unicode_map.js +0 -103
- package/src/core/type1_font.js +0 -421
- package/src/core/type1_parser.js +0 -776
- package/src/core/unicode.js +0 -1649
- package/src/core/worker.js +0 -848
- package/src/core/worker_stream.js +0 -135
- package/src/core/writer.js +0 -278
- package/src/core/xfa/bind.js +0 -652
- package/src/core/xfa/builder.js +0 -207
- package/src/core/xfa/config.js +0 -1926
- package/src/core/xfa/connection_set.js +0 -202
- package/src/core/xfa/data.js +0 -82
- package/src/core/xfa/datasets.js +0 -76
- package/src/core/xfa/factory.js +0 -111
- package/src/core/xfa/fonts.js +0 -181
- package/src/core/xfa/formcalc_lexer.js +0 -385
- package/src/core/xfa/formcalc_parser.js +0 -1340
- package/src/core/xfa/html_utils.js +0 -639
- package/src/core/xfa/layout.js +0 -383
- package/src/core/xfa/locale_set.js +0 -345
- package/src/core/xfa/namespaces.js +0 -81
- package/src/core/xfa/parser.js +0 -184
- package/src/core/xfa/setup.js +0 -38
- package/src/core/xfa/signature.js +0 -40
- package/src/core/xfa/som.js +0 -338
- package/src/core/xfa/stylesheet.js +0 -40
- package/src/core/xfa/template.js +0 -6260
- package/src/core/xfa/text.js +0 -290
- package/src/core/xfa/unknown.js +0 -29
- package/src/core/xfa/utils.js +0 -217
- package/src/core/xfa/xdp.js +0 -59
- package/src/core/xfa/xfa_object.js +0 -1130
- package/src/core/xfa/xhtml.js +0 -543
- package/src/core/xfa_fonts.js +0 -208
- package/src/core/xml_parser.js +0 -507
- package/src/core/xref.js +0 -899
- package/src/display/annotation_layer.js +0 -2107
- package/src/display/annotation_storage.js +0 -113
- package/src/display/api.js +0 -3292
- package/src/display/base_factory.js +0 -180
- package/src/display/canvas.js +0 -2828
- package/src/display/font_loader.js +0 -484
- package/src/display/metadata.js +0 -41
- package/src/display/network_utils.js +0 -100
- package/src/display/node_utils.js +0 -83
- package/src/display/optional_content_config.js +0 -189
- package/src/display/pattern_helper.js +0 -659
- package/src/display/svg.js +0 -1709
- package/src/display/text_layer.js +0 -847
- package/src/display/transport_stream.js +0 -303
- package/src/display/worker_options.js +0 -40
- package/src/display/xfa_layer.js +0 -204
- package/src/doc_helper.js +0 -25
- package/src/images/logo.svg +0 -41
- package/src/interfaces.js +0 -169
- package/src/license_header.js +0 -14
- package/src/license_header_libre.js +0 -21
- package/src/pdf.image_decoders.js +0 -46
- package/src/pdf.js +0 -146
- package/src/pdf.sandbox.external.js +0 -181
- package/src/pdf.sandbox.js +0 -151
- package/src/pdf.scripting.js +0 -25
- package/src/pdf.worker.entry.js +0 -19
- package/src/pdf.worker.js +0 -23
- package/src/scripting_api/aform.js +0 -608
- package/src/scripting_api/app.js +0 -621
- package/src/scripting_api/color.js +0 -129
- package/src/scripting_api/common.js +0 -58
- package/src/scripting_api/console.js +0 -38
- package/src/scripting_api/constants.js +0 -208
- package/src/scripting_api/doc.js +0 -1195
- package/src/scripting_api/error.js +0 -23
- package/src/scripting_api/event.js +0 -232
- package/src/scripting_api/field.js +0 -620
- package/src/scripting_api/fullscreen.js +0 -145
- package/src/scripting_api/initialization.js +0 -223
- package/src/scripting_api/pdf_object.js +0 -24
- package/src/scripting_api/print_params.js +0 -146
- package/src/scripting_api/proxy.js +0 -139
- package/src/scripting_api/thermometer.js +0 -69
- package/src/scripting_api/util.js +0 -581
- package/src/shared/.eslintrc +0 -13
- package/src/shared/cffStandardStrings.js +0 -311
- package/src/shared/compatibility.js +0 -114
- package/src/shared/fonts_utils.js +0 -429
- package/src/shared/is_node.js +0 -27
- package/src/shared/scripting_utils.js +0 -85
- package/src/worker_loader.js +0 -32
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { c as assert, M as MissingPDFException, l as createPromiseCapability, A as AbortException } from './util.js';
|
|
2
|
+
import { v as validateRangeRequestCapabilities, e as extractFilenameFromHeader } from './network_utils.js';
|
|
3
|
+
import './display_utils.js';
|
|
4
|
+
|
|
1
5
|
/* Copyright 2012 Mozilla Foundation
|
|
2
6
|
*
|
|
3
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,45 +16,38 @@
|
|
|
12
16
|
* See the License for the specific language governing permissions and
|
|
13
17
|
* limitations under the License.
|
|
14
18
|
*/
|
|
15
|
-
/* globals __non_webpack_require__ */
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
AbortException,
|
|
19
|
-
assert,
|
|
20
|
-
createPromiseCapability,
|
|
21
|
-
MissingPDFException,
|
|
22
|
-
} from "../shared/util.js";
|
|
23
|
-
import {
|
|
24
|
-
extractFilenameFromHeader,
|
|
25
|
-
validateRangeRequestCapabilities,
|
|
26
|
-
} from "./network_utils.js";
|
|
27
19
|
|
|
28
20
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|
29
|
-
throw new Error(
|
|
30
|
-
'Module "./node_stream.js" shall not be used with MOZCENTRAL builds.'
|
|
31
|
-
);
|
|
21
|
+
throw new Error('Module "./node_stream.js" shall not be used with MOZCENTRAL builds.');
|
|
32
22
|
}
|
|
33
23
|
|
|
34
24
|
const fs = __non_webpack_require__("fs");
|
|
25
|
+
|
|
35
26
|
const http = __non_webpack_require__("http");
|
|
27
|
+
|
|
36
28
|
const https = __non_webpack_require__("https");
|
|
29
|
+
|
|
37
30
|
const url = __non_webpack_require__("url");
|
|
38
31
|
|
|
39
32
|
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
|
40
33
|
|
|
41
34
|
function parseUrl(sourceUrl) {
|
|
42
35
|
const parsedUrl = url.parse(sourceUrl);
|
|
36
|
+
|
|
43
37
|
if (parsedUrl.protocol === "file:" || parsedUrl.host) {
|
|
44
38
|
return parsedUrl;
|
|
45
|
-
}
|
|
46
|
-
|
|
39
|
+
} // Prepending 'file:///' to Windows absolute path.
|
|
40
|
+
|
|
41
|
+
|
|
47
42
|
if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
|
|
48
43
|
return url.parse(`file:///${sourceUrl}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
44
|
+
} // Changes protocol to 'file:' if url refers to filesystem.
|
|
45
|
+
|
|
46
|
+
|
|
51
47
|
if (!parsedUrl.host) {
|
|
52
48
|
parsedUrl.protocol = "file:";
|
|
53
49
|
}
|
|
50
|
+
|
|
54
51
|
return parsedUrl;
|
|
55
52
|
}
|
|
56
53
|
|
|
@@ -58,28 +55,23 @@ class PDFNodeStream {
|
|
|
58
55
|
constructor(source) {
|
|
59
56
|
this.source = source;
|
|
60
57
|
this.url = parseUrl(source.url);
|
|
61
|
-
this.isHttp =
|
|
62
|
-
this.url.protocol === "http:" || this.url.protocol === "https:";
|
|
63
|
-
// Check if url refers to filesystem.
|
|
64
|
-
this.isFsUrl = this.url.protocol === "file:";
|
|
65
|
-
this.httpHeaders = (this.isHttp && source.httpHeaders) || {};
|
|
58
|
+
this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:"; // Check if url refers to filesystem.
|
|
66
59
|
|
|
60
|
+
this.isFsUrl = this.url.protocol === "file:";
|
|
61
|
+
this.httpHeaders = this.isHttp && source.httpHeaders || {};
|
|
67
62
|
this._fullRequestReader = null;
|
|
68
63
|
this._rangeRequestReaders = [];
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
get _progressiveDataLength() {
|
|
72
|
-
|
|
67
|
+
var _this$_fullRequestRea, _this$_fullRequestRea2;
|
|
68
|
+
|
|
69
|
+
return (_this$_fullRequestRea = (_this$_fullRequestRea2 = this._fullRequestReader) === null || _this$_fullRequestRea2 === void 0 ? void 0 : _this$_fullRequestRea2._loaded) !== null && _this$_fullRequestRea !== void 0 ? _this$_fullRequestRea : 0;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
getFullReader() {
|
|
76
|
-
assert(
|
|
77
|
-
|
|
78
|
-
"PDFNodeStream.getFullReader can only be called once."
|
|
79
|
-
);
|
|
80
|
-
this._fullRequestReader = this.isFsUrl
|
|
81
|
-
? new PDFNodeStreamFsFullReader(this)
|
|
82
|
-
: new PDFNodeStreamFullReader(this);
|
|
73
|
+
assert(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
|
|
74
|
+
this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
|
|
83
75
|
return this._fullRequestReader;
|
|
84
76
|
}
|
|
85
77
|
|
|
@@ -87,10 +79,11 @@ class PDFNodeStream {
|
|
|
87
79
|
if (end <= this._progressiveDataLength) {
|
|
88
80
|
return null;
|
|
89
81
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
|
|
83
|
+
const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
|
|
84
|
+
|
|
93
85
|
this._rangeRequestReaders.push(rangeReader);
|
|
86
|
+
|
|
94
87
|
return rangeReader;
|
|
95
88
|
}
|
|
96
89
|
|
|
@@ -98,10 +91,12 @@ class PDFNodeStream {
|
|
|
98
91
|
if (this._fullRequestReader) {
|
|
99
92
|
this._fullRequestReader.cancel(reason);
|
|
100
93
|
}
|
|
94
|
+
|
|
101
95
|
for (const reader of this._rangeRequestReaders.slice(0)) {
|
|
102
96
|
reader.cancel(reason);
|
|
103
97
|
}
|
|
104
98
|
}
|
|
99
|
+
|
|
105
100
|
}
|
|
106
101
|
|
|
107
102
|
class BaseFullReader {
|
|
@@ -112,18 +107,18 @@ class BaseFullReader {
|
|
|
112
107
|
this.onProgress = null;
|
|
113
108
|
const source = stream.source;
|
|
114
109
|
this._contentLength = source.length; // optional
|
|
110
|
+
|
|
115
111
|
this._loaded = 0;
|
|
116
112
|
this._filename = null;
|
|
117
|
-
|
|
118
113
|
this._disableRange = source.disableRange || false;
|
|
119
114
|
this._rangeChunkSize = source.rangeChunkSize;
|
|
115
|
+
|
|
120
116
|
if (!this._rangeChunkSize && !this._disableRange) {
|
|
121
117
|
this._disableRange = true;
|
|
122
118
|
}
|
|
123
119
|
|
|
124
120
|
this._isStreamingSupported = !source.disableStream;
|
|
125
121
|
this._isRangeSupported = !source.disableRange;
|
|
126
|
-
|
|
127
122
|
this._readableStream = null;
|
|
128
123
|
this._readCapability = createPromiseCapability();
|
|
129
124
|
this._headersCapability = createPromiseCapability();
|
|
@@ -151,28 +146,40 @@ class BaseFullReader {
|
|
|
151
146
|
|
|
152
147
|
async read() {
|
|
153
148
|
await this._readCapability.promise;
|
|
149
|
+
|
|
154
150
|
if (this._done) {
|
|
155
|
-
return {
|
|
151
|
+
return {
|
|
152
|
+
value: undefined,
|
|
153
|
+
done: true
|
|
154
|
+
};
|
|
156
155
|
}
|
|
156
|
+
|
|
157
157
|
if (this._storedError) {
|
|
158
158
|
throw this._storedError;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
const chunk = this._readableStream.read();
|
|
162
|
+
|
|
162
163
|
if (chunk === null) {
|
|
163
164
|
this._readCapability = createPromiseCapability();
|
|
164
165
|
return this.read();
|
|
165
166
|
}
|
|
167
|
+
|
|
166
168
|
this._loaded += chunk.length;
|
|
169
|
+
|
|
167
170
|
if (this.onProgress) {
|
|
168
171
|
this.onProgress({
|
|
169
172
|
loaded: this._loaded,
|
|
170
|
-
total: this._contentLength
|
|
173
|
+
total: this._contentLength
|
|
171
174
|
});
|
|
172
|
-
}
|
|
173
|
-
|
|
175
|
+
} // Ensure that `read()` method returns ArrayBuffer.
|
|
176
|
+
|
|
177
|
+
|
|
174
178
|
const buffer = new Uint8Array(chunk).buffer;
|
|
175
|
-
return {
|
|
179
|
+
return {
|
|
180
|
+
value: buffer,
|
|
181
|
+
done: false
|
|
182
|
+
};
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
cancel(reason) {
|
|
@@ -180,13 +187,16 @@ class BaseFullReader {
|
|
|
180
187
|
// before _readableStream is set.
|
|
181
188
|
if (!this._readableStream) {
|
|
182
189
|
this._error(reason);
|
|
190
|
+
|
|
183
191
|
return;
|
|
184
192
|
}
|
|
193
|
+
|
|
185
194
|
this._readableStream.destroy(reason);
|
|
186
195
|
}
|
|
187
196
|
|
|
188
197
|
_error(reason) {
|
|
189
198
|
this._storedError = reason;
|
|
199
|
+
|
|
190
200
|
this._readCapability.resolve();
|
|
191
201
|
}
|
|
192
202
|
|
|
@@ -195,29 +205,28 @@ class BaseFullReader {
|
|
|
195
205
|
readableStream.on("readable", () => {
|
|
196
206
|
this._readCapability.resolve();
|
|
197
207
|
});
|
|
198
|
-
|
|
199
208
|
readableStream.on("end", () => {
|
|
200
209
|
// Destroy readable to minimize resource usage.
|
|
201
210
|
readableStream.destroy();
|
|
202
211
|
this._done = true;
|
|
212
|
+
|
|
203
213
|
this._readCapability.resolve();
|
|
204
214
|
});
|
|
205
|
-
|
|
206
215
|
readableStream.on("error", reason => {
|
|
207
216
|
this._error(reason);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
// We need to stop reading when range is supported and streaming is
|
|
217
|
+
}); // We need to stop reading when range is supported and streaming is
|
|
211
218
|
// disabled.
|
|
219
|
+
|
|
212
220
|
if (!this._isStreamingSupported && this._isRangeSupported) {
|
|
213
221
|
this._error(new AbortException("streaming is disabled"));
|
|
214
|
-
}
|
|
222
|
+
} // Destroy ReadableStream if already in errored state.
|
|
223
|
+
|
|
215
224
|
|
|
216
|
-
// Destroy ReadableStream if already in errored state.
|
|
217
225
|
if (this._storedError) {
|
|
218
226
|
this._readableStream.destroy(this._storedError);
|
|
219
227
|
}
|
|
220
228
|
}
|
|
229
|
+
|
|
221
230
|
}
|
|
222
231
|
|
|
223
232
|
class BaseRangeReader {
|
|
@@ -239,25 +248,39 @@ class BaseRangeReader {
|
|
|
239
248
|
|
|
240
249
|
async read() {
|
|
241
250
|
await this._readCapability.promise;
|
|
251
|
+
|
|
242
252
|
if (this._done) {
|
|
243
|
-
return {
|
|
253
|
+
return {
|
|
254
|
+
value: undefined,
|
|
255
|
+
done: true
|
|
256
|
+
};
|
|
244
257
|
}
|
|
258
|
+
|
|
245
259
|
if (this._storedError) {
|
|
246
260
|
throw this._storedError;
|
|
247
261
|
}
|
|
248
262
|
|
|
249
263
|
const chunk = this._readableStream.read();
|
|
264
|
+
|
|
250
265
|
if (chunk === null) {
|
|
251
266
|
this._readCapability = createPromiseCapability();
|
|
252
267
|
return this.read();
|
|
253
268
|
}
|
|
269
|
+
|
|
254
270
|
this._loaded += chunk.length;
|
|
271
|
+
|
|
255
272
|
if (this.onProgress) {
|
|
256
|
-
this.onProgress({
|
|
257
|
-
|
|
258
|
-
|
|
273
|
+
this.onProgress({
|
|
274
|
+
loaded: this._loaded
|
|
275
|
+
});
|
|
276
|
+
} // Ensure that `read()` method returns ArrayBuffer.
|
|
277
|
+
|
|
278
|
+
|
|
259
279
|
const buffer = new Uint8Array(chunk).buffer;
|
|
260
|
-
return {
|
|
280
|
+
return {
|
|
281
|
+
value: buffer,
|
|
282
|
+
done: false
|
|
283
|
+
};
|
|
261
284
|
}
|
|
262
285
|
|
|
263
286
|
cancel(reason) {
|
|
@@ -265,13 +288,16 @@ class BaseRangeReader {
|
|
|
265
288
|
// before _readableStream is set.
|
|
266
289
|
if (!this._readableStream) {
|
|
267
290
|
this._error(reason);
|
|
291
|
+
|
|
268
292
|
return;
|
|
269
293
|
}
|
|
294
|
+
|
|
270
295
|
this._readableStream.destroy(reason);
|
|
271
296
|
}
|
|
272
297
|
|
|
273
298
|
_error(reason) {
|
|
274
299
|
this._storedError = reason;
|
|
300
|
+
|
|
275
301
|
this._readCapability.resolve();
|
|
276
302
|
}
|
|
277
303
|
|
|
@@ -280,23 +306,22 @@ class BaseRangeReader {
|
|
|
280
306
|
readableStream.on("readable", () => {
|
|
281
307
|
this._readCapability.resolve();
|
|
282
308
|
});
|
|
283
|
-
|
|
284
309
|
readableStream.on("end", () => {
|
|
285
310
|
// Destroy readableStream to minimize resource usage.
|
|
286
311
|
readableStream.destroy();
|
|
287
312
|
this._done = true;
|
|
313
|
+
|
|
288
314
|
this._readCapability.resolve();
|
|
289
315
|
});
|
|
290
|
-
|
|
291
316
|
readableStream.on("error", reason => {
|
|
292
317
|
this._error(reason);
|
|
293
|
-
});
|
|
318
|
+
}); // Destroy readableStream if already in errored state.
|
|
294
319
|
|
|
295
|
-
// Destroy readableStream if already in errored state.
|
|
296
320
|
if (this._storedError) {
|
|
297
321
|
this._readableStream.destroy(this._storedError);
|
|
298
322
|
}
|
|
299
323
|
}
|
|
324
|
+
|
|
300
325
|
}
|
|
301
326
|
|
|
302
327
|
function createRequestOptions(parsedUrl, headers) {
|
|
@@ -307,7 +332,7 @@ function createRequestOptions(parsedUrl, headers) {
|
|
|
307
332
|
port: parsedUrl.port,
|
|
308
333
|
path: parsedUrl.path,
|
|
309
334
|
method: "GET",
|
|
310
|
-
headers
|
|
335
|
+
headers
|
|
311
336
|
};
|
|
312
337
|
}
|
|
313
338
|
|
|
@@ -319,10 +344,14 @@ class PDFNodeStreamFullReader extends BaseFullReader {
|
|
|
319
344
|
if (response.statusCode === 404) {
|
|
320
345
|
const error = new MissingPDFException(`Missing PDF "${this._url}".`);
|
|
321
346
|
this._storedError = error;
|
|
347
|
+
|
|
322
348
|
this._headersCapability.reject(error);
|
|
349
|
+
|
|
323
350
|
return;
|
|
324
351
|
}
|
|
352
|
+
|
|
325
353
|
this._headersCapability.resolve();
|
|
354
|
+
|
|
326
355
|
this._setReadableStream(response);
|
|
327
356
|
|
|
328
357
|
const getResponseHeader = name => {
|
|
@@ -330,57 +359,59 @@ class PDFNodeStreamFullReader extends BaseFullReader {
|
|
|
330
359
|
// here: https://nodejs.org/api/http.html#http_message_headers.
|
|
331
360
|
return this._readableStream.headers[name.toLowerCase()];
|
|
332
361
|
};
|
|
333
|
-
const { allowRangeRequests, suggestedLength } =
|
|
334
|
-
validateRangeRequestCapabilities({
|
|
335
|
-
getResponseHeader,
|
|
336
|
-
isHttp: stream.isHttp,
|
|
337
|
-
rangeChunkSize: this._rangeChunkSize,
|
|
338
|
-
disableRange: this._disableRange,
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
this._isRangeSupported = allowRangeRequests;
|
|
342
|
-
// Setting right content length.
|
|
343
|
-
this._contentLength = suggestedLength || this._contentLength;
|
|
344
362
|
|
|
363
|
+
const {
|
|
364
|
+
allowRangeRequests,
|
|
365
|
+
suggestedLength
|
|
366
|
+
} = validateRangeRequestCapabilities({
|
|
367
|
+
getResponseHeader,
|
|
368
|
+
isHttp: stream.isHttp,
|
|
369
|
+
rangeChunkSize: this._rangeChunkSize,
|
|
370
|
+
disableRange: this._disableRange
|
|
371
|
+
});
|
|
372
|
+
this._isRangeSupported = allowRangeRequests; // Setting right content length.
|
|
373
|
+
|
|
374
|
+
this._contentLength = suggestedLength || this._contentLength;
|
|
345
375
|
this._filename = extractFilenameFromHeader(getResponseHeader);
|
|
346
376
|
};
|
|
347
377
|
|
|
348
378
|
this._request = null;
|
|
379
|
+
|
|
349
380
|
if (this._url.protocol === "http:") {
|
|
350
|
-
this._request = http.request(
|
|
351
|
-
createRequestOptions(this._url, stream.httpHeaders),
|
|
352
|
-
handleResponse
|
|
353
|
-
);
|
|
381
|
+
this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
|
354
382
|
} else {
|
|
355
|
-
this._request = https.request(
|
|
356
|
-
createRequestOptions(this._url, stream.httpHeaders),
|
|
357
|
-
handleResponse
|
|
358
|
-
);
|
|
383
|
+
this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
|
359
384
|
}
|
|
360
385
|
|
|
361
386
|
this._request.on("error", reason => {
|
|
362
387
|
this._storedError = reason;
|
|
388
|
+
|
|
363
389
|
this._headersCapability.reject(reason);
|
|
364
|
-
});
|
|
365
|
-
// Note: `request.end(data)` is used to write `data` to request body
|
|
390
|
+
}); // Note: `request.end(data)` is used to write `data` to request body
|
|
366
391
|
// and notify end of request. But one should always call `request.end()`
|
|
367
392
|
// even if there is no data to write -- (to notify the end of request).
|
|
393
|
+
|
|
394
|
+
|
|
368
395
|
this._request.end();
|
|
369
396
|
}
|
|
397
|
+
|
|
370
398
|
}
|
|
371
399
|
|
|
372
400
|
class PDFNodeStreamRangeReader extends BaseRangeReader {
|
|
373
401
|
constructor(stream, start, end) {
|
|
374
402
|
super(stream);
|
|
375
|
-
|
|
376
403
|
this._httpHeaders = {};
|
|
404
|
+
|
|
377
405
|
for (const property in stream.httpHeaders) {
|
|
378
406
|
const value = stream.httpHeaders[property];
|
|
407
|
+
|
|
379
408
|
if (typeof value === "undefined") {
|
|
380
409
|
continue;
|
|
381
410
|
}
|
|
411
|
+
|
|
382
412
|
this._httpHeaders[property] = value;
|
|
383
413
|
}
|
|
414
|
+
|
|
384
415
|
this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
|
|
385
416
|
|
|
386
417
|
const handleResponse = response => {
|
|
@@ -389,36 +420,32 @@ class PDFNodeStreamRangeReader extends BaseRangeReader {
|
|
|
389
420
|
this._storedError = error;
|
|
390
421
|
return;
|
|
391
422
|
}
|
|
423
|
+
|
|
392
424
|
this._setReadableStream(response);
|
|
393
425
|
};
|
|
394
426
|
|
|
395
427
|
this._request = null;
|
|
428
|
+
|
|
396
429
|
if (this._url.protocol === "http:") {
|
|
397
|
-
this._request = http.request(
|
|
398
|
-
createRequestOptions(this._url, this._httpHeaders),
|
|
399
|
-
handleResponse
|
|
400
|
-
);
|
|
430
|
+
this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
|
401
431
|
} else {
|
|
402
|
-
this._request = https.request(
|
|
403
|
-
createRequestOptions(this._url, this._httpHeaders),
|
|
404
|
-
handleResponse
|
|
405
|
-
);
|
|
432
|
+
this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
|
406
433
|
}
|
|
407
434
|
|
|
408
435
|
this._request.on("error", reason => {
|
|
409
436
|
this._storedError = reason;
|
|
410
437
|
});
|
|
438
|
+
|
|
411
439
|
this._request.end();
|
|
412
440
|
}
|
|
441
|
+
|
|
413
442
|
}
|
|
414
443
|
|
|
415
444
|
class PDFNodeStreamFsFullReader extends BaseFullReader {
|
|
416
445
|
constructor(stream) {
|
|
417
446
|
super(stream);
|
|
447
|
+
let path = decodeURIComponent(this._url.path); // Remove the extra slash to get right path from url like `file:///C:/`
|
|
418
448
|
|
|
419
|
-
let path = decodeURIComponent(this._url.path);
|
|
420
|
-
|
|
421
|
-
// Remove the extra slash to get right path from url like `file:///C:/`
|
|
422
449
|
if (fileUriRegex.test(this._url.href)) {
|
|
423
450
|
path = path.replace(/^\//, "");
|
|
424
451
|
}
|
|
@@ -428,32 +455,40 @@ class PDFNodeStreamFsFullReader extends BaseFullReader {
|
|
|
428
455
|
if (error.code === "ENOENT") {
|
|
429
456
|
error = new MissingPDFException(`Missing PDF "${path}".`);
|
|
430
457
|
}
|
|
458
|
+
|
|
431
459
|
this._storedError = error;
|
|
460
|
+
|
|
432
461
|
this._headersCapability.reject(error);
|
|
462
|
+
|
|
433
463
|
return;
|
|
434
|
-
}
|
|
435
|
-
|
|
464
|
+
} // Setting right content length.
|
|
465
|
+
|
|
466
|
+
|
|
436
467
|
this._contentLength = stat.size;
|
|
437
468
|
|
|
438
469
|
this._setReadableStream(fs.createReadStream(path));
|
|
470
|
+
|
|
439
471
|
this._headersCapability.resolve();
|
|
440
472
|
});
|
|
441
473
|
}
|
|
474
|
+
|
|
442
475
|
}
|
|
443
476
|
|
|
444
477
|
class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
|
445
478
|
constructor(stream, start, end) {
|
|
446
479
|
super(stream);
|
|
480
|
+
let path = decodeURIComponent(this._url.path); // Remove the extra slash to get right path from url like `file:///C:/`
|
|
447
481
|
|
|
448
|
-
let path = decodeURIComponent(this._url.path);
|
|
449
|
-
|
|
450
|
-
// Remove the extra slash to get right path from url like `file:///C:/`
|
|
451
482
|
if (fileUriRegex.test(this._url.href)) {
|
|
452
483
|
path = path.replace(/^\//, "");
|
|
453
484
|
}
|
|
454
485
|
|
|
455
|
-
this._setReadableStream(fs.createReadStream(path, {
|
|
486
|
+
this._setReadableStream(fs.createReadStream(path, {
|
|
487
|
+
start,
|
|
488
|
+
end: end - 1
|
|
489
|
+
}));
|
|
456
490
|
}
|
|
491
|
+
|
|
457
492
|
}
|
|
458
493
|
|
|
459
494
|
export { PDFNodeStream };
|