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

This commit is contained in:
Jonas Jenwald 2021-04-27 12:40:32 +02:00
parent c51ef1f21f
commit 0ecb42f4d7

View File

@ -21,33 +21,27 @@ import { shadow } from "../shared/util.js";
* For JPEG 2000's we use a library to decode these images and * For JPEG 2000's we use a library to decode these images and
* the stream behaves like all the other DecodeStreams. * the stream behaves like all the other DecodeStreams.
*/ */
const JpxStream = (function JpxStreamClosure() { class JpxStream extends DecodeStream {
// eslint-disable-next-line no-shadow constructor(stream, maybeLength, dict, params) {
function JpxStream(stream, maybeLength, dict, params) { 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);
} }
JpxStream.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(JpxStream.prototype, "bytes", { ensureBuffer(requested) {
get: function JpxStream_bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
},
configurable: true,
});
JpxStream.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`.
}; }
JpxStream.prototype.readBlock = function () { readBlock() {
if (this.eof) { if (this.eof) {
return; return;
} }
@ -87,9 +81,7 @@ const JpxStream = (function JpxStreamClosure() {
} }
this.bufferLength = this.buffer.length; this.bufferLength = this.buffer.length;
this.eof = true; this.eof = true;
}; }
}
return JpxStream;
})();
export { JpxStream }; export { JpxStream };