pdfjs-dist 2.0.489 → 2.2.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/bower.json +1 -1
- package/build/pdf.js +18515 -11402
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +48266 -37137
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/external/url/url-lib.js +627 -0
- package/image_decoders/pdf.image_decoders.js +11350 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +587 -242
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +433 -61
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +400 -152
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +147 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +560 -268
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1005 -360
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +812 -195
- package/lib/core/function.js +284 -71
- package/lib/core/glyphlist.js +4 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +479 -66
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +253 -29
- package/lib/core/jpx.js +396 -6
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +15 -15
- package/lib/core/murmurhash3.js +56 -34
- package/lib/core/obj.js +1354 -488
- package/lib/core/operator_list.js +144 -31
- package/lib/core/parser.js +539 -191
- package/lib/core/pattern.js +148 -14
- package/lib/core/pdf_manager.js +323 -133
- package/lib/core/primitives.js +111 -24
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +313 -34
- package/lib/core/type1_parser.js +143 -13
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +217 -190
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +450 -133
- package/lib/display/api.js +1597 -784
- package/lib/display/api_compatibility.js +11 -13
- package/lib/display/canvas.js +360 -44
- package/lib/display/content_disposition.js +83 -32
- package/lib/display/display_utils.js +747 -0
- package/lib/display/fetch_stream.js +221 -90
- package/lib/display/font_loader.js +468 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +635 -428
- package/lib/display/network_utils.js +32 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +81 -31
- package/lib/display/svg.js +1235 -519
- package/lib/display/text_layer.js +153 -29
- package/lib/display/transport_stream.js +345 -94
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +60 -4
- package/lib/pdf.js +36 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +158 -564
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +521 -0
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/url_polyfill.js +56 -0
- package/lib/shared/util.js +243 -710
- package/lib/test/unit/annotation_spec.js +870 -401
- package/lib/test/unit/api_spec.js +657 -345
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +54 -11
- package/lib/test/unit/clitests_helper.js +10 -8
- package/lib/test/unit/cmap_spec.js +95 -41
- package/lib/test/unit/colorspace_spec.js +115 -63
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +43 -55
- package/lib/test/unit/display_svg_spec.js +34 -18
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +8 -13
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +38 -15
- package/lib/test/unit/fetch_stream_spec.js +109 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +19 -54
- package/lib/test/unit/network_utils_spec.js +91 -14
- package/lib/test/unit/node_stream_spec.js +56 -32
- package/lib/test/unit/parser_spec.js +162 -71
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +53 -20
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +273 -56
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +8 -6
- package/lib/test/unit/ui_utils_spec.js +454 -16
- package/lib/test/unit/unicode_spec.js +18 -15
- package/lib/test/unit/util_spec.js +87 -128
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1290 -588
- package/lib/web/app_options.js +100 -62
- package/lib/web/base_viewer.js +511 -182
- package/lib/web/chromecom.js +261 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +32 -13
- package/lib/web/firefox_print_service.js +20 -10
- package/lib/web/firefoxcom.js +315 -80
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +28 -4
- package/lib/web/interfaces.js +170 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +22 -14
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +255 -136
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +138 -77
- package/lib/web/pdf_outline_viewer.js +122 -46
- package/lib/web/pdf_page_view.js +191 -67
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +61 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +141 -81
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +104 -33
- package/lib/web/pdf_thumbnail_viewer.js +66 -26
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +91 -52
- package/lib/web/preferences.js +284 -89
- package/lib/web/secondary_toolbar.js +165 -40
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +78 -43
- package/lib/web/ui_utils.js +462 -136
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +4 -13
- package/package.json +5 -4
- package/web/pdf_viewer.css +79 -11
- package/web/pdf_viewer.js +6107 -3748
- package/web/pdf_viewer.js.map +1 -1
- package/lib/display/dom_utils.js +0 -309
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,34 +19,52 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var _network_utils = require(
|
24
|
+
var _network_utils = require("../../display/network_utils");
|
25
25
|
|
26
|
-
var _util = require(
|
26
|
+
var _util = require("../../shared/util");
|
27
27
|
|
28
28
|
describe('network_utils', function () {
|
29
29
|
describe('validateRangeRequestCapabilities', function () {
|
30
|
-
var defaultValues = {
|
31
|
-
allowRangeRequests: false,
|
32
|
-
suggestedLength: undefined
|
33
|
-
};
|
34
30
|
it('rejects range chunk sizes that are not larger than zero', function () {
|
35
31
|
expect(function () {
|
36
|
-
(0, _network_utils.validateRangeRequestCapabilities)({
|
32
|
+
(0, _network_utils.validateRangeRequestCapabilities)({
|
33
|
+
rangeChunkSize: 0
|
34
|
+
});
|
37
35
|
}).toThrow(new Error('Range chunk size must be larger than zero'));
|
38
36
|
});
|
39
37
|
it('rejects disabled or non-HTTP range requests', function () {
|
40
38
|
expect((0, _network_utils.validateRangeRequestCapabilities)({
|
41
39
|
disableRange: true,
|
42
40
|
isHttp: true,
|
41
|
+
getResponseHeader: function getResponseHeader(headerName) {
|
42
|
+
if (headerName === 'Content-Length') {
|
43
|
+
return 8;
|
44
|
+
}
|
45
|
+
|
46
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
47
|
+
},
|
43
48
|
rangeChunkSize: 64
|
44
|
-
})).toEqual(
|
49
|
+
})).toEqual({
|
50
|
+
allowRangeRequests: false,
|
51
|
+
suggestedLength: 8
|
52
|
+
});
|
45
53
|
expect((0, _network_utils.validateRangeRequestCapabilities)({
|
46
54
|
disableRange: false,
|
47
55
|
isHttp: false,
|
56
|
+
getResponseHeader: function getResponseHeader(headerName) {
|
57
|
+
if (headerName === 'Content-Length') {
|
58
|
+
return 8;
|
59
|
+
}
|
60
|
+
|
61
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
62
|
+
},
|
48
63
|
rangeChunkSize: 64
|
49
|
-
})).toEqual(
|
64
|
+
})).toEqual({
|
65
|
+
allowRangeRequests: false,
|
66
|
+
suggestedLength: 8
|
67
|
+
});
|
50
68
|
});
|
51
69
|
it('rejects invalid Accept-Ranges header values', function () {
|
52
70
|
expect((0, _network_utils.validateRangeRequestCapabilities)({
|
@@ -55,10 +73,17 @@ describe('network_utils', function () {
|
|
55
73
|
getResponseHeader: function getResponseHeader(headerName) {
|
56
74
|
if (headerName === 'Accept-Ranges') {
|
57
75
|
return 'none';
|
76
|
+
} else if (headerName === 'Content-Length') {
|
77
|
+
return 8;
|
58
78
|
}
|
79
|
+
|
80
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
59
81
|
},
|
60
82
|
rangeChunkSize: 64
|
61
|
-
})).toEqual(
|
83
|
+
})).toEqual({
|
84
|
+
allowRangeRequests: false,
|
85
|
+
suggestedLength: 8
|
86
|
+
});
|
62
87
|
});
|
63
88
|
it('rejects invalid Content-Encoding header values', function () {
|
64
89
|
expect((0, _network_utils.validateRangeRequestCapabilities)({
|
@@ -69,10 +94,17 @@ describe('network_utils', function () {
|
|
69
94
|
return 'bytes';
|
70
95
|
} else if (headerName === 'Content-Encoding') {
|
71
96
|
return 'gzip';
|
97
|
+
} else if (headerName === 'Content-Length') {
|
98
|
+
return 8;
|
72
99
|
}
|
100
|
+
|
101
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
73
102
|
},
|
74
103
|
rangeChunkSize: 64
|
75
|
-
})).toEqual(
|
104
|
+
})).toEqual({
|
105
|
+
allowRangeRequests: false,
|
106
|
+
suggestedLength: 8
|
107
|
+
});
|
76
108
|
});
|
77
109
|
it('rejects invalid Content-Length header values', function () {
|
78
110
|
expect((0, _network_utils.validateRangeRequestCapabilities)({
|
@@ -86,9 +118,14 @@ describe('network_utils', function () {
|
|
86
118
|
} else if (headerName === 'Content-Length') {
|
87
119
|
return 'eight';
|
88
120
|
}
|
121
|
+
|
122
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
89
123
|
},
|
90
124
|
rangeChunkSize: 64
|
91
|
-
})).toEqual(
|
125
|
+
})).toEqual({
|
126
|
+
allowRangeRequests: false,
|
127
|
+
suggestedLength: undefined
|
128
|
+
});
|
92
129
|
});
|
93
130
|
it('rejects file sizes that are too small for range requests', function () {
|
94
131
|
expect((0, _network_utils.validateRangeRequestCapabilities)({
|
@@ -102,6 +139,8 @@ describe('network_utils', function () {
|
|
102
139
|
} else if (headerName === 'Content-Length') {
|
103
140
|
return 8;
|
104
141
|
}
|
142
|
+
|
143
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
105
144
|
},
|
106
145
|
rangeChunkSize: 64
|
107
146
|
})).toEqual({
|
@@ -121,6 +160,8 @@ describe('network_utils', function () {
|
|
121
160
|
} else if (headerName === 'Content-Length') {
|
122
161
|
return 8192;
|
123
162
|
}
|
163
|
+
|
164
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
124
165
|
},
|
125
166
|
rangeChunkSize: 64
|
126
167
|
})).toEqual({
|
@@ -135,16 +176,22 @@ describe('network_utils', function () {
|
|
135
176
|
if (headerName === 'Content-Disposition') {
|
136
177
|
return null;
|
137
178
|
}
|
179
|
+
|
180
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
138
181
|
})).toBeNull();
|
139
182
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
140
183
|
if (headerName === 'Content-Disposition') {
|
141
184
|
return undefined;
|
142
185
|
}
|
186
|
+
|
187
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
143
188
|
})).toBeNull();
|
144
189
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
145
190
|
if (headerName === 'Content-Disposition') {
|
146
191
|
return '';
|
147
192
|
}
|
193
|
+
|
194
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
148
195
|
})).toBeNull();
|
149
196
|
});
|
150
197
|
it('gets the filename from the response header', function () {
|
@@ -152,36 +199,50 @@ describe('network_utils', function () {
|
|
152
199
|
if (headerName === 'Content-Disposition') {
|
153
200
|
return 'inline';
|
154
201
|
}
|
202
|
+
|
203
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
155
204
|
})).toBeNull();
|
156
205
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
157
206
|
if (headerName === 'Content-Disposition') {
|
158
207
|
return 'attachment';
|
159
208
|
}
|
209
|
+
|
210
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
160
211
|
})).toBeNull();
|
161
212
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
162
213
|
if (headerName === 'Content-Disposition') {
|
163
214
|
return 'attachment; filename="filename.pdf"';
|
164
215
|
}
|
216
|
+
|
217
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
165
218
|
})).toEqual('filename.pdf');
|
166
219
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
167
220
|
if (headerName === 'Content-Disposition') {
|
168
221
|
return 'attachment; filename="filename.pdf and spaces.pdf"';
|
169
222
|
}
|
223
|
+
|
224
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
170
225
|
})).toEqual('filename.pdf and spaces.pdf');
|
171
226
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
172
227
|
if (headerName === 'Content-Disposition') {
|
173
228
|
return 'attachment; filename="tl;dr.pdf"';
|
174
229
|
}
|
230
|
+
|
231
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
175
232
|
})).toEqual('tl;dr.pdf');
|
176
233
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
177
234
|
if (headerName === 'Content-Disposition') {
|
178
235
|
return 'attachment; filename=filename.pdf';
|
179
236
|
}
|
237
|
+
|
238
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
180
239
|
})).toEqual('filename.pdf');
|
181
240
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
182
241
|
if (headerName === 'Content-Disposition') {
|
183
242
|
return 'attachment; filename=filename.pdf someotherparam';
|
184
243
|
}
|
244
|
+
|
245
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
185
246
|
})).toEqual('filename.pdf');
|
186
247
|
});
|
187
248
|
it('gets the filename from the response header (RFC 6266)', function () {
|
@@ -189,26 +250,36 @@ describe('network_utils', function () {
|
|
189
250
|
if (headerName === 'Content-Disposition') {
|
190
251
|
return 'attachment; filename*=filename.pdf';
|
191
252
|
}
|
253
|
+
|
254
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
192
255
|
})).toEqual('filename.pdf');
|
193
256
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
194
257
|
if (headerName === 'Content-Disposition') {
|
195
258
|
return 'attachment; filename*=\'\'filename.pdf';
|
196
259
|
}
|
260
|
+
|
261
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
197
262
|
})).toEqual('filename.pdf');
|
198
263
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
199
264
|
if (headerName === 'Content-Disposition') {
|
200
265
|
return 'attachment; filename*=utf-8\'\'filename.pdf';
|
201
266
|
}
|
267
|
+
|
268
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
202
269
|
})).toEqual('filename.pdf');
|
203
270
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
204
271
|
if (headerName === 'Content-Disposition') {
|
205
272
|
return 'attachment; filename=no.pdf; filename*=utf-8\'\'filename.pdf';
|
206
273
|
}
|
274
|
+
|
275
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
207
276
|
})).toEqual('filename.pdf');
|
208
277
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
209
278
|
if (headerName === 'Content-Disposition') {
|
210
279
|
return 'attachment; filename*=utf-8\'\'filename.pdf; filename=no.pdf';
|
211
280
|
}
|
281
|
+
|
282
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
212
283
|
})).toEqual('filename.pdf');
|
213
284
|
});
|
214
285
|
it('gets the filename from the response header (RFC 2231)', function () {
|
@@ -216,6 +287,8 @@ describe('network_utils', function () {
|
|
216
287
|
if (headerName === 'Content-Disposition') {
|
217
288
|
return 'attachment; filename*0=filename; filename*1=.pdf';
|
218
289
|
}
|
290
|
+
|
291
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
219
292
|
})).toEqual('filename.pdf');
|
220
293
|
});
|
221
294
|
it('only extracts filename with pdf extension', function () {
|
@@ -223,6 +296,8 @@ describe('network_utils', function () {
|
|
223
296
|
if (headerName === 'Content-Disposition') {
|
224
297
|
return 'attachment; filename="filename.png"';
|
225
298
|
}
|
299
|
+
|
300
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
226
301
|
})).toBeNull();
|
227
302
|
});
|
228
303
|
it('extension validation is case insensitive', function () {
|
@@ -230,6 +305,8 @@ describe('network_utils', function () {
|
|
230
305
|
if (headerName === 'Content-Disposition') {
|
231
306
|
return 'form-data; name="fieldName"; filename="file.PdF"';
|
232
307
|
}
|
308
|
+
|
309
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
233
310
|
})).toEqual('file.PdF');
|
234
311
|
});
|
235
312
|
});
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,25 +19,34 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var
|
24
|
+
var _util = require("../../shared/util");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _is_node = _interopRequireDefault(require("../../shared/is_node"));
|
27
27
|
|
28
|
-
var
|
28
|
+
var _node_stream = require("../../display/node_stream");
|
29
29
|
|
30
|
-
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
31
31
|
|
32
|
-
|
32
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
33
33
|
|
34
|
-
function
|
34
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
35
|
+
|
36
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
37
|
+
|
38
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
39
|
+
|
40
|
+
(0, _util.assert)((0, _is_node["default"])());
|
35
41
|
|
36
|
-
(0, _util.assert)((0, _is_node2.default)());
|
37
42
|
var path = require('path');
|
43
|
+
|
38
44
|
var url = require('url');
|
45
|
+
|
39
46
|
var http = require('http');
|
47
|
+
|
40
48
|
var fs = require('fs');
|
49
|
+
|
41
50
|
describe('node_stream', function () {
|
42
51
|
var server = null;
|
43
52
|
var port = null;
|
@@ -49,9 +58,10 @@ describe('node_stream', function () {
|
|
49
58
|
fs.lstat(filePath, function (error, stat) {
|
50
59
|
if (error) {
|
51
60
|
response.writeHead(404);
|
52
|
-
response.end(
|
61
|
+
response.end("File ".concat(request.url, " not found!"));
|
53
62
|
return;
|
54
63
|
}
|
64
|
+
|
55
65
|
if (!request.headers['range']) {
|
56
66
|
var contentLength = stat.size;
|
57
67
|
var stream = fs.createReadStream(filePath);
|
@@ -73,7 +83,11 @@ describe('node_stream', function () {
|
|
73
83
|
start: start,
|
74
84
|
end: end
|
75
85
|
});
|
76
|
-
|
86
|
+
|
87
|
+
response.writeHead(206, {
|
88
|
+
'Content-Type': 'application/pdf'
|
89
|
+
});
|
90
|
+
|
77
91
|
_stream.pipe(response);
|
78
92
|
}
|
79
93
|
});
|
@@ -87,7 +101,7 @@ describe('node_stream', function () {
|
|
87
101
|
});
|
88
102
|
it('read both http(s) and filesystem pdf files', function (done) {
|
89
103
|
var stream1 = new _node_stream.PDFNodeStream({
|
90
|
-
url:
|
104
|
+
url: "http://127.0.0.1:".concat(port, "/tracemonkey.pdf"),
|
91
105
|
rangeChunkSize: 65536,
|
92
106
|
disableStream: true,
|
93
107
|
disableRange: true
|
@@ -100,38 +114,41 @@ describe('node_stream', function () {
|
|
100
114
|
});
|
101
115
|
var fullReader1 = stream1.getFullReader();
|
102
116
|
var fullReader2 = stream2.getFullReader();
|
103
|
-
var isStreamingSupported1
|
104
|
-
isRangeSupported1 = void 0;
|
117
|
+
var isStreamingSupported1, isRangeSupported1;
|
105
118
|
var promise1 = fullReader1.headersReady.then(function () {
|
106
119
|
isStreamingSupported1 = fullReader1.isStreamingSupported;
|
107
120
|
isRangeSupported1 = fullReader1.isRangeSupported;
|
108
121
|
});
|
109
|
-
var isStreamingSupported2
|
110
|
-
isRangeSupported2 = void 0;
|
122
|
+
var isStreamingSupported2, isRangeSupported2;
|
111
123
|
var promise2 = fullReader2.headersReady.then(function () {
|
112
124
|
isStreamingSupported2 = fullReader2.isStreamingSupported;
|
113
125
|
isRangeSupported2 = fullReader2.isRangeSupported;
|
114
126
|
});
|
115
127
|
var len1 = 0,
|
116
128
|
len2 = 0;
|
129
|
+
|
117
130
|
var read1 = function read1() {
|
118
131
|
return fullReader1.read().then(function (result) {
|
119
132
|
if (result.done) {
|
120
|
-
return;
|
133
|
+
return undefined;
|
121
134
|
}
|
135
|
+
|
122
136
|
len1 += result.value.byteLength;
|
123
137
|
return read1();
|
124
138
|
});
|
125
139
|
};
|
140
|
+
|
126
141
|
var read2 = function read2() {
|
127
142
|
return fullReader2.read().then(function (result) {
|
128
143
|
if (result.done) {
|
129
|
-
return;
|
144
|
+
return undefined;
|
130
145
|
}
|
146
|
+
|
131
147
|
len2 += result.value.byteLength;
|
132
148
|
return read2();
|
133
149
|
});
|
134
150
|
};
|
151
|
+
|
135
152
|
var readPromise = Promise.all([read1(), read2(), promise1, promise2]);
|
136
153
|
readPromise.then(function (result) {
|
137
154
|
expect(isStreamingSupported1).toEqual(false);
|
@@ -141,14 +158,14 @@ describe('node_stream', function () {
|
|
141
158
|
expect(len1).toEqual(pdfLength);
|
142
159
|
expect(len1).toEqual(len2);
|
143
160
|
done();
|
144
|
-
})
|
161
|
+
})["catch"](function (reason) {
|
145
162
|
done.fail(reason);
|
146
163
|
});
|
147
164
|
});
|
148
165
|
it('read custom ranges for both http(s) and filesystem urls', function (done) {
|
149
166
|
var rangeSize = 32768;
|
150
167
|
var stream1 = new _node_stream.PDFNodeStream({
|
151
|
-
url:
|
168
|
+
url: "http://127.0.0.1:".concat(port, "/tracemonkey.pdf"),
|
152
169
|
length: pdfLength,
|
153
170
|
rangeChunkSize: rangeSize,
|
154
171
|
disableStream: true,
|
@@ -163,12 +180,8 @@ describe('node_stream', function () {
|
|
163
180
|
});
|
164
181
|
var fullReader1 = stream1.getFullReader();
|
165
182
|
var fullReader2 = stream2.getFullReader();
|
166
|
-
var isStreamingSupported1
|
167
|
-
|
168
|
-
fullReaderCancelled1 = void 0;
|
169
|
-
var isStreamingSupported2 = void 0,
|
170
|
-
isRangeSupported2 = void 0,
|
171
|
-
fullReaderCancelled2 = void 0;
|
183
|
+
var isStreamingSupported1, isRangeSupported1, fullReaderCancelled1;
|
184
|
+
var isStreamingSupported2, isRangeSupported2, fullReaderCancelled2;
|
172
185
|
var promise1 = fullReader1.headersReady.then(function () {
|
173
186
|
isStreamingSupported1 = fullReader1.isStreamingSupported;
|
174
187
|
isRangeSupported1 = fullReader1.isRangeSupported;
|
@@ -186,19 +199,30 @@ describe('node_stream', function () {
|
|
186
199
|
var range12Reader = stream1.getRangeReader(pdfLength - tailSize, pdfLength);
|
187
200
|
var range21Reader = stream2.getRangeReader(pdfLength - tailSize - rangeSize, pdfLength - tailSize);
|
188
201
|
var range22Reader = stream2.getRangeReader(pdfLength - tailSize, pdfLength);
|
189
|
-
var result11 = {
|
190
|
-
|
191
|
-
|
192
|
-
|
202
|
+
var result11 = {
|
203
|
+
value: 0
|
204
|
+
},
|
205
|
+
result12 = {
|
206
|
+
value: 0
|
207
|
+
};
|
208
|
+
var result21 = {
|
209
|
+
value: 0
|
210
|
+
},
|
211
|
+
result22 = {
|
212
|
+
value: 0
|
213
|
+
};
|
214
|
+
|
193
215
|
var read = function read(reader, lenResult) {
|
194
216
|
return reader.read().then(function (result) {
|
195
217
|
if (result.done) {
|
196
|
-
return;
|
218
|
+
return undefined;
|
197
219
|
}
|
220
|
+
|
198
221
|
lenResult.value += result.value.byteLength;
|
199
222
|
return read(reader, lenResult);
|
200
223
|
});
|
201
224
|
};
|
225
|
+
|
202
226
|
var readPromises = Promise.all([read(range11Reader, result11), read(range12Reader, result12), read(range21Reader, result21), read(range22Reader, result22), promise1, promise2]);
|
203
227
|
readPromises.then(function () {
|
204
228
|
expect(result11.value).toEqual(rangeSize);
|
@@ -212,7 +236,7 @@ describe('node_stream', function () {
|
|
212
236
|
expect(isRangeSupported2).toEqual(true);
|
213
237
|
expect(fullReaderCancelled2).toEqual(true);
|
214
238
|
done();
|
215
|
-
})
|
239
|
+
})["catch"](function (reason) {
|
216
240
|
done.fail(reason);
|
217
241
|
});
|
218
242
|
});
|