mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Improve the consistency between the LocalPdfManager
/NetworkPdfManager
constructor
Currently these classes take a bunch of parameters (somewhat randomly ordered), probably because this is very old code that's been extended over the years. Hence this patch changes the constructors to use parameter-objects instead, which improves consistency and (slightly) reduces the amount of code as well. *Please note:* Also removes the `msgHandler`-property on these classes, since I cannot find a single call-site that accesses it.
This commit is contained in:
parent
903adc8708
commit
18042163ce
2 changed files with 36 additions and 71 deletions
|
@ -36,10 +36,15 @@ function parseDocBaseUrl(url) {
|
|||
}
|
||||
|
||||
class BasePdfManager {
|
||||
constructor() {
|
||||
constructor(args) {
|
||||
if (this.constructor === BasePdfManager) {
|
||||
unreachable("Cannot initialize BasePdfManager.");
|
||||
}
|
||||
this._docBaseUrl = parseDocBaseUrl(args.docBaseUrl);
|
||||
this._docId = args.docId;
|
||||
this._password = args.password;
|
||||
this.enableXfa = args.enableXfa;
|
||||
this.evaluatorOptions = args.evaluatorOptions;
|
||||
}
|
||||
|
||||
get docId() {
|
||||
|
@ -117,25 +122,10 @@ class BasePdfManager {
|
|||
}
|
||||
|
||||
class LocalPdfManager extends BasePdfManager {
|
||||
constructor(
|
||||
docId,
|
||||
data,
|
||||
password,
|
||||
msgHandler,
|
||||
evaluatorOptions,
|
||||
enableXfa,
|
||||
docBaseUrl
|
||||
) {
|
||||
super();
|
||||
constructor(args) {
|
||||
super(args);
|
||||
|
||||
this._docId = docId;
|
||||
this._password = password;
|
||||
this._docBaseUrl = parseDocBaseUrl(docBaseUrl);
|
||||
this.msgHandler = msgHandler;
|
||||
this.evaluatorOptions = evaluatorOptions;
|
||||
this.enableXfa = enableXfa;
|
||||
|
||||
const stream = new Stream(data);
|
||||
const stream = new Stream(args.source);
|
||||
this.pdfDocument = new PDFDocument(this, stream);
|
||||
this._loadedStreamPromise = Promise.resolve(stream);
|
||||
}
|
||||
|
@ -160,25 +150,11 @@ class LocalPdfManager extends BasePdfManager {
|
|||
}
|
||||
|
||||
class NetworkPdfManager extends BasePdfManager {
|
||||
constructor(
|
||||
docId,
|
||||
pdfNetworkStream,
|
||||
args,
|
||||
evaluatorOptions,
|
||||
enableXfa,
|
||||
docBaseUrl
|
||||
) {
|
||||
super();
|
||||
constructor(args) {
|
||||
super(args);
|
||||
|
||||
this._docId = docId;
|
||||
this._password = args.password;
|
||||
this._docBaseUrl = parseDocBaseUrl(docBaseUrl);
|
||||
this.msgHandler = args.msgHandler;
|
||||
this.evaluatorOptions = evaluatorOptions;
|
||||
this.enableXfa = enableXfa;
|
||||
|
||||
this.streamManager = new ChunkedStreamManager(pdfNetworkStream, {
|
||||
msgHandler: args.msgHandler,
|
||||
this.streamManager = new ChunkedStreamManager(args.source, {
|
||||
msgHandler: args.handler,
|
||||
length: args.length,
|
||||
disableAutoFetch: args.disableAutoFetch,
|
||||
rangeChunkSize: args.rangeChunkSize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue