2017-08-10 16:30:54 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-08-31 00:53:38 +09:00
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
AbortException,
|
|
|
|
assert,
|
|
|
|
createPromiseCapability,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "../shared/util.js";
|
2017-08-10 16:30:54 +09:00
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
createResponseStatusError,
|
|
|
|
extractFilenameFromHeader,
|
|
|
|
validateRangeRequestCapabilities,
|
|
|
|
validateResponseStatus,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "./network_utils.js";
|
2017-08-10 16:30:54 +09:00
|
|
|
|
2020-05-19 22:10:05 +09:00
|
|
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|
|
|
throw new Error(
|
|
|
|
'Module "./fetch_stream.js" shall not be used with MOZCENTRAL builds.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-04 05:28:34 +09:00
|
|
|
function createFetchOptions(headers, withCredentials, abortController) {
|
2017-08-10 16:30:54 +09:00
|
|
|
return {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
method: "GET",
|
2017-08-10 16:30:54 +09:00
|
|
|
headers,
|
2020-11-06 22:36:16 +09:00
|
|
|
signal: abortController?.signal,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
mode: "cors",
|
|
|
|
credentials: withCredentials ? "include" : "same-origin",
|
|
|
|
redirect: "follow",
|
2017-08-10 16:30:54 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-12-23 06:04:25 +09:00
|
|
|
function createHeaders(httpHeaders) {
|
|
|
|
const headers = new Headers();
|
|
|
|
for (const property in httpHeaders) {
|
|
|
|
const value = httpHeaders[property];
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof value === "undefined") {
|
2019-12-23 06:04:25 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
headers.append(property, value);
|
|
|
|
}
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
|
2019-05-16 16:13:55 +09:00
|
|
|
/** @implements {IPDFStream} */
|
2017-08-10 16:30:54 +09:00
|
|
|
class PDFFetchStream {
|
2017-10-16 22:52:20 +09:00
|
|
|
constructor(source) {
|
|
|
|
this.source = source;
|
|
|
|
this.isHttp = /^https?:/i.test(source.url);
|
|
|
|
this.httpHeaders = (this.isHttp && source.httpHeaders) || {};
|
2017-08-10 16:30:54 +09:00
|
|
|
|
|
|
|
this._fullRequestReader = null;
|
|
|
|
this._rangeRequestReaders = [];
|
|
|
|
}
|
|
|
|
|
2019-03-28 01:54:05 +09:00
|
|
|
get _progressiveDataLength() {
|
2021-01-20 00:28:47 +09:00
|
|
|
return this._fullRequestReader?._loaded ?? 0;
|
2019-03-28 01:54:05 +09:00
|
|
|
}
|
|
|
|
|
2017-08-10 16:30:54 +09:00
|
|
|
getFullReader() {
|
2020-05-05 19:40:01 +09:00
|
|
|
assert(
|
|
|
|
!this._fullRequestReader,
|
|
|
|
"PDFFetchStream.getFullReader can only be called once."
|
|
|
|
);
|
2017-08-10 16:30:54 +09:00
|
|
|
this._fullRequestReader = new PDFFetchStreamReader(this);
|
|
|
|
return this._fullRequestReader;
|
|
|
|
}
|
|
|
|
|
|
|
|
getRangeReader(begin, end) {
|
2019-03-28 01:54:05 +09:00
|
|
|
if (end <= this._progressiveDataLength) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-05-16 16:13:55 +09:00
|
|
|
const reader = new PDFFetchStreamRangeReader(this, begin, end);
|
2017-08-10 16:30:54 +09:00
|
|
|
this._rangeRequestReaders.push(reader);
|
|
|
|
return reader;
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelAllRequests(reason) {
|
|
|
|
if (this._fullRequestReader) {
|
|
|
|
this._fullRequestReader.cancel(reason);
|
|
|
|
}
|
2021-04-24 19:36:01 +09:00
|
|
|
for (const reader of this._rangeRequestReaders.slice(0)) {
|
2017-08-10 16:30:54 +09:00
|
|
|
reader.cancel(reason);
|
2021-04-24 19:36:01 +09:00
|
|
|
}
|
2017-08-10 16:30:54 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 16:13:55 +09:00
|
|
|
/** @implements {IPDFStreamReader} */
|
2017-08-10 16:30:54 +09:00
|
|
|
class PDFFetchStreamReader {
|
|
|
|
constructor(stream) {
|
|
|
|
this._stream = stream;
|
|
|
|
this._reader = null;
|
|
|
|
this._loaded = 0;
|
2018-01-17 00:24:36 +09:00
|
|
|
this._filename = null;
|
2019-05-16 16:13:55 +09:00
|
|
|
const source = stream.source;
|
|
|
|
this._withCredentials = source.withCredentials || false;
|
2017-10-16 22:52:20 +09:00
|
|
|
this._contentLength = source.length;
|
2017-08-10 16:30:54 +09:00
|
|
|
this._headersCapability = createPromiseCapability();
|
2018-02-09 21:39:38 +09:00
|
|
|
this._disableRange = source.disableRange || false;
|
2017-10-16 22:52:20 +09:00
|
|
|
this._rangeChunkSize = source.rangeChunkSize;
|
2017-08-10 16:30:54 +09:00
|
|
|
if (!this._rangeChunkSize && !this._disableRange) {
|
|
|
|
this._disableRange = true;
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof AbortController !== "undefined") {
|
2018-05-04 05:28:34 +09:00
|
|
|
this._abortController = new AbortController();
|
|
|
|
}
|
2017-10-16 22:52:20 +09:00
|
|
|
this._isStreamingSupported = !source.disableStream;
|
2018-02-09 21:39:38 +09:00
|
|
|
this._isRangeSupported = !source.disableRange;
|
2017-08-10 16:30:54 +09:00
|
|
|
|
2019-12-23 06:04:25 +09:00
|
|
|
this._headers = createHeaders(this._stream.httpHeaders);
|
2017-08-10 16:30:54 +09:00
|
|
|
|
2019-05-16 16:13:55 +09:00
|
|
|
const url = source.url;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fetch(
|
|
|
|
url,
|
|
|
|
createFetchOptions(
|
|
|
|
this._headers,
|
|
|
|
this._withCredentials,
|
|
|
|
this._abortController
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.then(response => {
|
|
|
|
if (!validateResponseStatus(response.status)) {
|
|
|
|
throw createResponseStatusError(response.status, url);
|
|
|
|
}
|
|
|
|
this._reader = response.body.getReader();
|
|
|
|
this._headersCapability.resolve();
|
|
|
|
|
|
|
|
const getResponseHeader = name => {
|
|
|
|
return response.headers.get(name);
|
|
|
|
};
|
|
|
|
const {
|
|
|
|
allowRangeRequests,
|
|
|
|
suggestedLength,
|
|
|
|
} = validateRangeRequestCapabilities({
|
2018-01-13 17:01:50 +09:00
|
|
|
getResponseHeader,
|
2017-08-10 16:30:54 +09:00
|
|
|
isHttp: this._stream.isHttp,
|
|
|
|
rangeChunkSize: this._rangeChunkSize,
|
|
|
|
disableRange: this._disableRange,
|
|
|
|
});
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._isRangeSupported = allowRangeRequests;
|
|
|
|
// Setting right content length.
|
|
|
|
this._contentLength = suggestedLength || this._contentLength;
|
2018-01-17 00:24:36 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._filename = extractFilenameFromHeader(getResponseHeader);
|
2017-08-31 00:53:38 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
// 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."));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(this._headersCapability.reject);
|
2017-08-10 16:30:54 +09:00
|
|
|
|
|
|
|
this.onProgress = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get headersReady() {
|
|
|
|
return this._headersCapability.promise;
|
|
|
|
}
|
|
|
|
|
2018-01-17 00:24:36 +09:00
|
|
|
get filename() {
|
|
|
|
return this._filename;
|
2017-08-10 16:30:54 +09:00
|
|
|
}
|
|
|
|
|
2018-01-17 00:24:36 +09:00
|
|
|
get contentLength() {
|
|
|
|
return this._contentLength;
|
2018-01-13 17:01:50 +09:00
|
|
|
}
|
|
|
|
|
2017-08-10 16:30:54 +09:00
|
|
|
get isRangeSupported() {
|
|
|
|
return this._isRangeSupported;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isStreamingSupported() {
|
|
|
|
return this._isStreamingSupported;
|
|
|
|
}
|
|
|
|
|
2018-07-30 20:58:09 +09:00
|
|
|
async read() {
|
|
|
|
await this._headersCapability.promise;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const { value, done } = await this._reader.read();
|
2018-07-30 20:58:09 +09:00
|
|
|
if (done) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return { value, done };
|
2018-07-30 20:58:09 +09:00
|
|
|
}
|
|
|
|
this._loaded += value.byteLength;
|
|
|
|
if (this.onProgress) {
|
|
|
|
this.onProgress({
|
|
|
|
loaded: this._loaded,
|
|
|
|
total: this._contentLength,
|
2017-08-10 16:30:54 +09:00
|
|
|
});
|
2018-07-30 20:58:09 +09:00
|
|
|
}
|
2019-05-16 16:13:55 +09:00
|
|
|
const buffer = new Uint8Array(value).buffer;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return { value: buffer, done: false };
|
2017-08-10 16:30:54 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
cancel(reason) {
|
|
|
|
if (this._reader) {
|
|
|
|
this._reader.cancel(reason);
|
|
|
|
}
|
2018-05-04 05:28:34 +09:00
|
|
|
if (this._abortController) {
|
|
|
|
this._abortController.abort();
|
|
|
|
}
|
2017-08-10 16:30:54 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 16:13:55 +09:00
|
|
|
/** @implements {IPDFStreamRangeReader} */
|
2017-08-10 16:30:54 +09:00
|
|
|
class PDFFetchStreamRangeReader {
|
|
|
|
constructor(stream, begin, end) {
|
|
|
|
this._stream = stream;
|
|
|
|
this._reader = null;
|
|
|
|
this._loaded = 0;
|
2019-05-16 16:13:55 +09:00
|
|
|
const source = stream.source;
|
|
|
|
this._withCredentials = source.withCredentials || false;
|
2017-08-10 16:30:54 +09:00
|
|
|
this._readCapability = createPromiseCapability();
|
2017-10-16 22:52:20 +09:00
|
|
|
this._isStreamingSupported = !source.disableStream;
|
2017-08-10 16:30:54 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof AbortController !== "undefined") {
|
2018-05-04 05:28:34 +09:00
|
|
|
this._abortController = new AbortController();
|
|
|
|
}
|
|
|
|
|
2019-12-23 06:04:25 +09:00
|
|
|
this._headers = createHeaders(this._stream.httpHeaders);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._headers.append("Range", `bytes=${begin}-${end - 1}`);
|
2017-08-10 16:30:54 +09:00
|
|
|
|
2019-05-16 16:13:55 +09:00
|
|
|
const url = source.url;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fetch(
|
|
|
|
url,
|
|
|
|
createFetchOptions(
|
|
|
|
this._headers,
|
|
|
|
this._withCredentials,
|
|
|
|
this._abortController
|
|
|
|
)
|
2020-07-29 00:03:50 +09:00
|
|
|
)
|
|
|
|
.then(response => {
|
|
|
|
if (!validateResponseStatus(response.status)) {
|
|
|
|
throw createResponseStatusError(response.status, url);
|
|
|
|
}
|
|
|
|
this._readCapability.resolve();
|
|
|
|
this._reader = response.body.getReader();
|
|
|
|
})
|
|
|
|
.catch(reason => {
|
2020-11-06 22:36:16 +09:00
|
|
|
if (reason?.name === "AbortError") {
|
2020-07-29 00:03:50 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw reason;
|
|
|
|
});
|
2017-08-10 16:30:54 +09:00
|
|
|
|
|
|
|
this.onProgress = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isStreamingSupported() {
|
|
|
|
return this._isStreamingSupported;
|
|
|
|
}
|
|
|
|
|
2018-07-30 20:58:09 +09:00
|
|
|
async read() {
|
|
|
|
await this._readCapability.promise;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const { value, done } = await this._reader.read();
|
2018-07-30 20:58:09 +09:00
|
|
|
if (done) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return { value, done };
|
2018-07-30 20:58:09 +09:00
|
|
|
}
|
|
|
|
this._loaded += value.byteLength;
|
|
|
|
if (this.onProgress) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.onProgress({ loaded: this._loaded });
|
2018-07-30 20:58:09 +09:00
|
|
|
}
|
2019-05-16 16:13:55 +09:00
|
|
|
const buffer = new Uint8Array(value).buffer;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return { value: buffer, done: false };
|
2017-08-10 16:30:54 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
cancel(reason) {
|
|
|
|
if (this._reader) {
|
|
|
|
this._reader.cancel(reason);
|
|
|
|
}
|
2018-05-04 05:28:34 +09:00
|
|
|
if (this._abortController) {
|
|
|
|
this._abortController.abort();
|
|
|
|
}
|
2017-08-10 16:30:54 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
export { PDFFetchStream };
|