From c51ef1f21f8dc703b5a39f203cf76ed50db1887f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 27 Apr 2021 12:38:40 +0200 Subject: [PATCH] Convert `src/core/jbig2_stream.js` to use standard classes --- src/core/jbig2_stream.js | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/core/jbig2_stream.js b/src/core/jbig2_stream.js index 5d5af33d1..c760e8d90 100644 --- a/src/core/jbig2_stream.js +++ b/src/core/jbig2_stream.js @@ -22,33 +22,27 @@ import { shadow } from "../shared/util.js"; * For JBIG2's we use a library to decode these images and * the stream behaves like all the other DecodeStreams. */ -const Jbig2Stream = (function Jbig2StreamClosure() { - // eslint-disable-next-line no-shadow - function Jbig2Stream(stream, maybeLength, dict, params) { +class Jbig2Stream extends DecodeStream { + constructor(stream, maybeLength, dict, params) { + super(maybeLength); + this.stream = stream; this.maybeLength = maybeLength; this.dict = dict; this.params = params; - - DecodeStream.call(this, maybeLength); } - Jbig2Stream.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(Jbig2Stream.prototype, "bytes", { - get() { - // If `this.maybeLength` is null, we'll get the entire stream. - return shadow(this, "bytes", this.stream.getBytes(this.maybeLength)); - }, - configurable: true, - }); - - Jbig2Stream.prototype.ensureBuffer = function (requested) { + ensureBuffer(requested) { // No-op, since `this.readBlock` will always parse the entire image and // directly insert all of its data into `this.buffer`. - }; + } - Jbig2Stream.prototype.readBlock = function () { + readBlock() { if (this.eof) { return; } @@ -73,9 +67,7 @@ const Jbig2Stream = (function Jbig2StreamClosure() { this.buffer = data; this.bufferLength = dataLength; this.eof = true; - }; - - return Jbig2Stream; -})(); + } +} export { Jbig2Stream };