mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Re-factor how parameters are passed to the network streams
*This patch is the result of me starting to look into moving parameters from `PDFJS` into `getDocument` and other API methods.* When familiarizing myself with the code, the signatures of the various network streams seemed to be unnecessarily cumbersome since `disableRange` is currently handled separately from other parameters. I'm assuming that the explanation for this is probably "for historical reasons", as is often the case. Hence I'd like to clean this up *before* we start the larger, and more invasive, `PDFJS` parameter re-factoring.
This commit is contained in:
parent
0052dc2b0d
commit
23699cef1c
6 changed files with 65 additions and 81 deletions
|
@ -25,15 +25,14 @@ import {
|
|||
import { validateRangeRequestCapabilities } from './network_utils';
|
||||
|
||||
class PDFNodeStream {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
this.source = options.source;
|
||||
this.url = url.parse(this.source.url);
|
||||
constructor(source) {
|
||||
this.source = source;
|
||||
this.url = url.parse(source.url);
|
||||
this.isHttp = this.url.protocol === 'http:' ||
|
||||
this.url.protocol === 'https:';
|
||||
// Check if url refers to filesystem.
|
||||
this.isFsUrl = this.url.protocol === 'file:' || !this.url.host;
|
||||
this.httpHeaders = (this.isHttp && this.source.httpHeaders) || {};
|
||||
this.httpHeaders = (this.isHttp && source.httpHeaders) || {};
|
||||
|
||||
this._fullRequest = null;
|
||||
this._rangeRequestReaders = [];
|
||||
|
@ -74,17 +73,18 @@ class BaseFullReader {
|
|||
this._errored = false;
|
||||
this._reason = null;
|
||||
this.onProgress = null;
|
||||
this._contentLength = stream.source.length; // optional
|
||||
let source = stream.source;
|
||||
this._contentLength = source.length; // optional
|
||||
this._loaded = 0;
|
||||
|
||||
this._disableRange = stream.options.disableRange || false;
|
||||
this._rangeChunkSize = stream.source.rangeChunkSize;
|
||||
this._disableRange = source.disableRange || false;
|
||||
this._rangeChunkSize = source.rangeChunkSize;
|
||||
if (!this._rangeChunkSize && !this._disableRange) {
|
||||
this._disableRange = true;
|
||||
}
|
||||
|
||||
this._isStreamingSupported = !stream.source.disableStream;
|
||||
this._isRangeSupported = !stream.options.disableRange;
|
||||
this._isStreamingSupported = !source.disableStream;
|
||||
this._isRangeSupported = !source.disableRange;
|
||||
|
||||
this._readableStream = null;
|
||||
this._readCapability = createPromiseCapability();
|
||||
|
@ -190,8 +190,8 @@ class BaseRangeReader {
|
|||
this._loaded = 0;
|
||||
this._readableStream = null;
|
||||
this._readCapability = createPromiseCapability();
|
||||
|
||||
this._isStreamingSupported = !stream.source.disableStream;
|
||||
let source = stream.source;
|
||||
this._isStreamingSupported = !source.disableStream;
|
||||
}
|
||||
|
||||
get isStreamingSupported() {
|
||||
|
@ -303,11 +303,13 @@ class PDFNodeStreamFullReader extends BaseFullReader {
|
|||
|
||||
this._request = null;
|
||||
if (this._url.protocol === 'http:') {
|
||||
this._request = http.request(createRequestOptions(
|
||||
this._url, stream.httpHeaders), handleResponse);
|
||||
this._request = http.request(
|
||||
createRequestOptions(this._url, stream.httpHeaders),
|
||||
handleResponse);
|
||||
} else {
|
||||
this._request = https.request(createRequestOptions(
|
||||
this._url, stream.httpHeaders), handleResponse);
|
||||
this._request = https.request(
|
||||
createRequestOptions(this._url, stream.httpHeaders),
|
||||
handleResponse);
|
||||
}
|
||||
|
||||
this._request.on('error', (reason) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue