Browse Source

Do not switch to a range request for small PDFs

Rob Wu 11 years ago
parent
commit
2a19dc86e7
  1. 8
      src/core/pdf_manager.js
  2. 10
      src/core/worker.js

8
src/core/pdf_manager.js

@ -19,6 +19,9 @@
'use strict'; 'use strict';
// The maximum number of bytes fetched per range request
var RANGE_CHUNK_SIZE = 65536;
// TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
var BasePdfManager = (function BasePdfManagerClosure() { var BasePdfManager = (function BasePdfManagerClosure() {
function BasePdfManager() { function BasePdfManager() {
@ -132,9 +135,6 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
})(); })();
var NetworkPdfManager = (function NetworkPdfManagerClosure() { var NetworkPdfManager = (function NetworkPdfManagerClosure() {
var CHUNK_SIZE = 65536;
function NetworkPdfManager(args, msgHandler) { function NetworkPdfManager(args, msgHandler) {
this.msgHandler = msgHandler; this.msgHandler = msgHandler;
@ -147,7 +147,7 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
disableAutoFetch: args.disableAutoFetch, disableAutoFetch: args.disableAutoFetch,
initialData: args.initialData initialData: args.initialData
}; };
this.streamManager = new ChunkedStreamManager(args.length, CHUNK_SIZE, this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
args.url, params); args.url, params);
this.pdfModel = new PDFDocument(this, this.streamManager.getStream(), this.pdfModel = new PDFDocument(this, this.streamManager.getStream(),

10
src/core/worker.js

@ -18,7 +18,7 @@
MissingPDFException, PasswordException, PDFJS, Promise, MissingPDFException, PasswordException, PDFJS, Promise,
UnknownErrorException, NetworkManager, LocalPdfManager, UnknownErrorException, NetworkManager, LocalPdfManager,
NetworkPdfManager, XRefParseException, LegacyPromise, NetworkPdfManager, XRefParseException, LegacyPromise,
isInt, PasswordResponses, MessageHandler, Ref */ isInt, PasswordResponses, MessageHandler, Ref, RANGE_CHUNK_SIZE */
'use strict'; 'use strict';
@ -119,6 +119,13 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
if (!isInt(length)) { if (!isInt(length)) {
return; return;
} }
source.length = length;
if (length <= 2 * RANGE_CHUNK_SIZE) {
// The file size is smaller than the size of two chunks, so it does
// not make any sense to abort the request and retry with a range
// request.
return;
}
// NOTE: by cancelling the full request, and then issuing range // NOTE: by cancelling the full request, and then issuing range
// requests, there will be an issue for sites where you can only // requests, there will be an issue for sites where you can only
@ -126,7 +133,6 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
// server should not be returning that it can support range requests. // server should not be returning that it can support range requests.
networkManager.abortRequest(fullRequestXhrId); networkManager.abortRequest(fullRequestXhrId);
source.length = length;
try { try {
pdfManager = new NetworkPdfManager(source, handler); pdfManager = new NetworkPdfManager(source, handler);
pdfManagerPromise.resolve(pdfManager); pdfManagerPromise.resolve(pdfManager);

Loading…
Cancel
Save