Remove the BaseFullReader and BaseRangeReader classes in the src/display/node_stream.js file
After the previous patch these base-classes are only extended once each and they can thus be combined with the final classes.
This commit is contained in:
parent
cbf0ca71bf
commit
9269fb9be2
@ -76,7 +76,7 @@ class PDFNodeStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BaseFullReader {
|
class PDFNodeStreamFsFullReader {
|
||||||
constructor(stream) {
|
constructor(stream) {
|
||||||
this._url = stream.url;
|
this._url = stream.url;
|
||||||
this._done = false;
|
this._done = false;
|
||||||
@ -99,6 +99,24 @@ class BaseFullReader {
|
|||||||
this._readableStream = null;
|
this._readableStream = null;
|
||||||
this._readCapability = Promise.withResolvers();
|
this._readCapability = Promise.withResolvers();
|
||||||
this._headersCapability = Promise.withResolvers();
|
this._headersCapability = Promise.withResolvers();
|
||||||
|
|
||||||
|
const fs = process.getBuiltinModule("fs");
|
||||||
|
fs.promises.lstat(this._url).then(
|
||||||
|
stat => {
|
||||||
|
// Setting right content length.
|
||||||
|
this._contentLength = stat.size;
|
||||||
|
|
||||||
|
this._setReadableStream(fs.createReadStream(this._url));
|
||||||
|
this._headersCapability.resolve();
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
if (error.code === "ENOENT") {
|
||||||
|
error = new MissingPDFException(`Missing PDF "${this._url}".`);
|
||||||
|
}
|
||||||
|
this._storedError = error;
|
||||||
|
this._headersCapability.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get headersReady() {
|
get headersReady() {
|
||||||
@ -191,8 +209,8 @@ class BaseFullReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BaseRangeReader {
|
class PDFNodeStreamFsRangeReader {
|
||||||
constructor(stream) {
|
constructor(stream, start, end) {
|
||||||
this._url = stream.url;
|
this._url = stream.url;
|
||||||
this._done = false;
|
this._done = false;
|
||||||
this._storedError = null;
|
this._storedError = null;
|
||||||
@ -202,6 +220,11 @@ class BaseRangeReader {
|
|||||||
this._readCapability = Promise.withResolvers();
|
this._readCapability = Promise.withResolvers();
|
||||||
const source = stream.source;
|
const source = stream.source;
|
||||||
this._isStreamingSupported = !source.disableStream;
|
this._isStreamingSupported = !source.disableStream;
|
||||||
|
|
||||||
|
const fs = process.getBuiltinModule("fs");
|
||||||
|
this._setReadableStream(
|
||||||
|
fs.createReadStream(this._url, { start, end: end - 1 })
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get isStreamingSupported() {
|
get isStreamingSupported() {
|
||||||
@ -269,39 +292,4 @@ class BaseRangeReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PDFNodeStreamFsFullReader extends BaseFullReader {
|
|
||||||
constructor(stream) {
|
|
||||||
super(stream);
|
|
||||||
|
|
||||||
const fs = process.getBuiltinModule("fs");
|
|
||||||
fs.promises.lstat(this._url).then(
|
|
||||||
stat => {
|
|
||||||
// Setting right content length.
|
|
||||||
this._contentLength = stat.size;
|
|
||||||
|
|
||||||
this._setReadableStream(fs.createReadStream(this._url));
|
|
||||||
this._headersCapability.resolve();
|
|
||||||
},
|
|
||||||
error => {
|
|
||||||
if (error.code === "ENOENT") {
|
|
||||||
error = new MissingPDFException(`Missing PDF "${this._url}".`);
|
|
||||||
}
|
|
||||||
this._storedError = error;
|
|
||||||
this._headersCapability.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
|
||||||
constructor(stream, start, end) {
|
|
||||||
super(stream);
|
|
||||||
|
|
||||||
const fs = process.getBuiltinModule("fs");
|
|
||||||
this._setReadableStream(
|
|
||||||
fs.createReadStream(this._url, { start, end: end - 1 })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { PDFNodeStream };
|
export { PDFNodeStream };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user