Browse Source

PDF.js version 1.9.466 - See mozilla/pdf.js@e82811adb4ca4667e7f8f2caa96a457ed22e0243

master v1.9.466
pdfjsbot 8 years ago
parent
commit
edd10c329a
  1. 2
      bower.json
  2. 6754
      build/pdf.combined.js
  3. 2
      build/pdf.combined.js.map
  4. 5506
      build/pdf.js
  5. 2
      build/pdf.js.map
  6. 18
      build/pdf.min.js
  7. 4
      build/pdf.worker.js
  8. 2
      build/pdf.worker.js.map
  9. 4
      lib/display/api.js
  10. 4
      lib/display/global.js
  11. 47
      lib/display/network.js
  12. 57
      lib/display/network_utils.js
  13. 434
      lib/display/node_stream.js
  14. 12
      lib/pdf.js
  15. 4
      lib/pdf.worker.js
  16. 5
      lib/test/unit/jasmine-boot.js
  17. 214
      lib/test/unit/node_stream_spec.js
  18. 2
      package.json

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.9.462", "version": "1.9.466",
"main": [ "main": [
"build/pdf.js", "build/pdf.js",
"build/pdf.worker.js" "build/pdf.worker.js"

6754
build/pdf.combined.js

File diff suppressed because it is too large Load Diff

2
build/pdf.combined.js.map

File diff suppressed because one or more lines are too long

5506
build/pdf.js

File diff suppressed because it is too large Load Diff

2
build/pdf.js.map

File diff suppressed because one or more lines are too long

18
build/pdf.min.js vendored

File diff suppressed because one or more lines are too long

4
build/pdf.worker.js vendored

@ -42129,8 +42129,8 @@ exports.Type1Parser = Type1Parser;
"use strict"; "use strict";
var pdfjsVersion = '1.9.462'; var pdfjsVersion = '1.9.466';
var pdfjsBuild = 'e9ba5494'; var pdfjsBuild = 'e82811ad';
var pdfjsCoreWorker = __w_pdfjs_require__(61); var pdfjsCoreWorker = __w_pdfjs_require__(61);
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler; exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;

2
build/pdf.worker.js.map vendored

File diff suppressed because one or more lines are too long

4
lib/display/api.js

@ -1581,8 +1581,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '1.9.462'; exports.version = version = '1.9.466';
exports.build = build = 'e9ba5494'; exports.build = build = 'e82811ad';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;

4
lib/display/global.js

@ -45,8 +45,8 @@ if (!_global_scope2.default.PDFJS) {
} }
var PDFJS = _global_scope2.default.PDFJS; var PDFJS = _global_scope2.default.PDFJS;
{ {
PDFJS.version = '1.9.462'; PDFJS.version = '1.9.466';
PDFJS.build = 'e9ba5494'; PDFJS.build = 'e82811ad';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {

47
lib/display/network.js

@ -25,7 +25,7 @@ var _global_scope = require('../shared/global_scope');
var _global_scope2 = _interopRequireDefault(_global_scope); var _global_scope2 = _interopRequireDefault(_global_scope);
var _api = require('./api'); var _network_utils = require('./network_utils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@ -285,40 +285,26 @@ function PDFNetworkStreamFullRequestReader(manager, options) {
this.onProgress = null; this.onProgress = null;
} }
PDFNetworkStreamFullRequestReader.prototype = { PDFNetworkStreamFullRequestReader.prototype = {
_validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() { _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
if (this._disableRange) {
return false;
}
var networkManager = this._manager;
if (!networkManager.isHttp) {
return false;
}
var fullRequestXhrId = this._fullRequestId; var fullRequestXhrId = this._fullRequestId;
var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId); var fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
return false; var _validateRangeRequest = (0, _network_utils.validateRangeRequestCapabilities)({
} getResponseHeader: function getResponseHeader(name) {
var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity'; return fullRequestXhr.getResponseHeader(name);
if (contentEncoding !== 'identity') {
return false;
}
var length = fullRequestXhr.getResponseHeader('Content-Length');
length = parseInt(length, 10);
if (!(0, _util.isInt)(length)) {
return false;
}
this._contentLength = length;
if (length <= 2 * this._rangeChunkSize) {
return false;
}
return true;
}, },
_onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() { isHttp: this._manager.isHttp,
if (this._validateRangeRequestCapabilities()) { rangeChunkSize: this._rangeChunkSize,
disableRange: this._disableRange
}),
allowRangeRequests = _validateRangeRequest.allowRangeRequests,
suggestedLength = _validateRangeRequest.suggestedLength;
this._contentLength = suggestedLength || this._contentLength;
if (allowRangeRequests) {
this._isRangeSupported = true; this._isRangeSupported = true;
} }
var networkManager = this._manager; var networkManager = this._manager;
var fullRequestXhrId = this._fullRequestId;
if (networkManager.isStreamingRequest(fullRequestXhrId)) { if (networkManager.isStreamingRequest(fullRequestXhrId)) {
this._isStreamingSupported = true; this._isStreamingSupported = true;
} else if (this._isRangeSupported) { } else if (this._isRangeSupported) {
@ -508,6 +494,5 @@ PDFNetworkStreamRangeRequestReader.prototype = {
this._close(); this._close();
} }
}; };
(0, _api.setPDFNetworkStreamClass)(PDFNetworkStream);
exports.PDFNetworkStream = PDFNetworkStream; exports.PDFNetworkStream = PDFNetworkStream;
exports.NetworkManager = NetworkManager; exports.NetworkManager = NetworkManager;

57
lib/display/network_utils.js

@ -0,0 +1,57 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateRangeRequestCapabilities = undefined;
var _util = require('../shared/util');
function validateRangeRequestCapabilities(_ref) {
var getResponseHeader = _ref.getResponseHeader,
isHttp = _ref.isHttp,
rangeChunkSize = _ref.rangeChunkSize,
disableRange = _ref.disableRange;
(0, _util.assert)(rangeChunkSize > 0);
var returnValues = {
allowRangeRequests: false,
suggestedLength: undefined
};
if (disableRange || !isHttp) {
return returnValues;
}
if (getResponseHeader('Accept-Ranges') !== 'bytes') {
return returnValues;
}
var contentEncoding = getResponseHeader('Content-Encoding') || 'identity';
if (contentEncoding !== 'identity') {
return returnValues;
}
var length = getResponseHeader('Content-Length');
length = parseInt(length, 10);
if (!(0, _util.isInt)(length)) {
return returnValues;
}
returnValues.suggestedLength = length;
if (length <= 2 * rangeChunkSize) {
return returnValues;
}
returnValues.allowRangeRequests = true;
return returnValues;
}
exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;

434
lib/display/node_stream.js

@ -0,0 +1,434 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PDFNodeStream = undefined;
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; }; }();
var _util = require('../shared/util');
var _network_utils = require('./network_utils');
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; }
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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var fs = require('fs');
var http = require('http');
var https = require('https');
var url = require('url');
var PDFNodeStream = function () {
function PDFNodeStream(options) {
_classCallCheck(this, PDFNodeStream);
this.options = options;
this.source = options.source;
this.url = url.parse(this.source.url);
this.isHttp = this.url.protocol === 'http:' || this.url.protocol === 'https:';
this.isFsUrl = this.url.protocol === 'file:' || !this.url.host;
this.httpHeaders = this.isHttp && this.source.httpHeaders || {};
this._fullRequest = null;
this._rangeRequestReaders = [];
}
_createClass(PDFNodeStream, [{
key: 'getFullReader',
value: function getFullReader() {
(0, _util.assert)(!this._fullRequest);
this._fullRequest = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
return this._fullRequest;
}
}, {
key: 'getRangeReader',
value: function getRangeReader(start, end) {
var rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
this._rangeRequestReaders.push(rangeReader);
return rangeReader;
}
}, {
key: 'cancelAllRequests',
value: function cancelAllRequests(reason) {
if (this._fullRequest) {
this._fullRequest.cancel(reason);
}
var readers = this._rangeRequestReaders.slice(0);
readers.forEach(function (reader) {
reader.cancel(reason);
});
}
}]);
return PDFNodeStream;
}();
var BaseFullReader = function () {
function BaseFullReader(stream) {
_classCallCheck(this, BaseFullReader);
this._url = stream.url;
this._done = false;
this._errored = false;
this._reason = null;
this.onProgress = null;
this._contentLength = stream.source.length;
this._loaded = 0;
this._disableRange = stream.options.disableRange || false;
this._rangeChunkSize = stream.source.rangeChunkSize;
if (!this._rangeChunkSize && !this._disableRange) {
this._disableRange = true;
}
this._isStreamingSupported = !stream.source.disableStream;
this._isRangeSupported = !stream.options.disableRange;
this._readableStream = null;
this._readCapability = (0, _util.createPromiseCapability)();
this._headersCapability = (0, _util.createPromiseCapability)();
}
_createClass(BaseFullReader, [{
key: 'read',
value: function read() {
var _this = this;
return this._readCapability.promise.then(function () {
if (_this._done) {
return Promise.resolve({
value: undefined,
done: true
});
}
if (_this._errored) {
return Promise.reject(_this._reason);
}
var chunk = _this._readableStream.read();
if (chunk === null) {
_this._readCapability = (0, _util.createPromiseCapability)();
return _this.read();
}
_this._loaded += chunk.length;
if (_this.onProgress) {
_this.onProgress({
loaded: _this._loaded,
total: _this._contentLength
});
}
var buffer = new Uint8Array(chunk).buffer;
return Promise.resolve({
value: buffer,
done: false
});
});
}
}, {
key: 'cancel',
value: function cancel(reason) {
if (!this._readableStream) {
this._error(reason);
return;
}
this._readableStream.destroy(reason);
}
}, {
key: '_error',
value: function _error(reason) {
this._errored = true;
this._reason = reason;
this._readCapability.resolve();
}
}, {
key: '_setReadableStream',
value: function _setReadableStream(readableStream) {
var _this2 = this;
this._readableStream = readableStream;
readableStream.on('readable', function () {
_this2._readCapability.resolve();
});
readableStream.on('end', function () {
readableStream.destroy();
_this2._done = true;
_this2._readCapability.resolve();
});
readableStream.on('error', function (reason) {
_this2._error(reason);
});
if (this._errored) {
this._readableStream.destroy(this._reason);
}
}
}, {
key: 'headersReady',
get: function get() {
return this._headersCapability.promise;
}
}, {
key: 'contentLength',
get: function get() {
return this._contentLength;
}
}, {
key: 'isRangeSupported',
get: function get() {
return this._isRangeSupported;
}
}, {
key: 'isStreamingSupported',
get: function get() {
return this._isStreamingSupported;
}
}]);
return BaseFullReader;
}();
var BaseRangeReader = function () {
function BaseRangeReader(stream) {
_classCallCheck(this, BaseRangeReader);
this._url = stream.url;
this._done = false;
this._errored = false;
this._reason = null;
this.onProgress = null;
this._loaded = 0;
this._readableStream = null;
this._readCapability = (0, _util.createPromiseCapability)();
this._isStreamingSupported = !stream.source.disableStream;
}
_createClass(BaseRangeReader, [{
key: 'read',
value: function read() {
var _this3 = this;
return this._readCapability.promise.then(function () {
if (_this3._done) {
return Promise.resolve({
value: undefined,
done: true
});
}
if (_this3._errored) {
return Promise.reject(_this3._reason);
}
var chunk = _this3._readableStream.read();
if (chunk === null) {
_this3._readCapability = (0, _util.createPromiseCapability)();
return _this3.read();
}
_this3._loaded += chunk.length;
if (_this3.onProgress) {
_this3.onProgress({ loaded: _this3._loaded });
}
var buffer = new Uint8Array(chunk).buffer;
return Promise.resolve({
value: buffer,
done: false
});
});
}
}, {
key: 'cancel',
value: function cancel(reason) {
if (!this._readableStream) {
this._error(reason);
return;
}
this._readableStream.destroy(reason);
}
}, {
key: '_error',
value: function _error(reason) {
this._errored = true;
this._reason = reason;
this._readCapability.resolve();
}
}, {
key: '_setReadableStream',
value: function _setReadableStream(readableStream) {
var _this4 = this;
this._readableStream = readableStream;
readableStream.on('readable', function () {
_this4._readCapability.resolve();
});
readableStream.on('end', function () {
readableStream.destroy();
_this4._done = true;
_this4._readCapability.resolve();
});
readableStream.on('error', function (reason) {
_this4._error(reason);
});
if (this._errored) {
this._readableStream.destroy(this._reason);
}
}
}, {
key: 'isStreamingSupported',
get: function get() {
return this._isStreamingSupported;
}
}]);
return BaseRangeReader;
}();
function createRequestOptions(url, headers) {
return {
protocol: url.protocol,
auth: url.auth,
host: url.hostname,
port: url.port,
path: url.path,
method: 'GET',
headers: headers
};
}
var PDFNodeStreamFullReader = function (_BaseFullReader) {
_inherits(PDFNodeStreamFullReader, _BaseFullReader);
function PDFNodeStreamFullReader(stream) {
_classCallCheck(this, PDFNodeStreamFullReader);
var _this5 = _possibleConstructorReturn(this, (PDFNodeStreamFullReader.__proto__ || Object.getPrototypeOf(PDFNodeStreamFullReader)).call(this, stream));
var handleResponse = function handleResponse(response) {
_this5._headersCapability.resolve();
_this5._setReadableStream(response);
var _validateRangeRequest = (0, _network_utils.validateRangeRequestCapabilities)({
getResponseHeader: function getResponseHeader(name) {
return _this5._readableStream.headers[name.toLowerCase()];
},
isHttp: stream.isHttp,
rangeChunkSize: _this5._rangeChunkSize,
disableRange: _this5._disableRange
}),
allowRangeRequests = _validateRangeRequest.allowRangeRequests,
suggestedLength = _validateRangeRequest.suggestedLength;
if (allowRangeRequests) {
_this5._isRangeSupported = true;
}
_this5._contentLength = suggestedLength;
};
_this5._request = null;
if (_this5._url.protocol === 'http:') {
_this5._request = http.request(createRequestOptions(_this5._url, stream.httpHeaders), handleResponse);
} else {
_this5._request = https.request(createRequestOptions(_this5._url, stream.httpHeaders), handleResponse);
}
_this5._request.on('error', function (reason) {
_this5._errored = true;
_this5._reason = reason;
_this5._headersCapability.reject(reason);
});
_this5._request.end();
return _this5;
}
return PDFNodeStreamFullReader;
}(BaseFullReader);
var PDFNodeStreamRangeReader = function (_BaseRangeReader) {
_inherits(PDFNodeStreamRangeReader, _BaseRangeReader);
function PDFNodeStreamRangeReader(stream, start, end) {
_classCallCheck(this, PDFNodeStreamRangeReader);
var _this6 = _possibleConstructorReturn(this, (PDFNodeStreamRangeReader.__proto__ || Object.getPrototypeOf(PDFNodeStreamRangeReader)).call(this, stream));
_this6._httpHeaders = {};
for (var property in stream.httpHeaders) {
var value = stream.httpHeaders[property];
if (typeof value === 'undefined') {
continue;
}
_this6._httpHeaders[property] = value;
}
_this6._httpHeaders['Range'] = 'bytes=' + start + '-' + (end - 1);
_this6._request = null;
if (_this6._url.protocol === 'http:') {
_this6._request = http.request(createRequestOptions(_this6._url, _this6._httpHeaders), function (response) {
_this6._setReadableStream(response);
});
} else {
_this6._request = https.request(createRequestOptions(_this6._url, _this6._httpHeaders), function (response) {
_this6._setReadableStream(response);
});
}
_this6._request.on('error', function (reason) {
_this6._errored = true;
_this6._reason = reason;
});
_this6._request.end();
return _this6;
}
return PDFNodeStreamRangeReader;
}(BaseRangeReader);
var PDFNodeStreamFsFullReader = function (_BaseFullReader2) {
_inherits(PDFNodeStreamFsFullReader, _BaseFullReader2);
function PDFNodeStreamFsFullReader(stream) {
_classCallCheck(this, PDFNodeStreamFsFullReader);
var _this7 = _possibleConstructorReturn(this, (PDFNodeStreamFsFullReader.__proto__ || Object.getPrototypeOf(PDFNodeStreamFsFullReader)).call(this, stream));
_this7._setReadableStream(fs.createReadStream(_this7._url.path));
fs.lstat(_this7._url.path, function (error, stat) {
if (error) {
_this7._errored = true;
_this7._reason = error;
_this7._headersCapability.reject(error);
return;
}
_this7._contentLength = stat.size;
_this7._headersCapability.resolve();
});
return _this7;
}
return PDFNodeStreamFsFullReader;
}(BaseFullReader);
var PDFNodeStreamFsRangeReader = function (_BaseRangeReader2) {
_inherits(PDFNodeStreamFsRangeReader, _BaseRangeReader2);
function PDFNodeStreamFsRangeReader(stream, start, end) {
_classCallCheck(this, PDFNodeStreamFsRangeReader);
var _this8 = _possibleConstructorReturn(this, (PDFNodeStreamFsRangeReader.__proto__ || Object.getPrototypeOf(PDFNodeStreamFsRangeReader)).call(this, stream));
_this8._setReadableStream(fs.createReadStream(_this8._url.path, {
start: start,
end: end - 1
}));
return _this8;
}
return PDFNodeStreamFsRangeReader;
}(BaseRangeReader);
exports.PDFNodeStream = PDFNodeStream;

12
lib/pdf.js

@ -14,8 +14,8 @@
*/ */
'use strict'; 'use strict';
var pdfjsVersion = '1.9.462'; var pdfjsVersion = '1.9.466';
var pdfjsBuild = 'e9ba5494'; var pdfjsBuild = 'e82811ad';
var pdfjsSharedUtil = require('./shared/util.js'); var pdfjsSharedUtil = require('./shared/util.js');
var pdfjsDisplayGlobal = require('./display/global.js'); var pdfjsDisplayGlobal = require('./display/global.js');
var pdfjsDisplayAPI = require('./display/api.js'); var pdfjsDisplayAPI = require('./display/api.js');
@ -24,7 +24,13 @@ var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
var pdfjsDisplayDOMUtils = require('./display/dom_utils.js'); var pdfjsDisplayDOMUtils = require('./display/dom_utils.js');
var pdfjsDisplaySVG = require('./display/svg.js'); var pdfjsDisplaySVG = require('./display/svg.js');
{ {
require('./display/network.js'); if (pdfjsSharedUtil.isNodeJS()) {
var PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFNodeStream);
} else {
var PDFNetworkStream = require('./display/network.js').PDFNetworkStream;
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFNetworkStream);
}
} }
exports.PDFJS = pdfjsDisplayGlobal.PDFJS; exports.PDFJS = pdfjsDisplayGlobal.PDFJS;
exports.build = pdfjsDisplayAPI.build; exports.build = pdfjsDisplayAPI.build;

4
lib/pdf.worker.js vendored

@ -14,7 +14,7 @@
*/ */
'use strict'; 'use strict';
var pdfjsVersion = '1.9.462'; var pdfjsVersion = '1.9.466';
var pdfjsBuild = 'e9ba5494'; var pdfjsBuild = 'e82811ad';
var pdfjsCoreWorker = require('./core/worker.js'); var pdfjsCoreWorker = require('./core/worker.js');
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler; exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;

5
lib/test/unit/jasmine-boot.js

@ -15,10 +15,13 @@
'use strict'; 'use strict';
function initializePDFJS(callback) { function initializePDFJS(callback) {
Promise.all(['pdfjs/display/global', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/colorspace_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/custom_spec', 'pdfjs-test/unit/display_svg_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec', 'pdfjs-test/unit/util_stream_spec'].map(function (moduleName) { Promise.all(['pdfjs/display/global', 'pdfjs/display/api', 'pdfjs/display/network', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/colorspace_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/custom_spec', 'pdfjs-test/unit/display_svg_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec', 'pdfjs-test/unit/util_stream_spec'].map(function (moduleName) {
return SystemJS.import(moduleName); return SystemJS.import(moduleName);
})).then(function (modules) { })).then(function (modules) {
var displayGlobal = modules[0]; var displayGlobal = modules[0];
var displayApi = modules[1];
var PDFNetworkStream = modules[2].PDFNetworkStream;
displayApi.setPDFNetworkStreamClass(PDFNetworkStream);
displayGlobal.PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js'; displayGlobal.PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js';
displayGlobal.PDFJS.pdfjsNext = true; displayGlobal.PDFJS.pdfjsNext = true;
callback(); callback();

214
lib/test/unit/node_stream_spec.js

@ -0,0 +1,214 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
var _slicedToArray = function () { function sliceIterator(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"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _util = require('../../shared/util');
var _node_stream = require('../../display/node_stream');
(0, _util.assert)((0, _util.isNodeJS)());
var path = require('path');
var url = require('url');
var http = require('http');
var fs = require('fs');
describe('node_stream', function () {
var server = null;
var port = null;
var pdf = url.parse(encodeURI('file://' + path.join(process.cwd(), './test/pdfs/tracemonkey.pdf'))).href;
var pdfLength = 1016315;
beforeAll(function (done) {
server = http.createServer(function (request, response) {
var filePath = process.cwd() + '/test/pdfs' + request.url;
fs.lstat(filePath, function (error, stat) {
if (error) {
response.writeHead(404);
response.end('File ' + request.url + ' not found!');
return;
}
if (!request.headers['range']) {
var contentLength = stat.size;
var stream = fs.createReadStream(filePath);
response.writeHead(200, {
'Content-Type': 'application/pdf',
'Content-Length': contentLength,
'Accept-Ranges': 'bytes'
});
stream.pipe(response);
} else {
var _request$headers$rang = request.headers['range'].split('=')[1].split('-').map(function (x) {
return Number(x);
}),
_request$headers$rang2 = _slicedToArray(_request$headers$rang, 2),
start = _request$headers$rang2[0],
end = _request$headers$rang2[1];
var _stream = fs.createReadStream(filePath, {
start: start,
end: end
});
response.writeHead(206, { 'Content-Type': 'application/pdf' });
_stream.pipe(response);
}
});
}).listen(0);
port = server.address().port;
done();
});
afterAll(function (done) {
server.close();
done();
});
it('read both http(s) and filesystem pdf files', function (done) {
var stream1 = new _node_stream.PDFNodeStream({
source: {
url: 'http://127.0.0.1:' + port + '/tracemonkey.pdf',
rangeChunkSize: 65536,
disableStream: true
},
disableRange: true
});
var stream2 = new _node_stream.PDFNodeStream({
source: {
url: pdf,
rangeChunkSize: 65536,
disableStream: true
},
disableRange: true
});
var fullReader1 = stream1.getFullReader();
var fullReader2 = stream2.getFullReader();
var isStreamingSupported1 = void 0,
isRangeSupported1 = void 0;
var promise1 = fullReader1.headersReady.then(function () {
isStreamingSupported1 = fullReader1.isStreamingSupported;
isRangeSupported1 = fullReader1.isRangeSupported;
});
var isStreamingSupported2 = void 0,
isRangeSupported2 = void 0;
var promise2 = fullReader2.headersReady.then(function () {
isStreamingSupported2 = fullReader2.isStreamingSupported;
isRangeSupported2 = fullReader2.isRangeSupported;
});
var len1 = 0,
len2 = 0;
var read1 = function read1() {
return fullReader1.read().then(function (result) {
if (result.done) {
return;
}
len1 += result.value.byteLength;
return read1();
});
};
var read2 = function read2() {
return fullReader2.read().then(function (result) {
if (result.done) {
return;
}
len2 += result.value.byteLength;
return read2();
});
};
var readPromise = Promise.all([read1(), read2(), promise1, promise2]);
readPromise.then(function (result) {
expect(isStreamingSupported1).toEqual(false);
expect(isRangeSupported1).toEqual(false);
expect(isStreamingSupported2).toEqual(false);
expect(isRangeSupported2).toEqual(false);
expect(len1).toEqual(pdfLength);
expect(len1).toEqual(len2);
done();
}).catch(function (reason) {
done.fail(reason);
});
});
it('read custom ranges for both http(s) and filesystem urls', function (done) {
var rangeSize = 32768;
var stream1 = new _node_stream.PDFNodeStream({
source: {
url: 'http://127.0.0.1:' + port + '/tracemonkey.pdf',
length: pdfLength,
rangeChunkSize: rangeSize,
disableStream: true
},
disableRange: false
});
var stream2 = new _node_stream.PDFNodeStream({
source: {
url: pdf,
length: pdfLength,
rangeChunkSize: rangeSize,
disableStream: true
},
disableRange: false
});
var fullReader1 = stream1.getFullReader();
var fullReader2 = stream2.getFullReader();
var isStreamingSupported1 = void 0,
isRangeSupported1 = void 0,
fullReaderCancelled1 = void 0;
var isStreamingSupported2 = void 0,
isRangeSupported2 = void 0,
fullReaderCancelled2 = void 0;
var promise1 = fullReader1.headersReady.then(function () {
isStreamingSupported1 = fullReader1.isStreamingSupported;
isRangeSupported1 = fullReader1.isRangeSupported;
fullReader1.cancel('Don\'t need full reader');
fullReaderCancelled1 = true;
});
var promise2 = fullReader2.headersReady.then(function () {
isStreamingSupported2 = fullReader2.isStreamingSupported;
isRangeSupported2 = fullReader2.isRangeSupported;
fullReader2.cancel('Don\'t need full reader');
fullReaderCancelled2 = true;
});
var tailSize = pdfLength % rangeSize || rangeSize;
var range11Reader = stream1.getRangeReader(pdfLength - tailSize - rangeSize, pdfLength - tailSize);
var range12Reader = stream1.getRangeReader(pdfLength - tailSize, pdfLength);
var range21Reader = stream2.getRangeReader(pdfLength - tailSize - rangeSize, pdfLength - tailSize);
var range22Reader = stream2.getRangeReader(pdfLength - tailSize, pdfLength);
var result11 = { value: 0 },
result12 = { value: 0 };
var result21 = { value: 0 },
result22 = { value: 0 };
var read = function read(reader, lenResult) {
return reader.read().then(function (result) {
if (result.done) {
return;
}
lenResult.value += result.value.byteLength;
return read(reader, lenResult);
});
};
var readPromises = Promise.all([read(range11Reader, result11), read(range12Reader, result12), read(range21Reader, result21), read(range22Reader, result22), promise1, promise2]);
readPromises.then(function () {
expect(result11.value).toEqual(rangeSize);
expect(result12.value).toEqual(tailSize);
expect(result21.value).toEqual(rangeSize);
expect(result22.value).toEqual(tailSize);
expect(isStreamingSupported1).toEqual(false);
expect(isRangeSupported1).toEqual(true);
expect(fullReaderCancelled1).toEqual(true);
expect(isStreamingSupported2).toEqual(false);
expect(isRangeSupported2).toEqual(true);
expect(fullReaderCancelled2).toEqual(true);
done();
}).catch(function (reason) {
done.fail(reason);
});
});
});

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.9.462", "version": "1.9.466",
"main": "build/pdf.js", "main": "build/pdf.js",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [

Loading…
Cancel
Save