Convert src/core/jpeg_stream.js to use standard classes

This commit is contained in:
Jonas Jenwald 2021-04-27 12:36:33 +02:00
parent 0ca63f94b4
commit d9c1bf96b6

View File

@ -22,9 +22,8 @@ import { shadow } from "../shared/util.js";
* For JPEG's we use a library to decode these images and the stream behaves * For JPEG's we use a library to decode these images and the stream behaves
* like all the other DecodeStreams. * like all the other DecodeStreams.
*/ */
const JpegStream = (function JpegStreamClosure() { class JpegStream extends DecodeStream {
// eslint-disable-next-line no-shadow constructor(stream, maybeLength, dict, params) {
function JpegStream(stream, maybeLength, dict, params) {
// Some images may contain 'junk' before the SOI (start-of-image) marker. // Some images may contain 'junk' before the SOI (start-of-image) marker.
// Note: this seems to mainly affect inline images. // Note: this seems to mainly affect inline images.
let ch; let ch;
@ -35,30 +34,25 @@ const JpegStream = (function JpegStreamClosure() {
break; break;
} }
} }
super(maybeLength);
this.stream = stream; this.stream = stream;
this.maybeLength = maybeLength; this.maybeLength = maybeLength;
this.dict = dict; this.dict = dict;
this.params = params; this.params = params;
DecodeStream.call(this, maybeLength);
} }
JpegStream.prototype = Object.create(DecodeStream.prototype); get bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
}
Object.defineProperty(JpegStream.prototype, "bytes", { ensureBuffer(requested) {
get: function JpegStream_bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
},
configurable: true,
});
JpegStream.prototype.ensureBuffer = function (requested) {
// No-op, since `this.readBlock` will always parse the entire image and // No-op, since `this.readBlock` will always parse the entire image and
// directly insert all of its data into `this.buffer`. // directly insert all of its data into `this.buffer`.
}; }
JpegStream.prototype.readBlock = function () { readBlock() {
if (this.eof) { if (this.eof) {
return; return;
} }
@ -105,9 +99,7 @@ const JpegStream = (function JpegStreamClosure() {
this.buffer = data; this.buffer = data;
this.bufferLength = data.length; this.bufferLength = data.length;
this.eof = true; this.eof = true;
}; }
}
return JpegStream;
})();
export { JpegStream }; export { JpegStream };