Skip to content

Commit

Permalink
Update fetch_stream.js to use const in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffleupagus committed May 16, 2019
1 parent 7377052 commit cc661a4
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/display/fetch_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint no-var: error */

import {
AbortException, assert, createPromiseCapability
Expand All @@ -32,6 +33,7 @@ function createFetchOptions(headers, withCredentials, abortController) {
};
}

/** @implements {IPDFStream} */
class PDFFetchStream {
constructor(source) {
this.source = source;
Expand All @@ -56,7 +58,7 @@ class PDFFetchStream {
if (end <= this._progressiveDataLength) {
return null;
}
let reader = new PDFFetchStreamRangeReader(this, begin, end);
const reader = new PDFFetchStreamRangeReader(this, begin, end);
this._rangeRequestReaders.push(reader);
return reader;
}
Expand All @@ -65,21 +67,22 @@ class PDFFetchStream {
if (this._fullRequestReader) {
this._fullRequestReader.cancel(reason);
}
let readers = this._rangeRequestReaders.slice(0);
const readers = this._rangeRequestReaders.slice(0);
readers.forEach(function(reader) {
reader.cancel(reason);
});
}
}

/** @implements {IPDFStreamReader} */
class PDFFetchStreamReader {
constructor(stream) {
this._stream = stream;
this._reader = null;
this._loaded = 0;
this._filename = null;
let source = stream.source;
this._withCredentials = source.withCredentials;
const source = stream.source;
this._withCredentials = source.withCredentials || false;
this._contentLength = source.length;
this._headersCapability = createPromiseCapability();
this._disableRange = source.disableRange || false;
Expand All @@ -95,15 +98,15 @@ class PDFFetchStreamReader {
this._isRangeSupported = !source.disableRange;

this._headers = new Headers();
for (let property in this._stream.httpHeaders) {
let value = this._stream.httpHeaders[property];
for (const property in this._stream.httpHeaders) {
const value = this._stream.httpHeaders[property];
if (typeof value === 'undefined') {
continue;
}
this._headers.append(property, value);
}

let url = source.url;
const url = source.url;
fetch(url, createFetchOptions(this._headers, this._withCredentials,
this._abortController)).then((response) => {
if (!validateResponseStatus(response.status)) {
Expand All @@ -115,7 +118,7 @@ class PDFFetchStreamReader {
const getResponseHeader = (name) => {
return response.headers.get(name);
};
let { allowRangeRequests, suggestedLength, } =
const { allowRangeRequests, suggestedLength, } =
validateRangeRequestCapabilities({
getResponseHeader,
isHttp: this._stream.isHttp,
Expand All @@ -132,7 +135,7 @@ class PDFFetchStreamReader {
// We need to stop reading when range is supported and streaming is
// disabled.
if (!this._isStreamingSupported && this._isRangeSupported) {
this.cancel(new AbortException('streaming is disabled'));
this.cancel(new AbortException('Streaming is disabled.'));
}
}).catch(this._headersCapability.reject);

Expand Down Expand Up @@ -172,7 +175,7 @@ class PDFFetchStreamReader {
total: this._contentLength,
});
}
let buffer = new Uint8Array(value).buffer;
const buffer = new Uint8Array(value).buffer;
return { value: buffer, done: false, };
}

Expand All @@ -186,13 +189,14 @@ class PDFFetchStreamReader {
}
}

/** @implements {IPDFStreamRangeReader} */
class PDFFetchStreamRangeReader {
constructor(stream, begin, end) {
this._stream = stream;
this._reader = null;
this._loaded = 0;
let source = stream.source;
this._withCredentials = source.withCredentials;
const source = stream.source;
this._withCredentials = source.withCredentials || false;
this._readCapability = createPromiseCapability();
this._isStreamingSupported = !source.disableStream;

Expand All @@ -201,17 +205,16 @@ class PDFFetchStreamRangeReader {
}

this._headers = new Headers();
for (let property in this._stream.httpHeaders) {
let value = this._stream.httpHeaders[property];
for (const property in this._stream.httpHeaders) {
const value = this._stream.httpHeaders[property];
if (typeof value === 'undefined') {
continue;
}
this._headers.append(property, value);
}
this._headers.append('Range', `bytes=${begin}-${end - 1}`);

let rangeStr = begin + '-' + (end - 1);
this._headers.append('Range', 'bytes=' + rangeStr);
let url = source.url;
const url = source.url;
fetch(url, createFetchOptions(this._headers, this._withCredentials,
this._abortController)).then((response) => {
if (!validateResponseStatus(response.status)) {
Expand All @@ -238,7 +241,7 @@ class PDFFetchStreamRangeReader {
if (this.onProgress) {
this.onProgress({ loaded: this._loaded, });
}
let buffer = new Uint8Array(value).buffer;
const buffer = new Uint8Array(value).buffer;
return { value: buffer, done: false, };
}

Expand Down

0 comments on commit cc661a4

Please sign in to comment.