Update fetch_stream.js
to use const
in more places
This commit is contained in:
parent
737705264b
commit
cc661a4d38
@ -12,6 +12,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AbortException, assert, createPromiseCapability
|
AbortException, assert, createPromiseCapability
|
||||||
@ -32,6 +33,7 @@ function createFetchOptions(headers, withCredentials, abortController) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @implements {IPDFStream} */
|
||||||
class PDFFetchStream {
|
class PDFFetchStream {
|
||||||
constructor(source) {
|
constructor(source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
@ -56,7 +58,7 @@ class PDFFetchStream {
|
|||||||
if (end <= this._progressiveDataLength) {
|
if (end <= this._progressiveDataLength) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
let reader = new PDFFetchStreamRangeReader(this, begin, end);
|
const reader = new PDFFetchStreamRangeReader(this, begin, end);
|
||||||
this._rangeRequestReaders.push(reader);
|
this._rangeRequestReaders.push(reader);
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
@ -65,21 +67,22 @@ class PDFFetchStream {
|
|||||||
if (this._fullRequestReader) {
|
if (this._fullRequestReader) {
|
||||||
this._fullRequestReader.cancel(reason);
|
this._fullRequestReader.cancel(reason);
|
||||||
}
|
}
|
||||||
let readers = this._rangeRequestReaders.slice(0);
|
const readers = this._rangeRequestReaders.slice(0);
|
||||||
readers.forEach(function(reader) {
|
readers.forEach(function(reader) {
|
||||||
reader.cancel(reason);
|
reader.cancel(reason);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @implements {IPDFStreamReader} */
|
||||||
class PDFFetchStreamReader {
|
class PDFFetchStreamReader {
|
||||||
constructor(stream) {
|
constructor(stream) {
|
||||||
this._stream = stream;
|
this._stream = stream;
|
||||||
this._reader = null;
|
this._reader = null;
|
||||||
this._loaded = 0;
|
this._loaded = 0;
|
||||||
this._filename = null;
|
this._filename = null;
|
||||||
let source = stream.source;
|
const source = stream.source;
|
||||||
this._withCredentials = source.withCredentials;
|
this._withCredentials = source.withCredentials || false;
|
||||||
this._contentLength = source.length;
|
this._contentLength = source.length;
|
||||||
this._headersCapability = createPromiseCapability();
|
this._headersCapability = createPromiseCapability();
|
||||||
this._disableRange = source.disableRange || false;
|
this._disableRange = source.disableRange || false;
|
||||||
@ -95,15 +98,15 @@ class PDFFetchStreamReader {
|
|||||||
this._isRangeSupported = !source.disableRange;
|
this._isRangeSupported = !source.disableRange;
|
||||||
|
|
||||||
this._headers = new Headers();
|
this._headers = new Headers();
|
||||||
for (let property in this._stream.httpHeaders) {
|
for (const property in this._stream.httpHeaders) {
|
||||||
let value = this._stream.httpHeaders[property];
|
const value = this._stream.httpHeaders[property];
|
||||||
if (typeof value === 'undefined') {
|
if (typeof value === 'undefined') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this._headers.append(property, value);
|
this._headers.append(property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = source.url;
|
const url = source.url;
|
||||||
fetch(url, createFetchOptions(this._headers, this._withCredentials,
|
fetch(url, createFetchOptions(this._headers, this._withCredentials,
|
||||||
this._abortController)).then((response) => {
|
this._abortController)).then((response) => {
|
||||||
if (!validateResponseStatus(response.status)) {
|
if (!validateResponseStatus(response.status)) {
|
||||||
@ -115,7 +118,7 @@ class PDFFetchStreamReader {
|
|||||||
const getResponseHeader = (name) => {
|
const getResponseHeader = (name) => {
|
||||||
return response.headers.get(name);
|
return response.headers.get(name);
|
||||||
};
|
};
|
||||||
let { allowRangeRequests, suggestedLength, } =
|
const { allowRangeRequests, suggestedLength, } =
|
||||||
validateRangeRequestCapabilities({
|
validateRangeRequestCapabilities({
|
||||||
getResponseHeader,
|
getResponseHeader,
|
||||||
isHttp: this._stream.isHttp,
|
isHttp: this._stream.isHttp,
|
||||||
@ -132,7 +135,7 @@ class PDFFetchStreamReader {
|
|||||||
// We need to stop reading when range is supported and streaming is
|
// We need to stop reading when range is supported and streaming is
|
||||||
// disabled.
|
// disabled.
|
||||||
if (!this._isStreamingSupported && this._isRangeSupported) {
|
if (!this._isStreamingSupported && this._isRangeSupported) {
|
||||||
this.cancel(new AbortException('streaming is disabled'));
|
this.cancel(new AbortException('Streaming is disabled.'));
|
||||||
}
|
}
|
||||||
}).catch(this._headersCapability.reject);
|
}).catch(this._headersCapability.reject);
|
||||||
|
|
||||||
@ -172,7 +175,7 @@ class PDFFetchStreamReader {
|
|||||||
total: this._contentLength,
|
total: this._contentLength,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let buffer = new Uint8Array(value).buffer;
|
const buffer = new Uint8Array(value).buffer;
|
||||||
return { value: buffer, done: false, };
|
return { value: buffer, done: false, };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,13 +189,14 @@ class PDFFetchStreamReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @implements {IPDFStreamRangeReader} */
|
||||||
class PDFFetchStreamRangeReader {
|
class PDFFetchStreamRangeReader {
|
||||||
constructor(stream, begin, end) {
|
constructor(stream, begin, end) {
|
||||||
this._stream = stream;
|
this._stream = stream;
|
||||||
this._reader = null;
|
this._reader = null;
|
||||||
this._loaded = 0;
|
this._loaded = 0;
|
||||||
let source = stream.source;
|
const source = stream.source;
|
||||||
this._withCredentials = source.withCredentials;
|
this._withCredentials = source.withCredentials || false;
|
||||||
this._readCapability = createPromiseCapability();
|
this._readCapability = createPromiseCapability();
|
||||||
this._isStreamingSupported = !source.disableStream;
|
this._isStreamingSupported = !source.disableStream;
|
||||||
|
|
||||||
@ -201,17 +205,16 @@ class PDFFetchStreamRangeReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._headers = new Headers();
|
this._headers = new Headers();
|
||||||
for (let property in this._stream.httpHeaders) {
|
for (const property in this._stream.httpHeaders) {
|
||||||
let value = this._stream.httpHeaders[property];
|
const value = this._stream.httpHeaders[property];
|
||||||
if (typeof value === 'undefined') {
|
if (typeof value === 'undefined') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this._headers.append(property, value);
|
this._headers.append(property, value);
|
||||||
}
|
}
|
||||||
|
this._headers.append('Range', `bytes=${begin}-${end - 1}`);
|
||||||
|
|
||||||
let rangeStr = begin + '-' + (end - 1);
|
const url = source.url;
|
||||||
this._headers.append('Range', 'bytes=' + rangeStr);
|
|
||||||
let url = source.url;
|
|
||||||
fetch(url, createFetchOptions(this._headers, this._withCredentials,
|
fetch(url, createFetchOptions(this._headers, this._withCredentials,
|
||||||
this._abortController)).then((response) => {
|
this._abortController)).then((response) => {
|
||||||
if (!validateResponseStatus(response.status)) {
|
if (!validateResponseStatus(response.status)) {
|
||||||
@ -238,7 +241,7 @@ class PDFFetchStreamRangeReader {
|
|||||||
if (this.onProgress) {
|
if (this.onProgress) {
|
||||||
this.onProgress({ loaded: this._loaded, });
|
this.onProgress({ loaded: this._loaded, });
|
||||||
}
|
}
|
||||||
let buffer = new Uint8Array(value).buffer;
|
const buffer = new Uint8Array(value).buffer;
|
||||||
return { value: buffer, done: false, };
|
return { value: buffer, done: false, };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user