: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
this._requests.length = 0;
this._storedError = createResponseStatusError(status, this._url);
this._headersReceivedCapability.reject(this._storedError);
for (const requestCapability of this._requests) {
requestCapability.reject(this._storedError);
this._requests.length = 0;
this._cachedChunks.length = 0;
total: evt.lengthComputable ? evt.total : this._contentLength
return this._isRangeSupported;
get isStreamingSupported() {
return this._isStreamingSupported;
return this._contentLength;
return this._headersReceivedCapability.promise;
if (this._cachedChunks.length > 0) {
const chunk = this._cachedChunks.shift();
const requestCapability = Promise.withResolvers();
this._requests.push(requestCapability);
return requestCapability.promise;
this._headersReceivedCapability.reject(reason);
for (const requestCapability of this._requests) {
requestCapability.resolve({
this._requests.length = 0;
if (this._manager.isPendingRequest(this._fullRequestId)) {
this._manager.abortRequest(this._fullRequestId);
this._fullRequestReader = null;
class PDFNetworkStreamRangeRequestReader {
constructor(manager, begin, end) {
onDone: this._onDone.bind(this),
onError: this._onError.bind(this),
onProgress: this._onProgress.bind(this)
this._requestId = manager.requestRange(begin, end, args);
this._queuedChunk = null;
this._storedError = undefined;
const chunk = data.chunk;
if (this._requests.length > 0) {
const requestCapability = this._requests.shift();
requestCapability.resolve({
this._queuedChunk = chunk;
for (const requestCapability of this._requests) {
requestCapability.resolve({
this._requests.length = 0;
this._storedError = createResponseStatusError(status, this._url);
for (const requestCapability of this._requests) {
requestCapability.reject(this._storedError);
this._requests.length = 0;
this._queuedChunk = null;
if (!this.isStreamingSupported) {
get isStreamingSupported() {
if (this._queuedChunk !== null) {
const chunk = this._queuedChunk;
this._queuedChunk = null;
const requestCapability = Promise.withResolvers();
this._requests.push(requestCapability);
return requestCapability.promise;
for (const requestCapability of this._requests) {
requestCapability.resolve({
this._requests.length = 0;
if (this._manager.isPendingRequest(this._requestId)) {
this._manager.abortRequest(this._requestId);
;// CONCATENATED MODULE: ./src/display/node_stream.js
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
function parseUrl(sourceUrl) {
const url = NodePackages.get("url");
const parsedUrl = url.parse(sourceUrl);
if (parsedUrl.protocol === "file:" || parsedUrl.host) {
if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
return url.parse(`file:///${sourceUrl}`);
parsedUrl.protocol = "file:";
this.url = parseUrl(source.url);
this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
this.isFsUrl = this.url.protocol === "file:";
this.httpHeaders = this.isHttp && source.httpHeaders || {};
this._fullRequestReader = null;
this._rangeRequestReaders = [];
get _progressiveDataLength() {
return this._fullRequestReader?._loaded ?? 0;
assert(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
return this._fullRequestReader;
getRangeReader(start, end) {
if (end <= this._progressiveDataLength) {
const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
this._rangeRequestReaders.push(rangeReader);
cancelAllRequests(reason) {
this._fullRequestReader?.cancel(reason);
for (const reader of this._rangeRequestReaders.slice(0)) {
this._storedError = null;
const source = stream.source;
this._contentLength = source.length;
this._disableRange = source.disableRange || false;
this._rangeChunkSize = source.rangeChunkSize;
if (!this._rangeChunkSize && !this._disableRange) {
this._disableRange = true;
this._isStreamingSupported = !source.disableStream;
this._isRangeSupported = !source.disableRange;
this._readableStream = null;
this._readCapability = Promise.withResolvers();
this._headersCapability = Promise.withResolvers();
return this._headersCapability.promise;
return this._contentLength;
return this._isRangeSupported;
get isStreamingSupported() {
return this._isStreamingSupported;
await this._readCapability.promise;
const chunk = this._readableStream.read();
this._readCapability = Promise.withResolvers();
this._loaded += chunk.length;
total: this._contentLength
const buffer = new Uint8Array(chunk).buffer;
if (!this._readableStream) {
this._readableStream.destroy(reason);
this._storedError = reason;
this._readCapability.resolve();
_setReadableStream(readableStream) {
this._readableStream = readableStream;
readableStream.on("readable", () => {
this._readCapability.resolve();
readableStream.on("end", () => {
readableStream.destroy();
this._readCapability.resolve();
readableStream.on("error", reason => {
if (!this._isStreamingSupported && this._isRangeSupported) {
this._error(new AbortException("streaming is disabled"));
this._readableStream.destroy(this._storedError);
this._storedError = null;
this._readableStream = null;
this._readCapability = Promise.withResolvers();
const source = stream.source;
this._isStreamingSupported = !source.disableStream;
get isStreamingSupported() {
return this._isStreamingSupported;
await this._readCapability.promise;
const chunk = this._readableStream.read();
this._readCapability = Promise.withResolvers();
this._loaded += chunk.length;
const buffer = new Uint8Array(chunk).buffer;
if (!this._readableStream) {
this._readableStream.destroy(reason);
this._storedError = reason;
this._readCapability.resolve();
_setReadableStream(readableStream) {
this._readableStream = readableStream;
readableStream.on("readable", () => {
this._readCapability.resolve();
readableStream.on("end", () => {
readableStream.destroy();
this._readCapability.resolve();
readableStream.on("error", reason => {
this._readableStream.destroy(this._storedError);
function createRequestOptions(parsedUrl, headers) {
protocol: parsedUrl.protocol,
host: parsedUrl.hostname,
class PDFNodeStreamFullReader extends BaseFullReader {
const handleResponse = response => {
if (response.statusCode === 404) {
const error = new MissingPDFException(`Missing PDF "${this._url}".`);
this._storedError = error;
this._headersCapability.reject(error);
this._headersCapability.resolve();
this._setReadableStream(response);
const getResponseHeader = name => this._readableStream.headers[name.toLowerCase()];
} = validateRangeRequestCapabilities({
rangeChunkSize: this._rangeChunkSize,
disableRange: this._disableRange
this._isRangeSupported = allowRangeRequests;
this._contentLength = suggestedLength || this._contentLength;
this._filename = extractFilenameFromHeader(getResponseHeader);
if (this._url.protocol === "http:") {
const http = NodePackages.get("http");
this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
const https = NodePackages.get("https");
this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
this._request.on("error", reason => {
this._storedError = reason;
this._headersCapability.reject(reason);
class PDFNodeStreamRangeReader extends BaseRangeReader {
constructor(stream, start, end) {
for (const property in stream.httpHeaders) {
const value = stream.httpHeaders[property];
if (value === undefined) {
this._httpHeaders[property] = value;
this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
const handleResponse = response => {
if (response.statusCode === 404) {
const error = new MissingPDFException(`Missing PDF "${this._url}".`);
this._storedError = error;
this._setReadableStream(response);
if (this._url.protocol === "http:") {
const http = NodePackages.get("http");
this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
const https = NodePackages.get("https");
this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
this._request.on("error", reason => {
this._storedError = reason;
class PDFNodeStreamFsFullReader extends BaseFullReader {
let path = decodeURIComponent(this._url.path);
if (fileUriRegex.test(this._url.href)) {
path = path.replace(/^\//, "");
const fs = NodePackages.get("fs");
fs.promises.lstat(path).then(stat => {
this._contentLength = stat.size;
this._setReadableStream(fs.createReadStream(path));
this._headersCapability.resolve();
if (error.code === "ENOENT") {
error = new MissingPDFException(`Missing PDF "${path}".`);
this._storedError = error;
this._headersCapability.reject(error);
class PDFNodeStreamFsRangeReader extends BaseRangeReader {