From d9c1bf96b677fb87cf0d0225fb908acdf7a1a5a0 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 27 Apr 2021 12:36:33 +0200 Subject: [PATCH] Convert `src/core/jpeg_stream.js` to use standard classes --- src/core/jpeg_stream.js | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/core/jpeg_stream.js b/src/core/jpeg_stream.js index f936626ea..300f055a8 100644 --- a/src/core/jpeg_stream.js +++ b/src/core/jpeg_stream.js @@ -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 * like all the other DecodeStreams. */ -const JpegStream = (function JpegStreamClosure() { - // eslint-disable-next-line no-shadow - function JpegStream(stream, maybeLength, dict, params) { +class JpegStream extends DecodeStream { + constructor(stream, maybeLength, dict, params) { // Some images may contain 'junk' before the SOI (start-of-image) marker. // Note: this seems to mainly affect inline images. let ch; @@ -35,30 +34,25 @@ const JpegStream = (function JpegStreamClosure() { break; } } + super(maybeLength); + this.stream = stream; this.maybeLength = maybeLength; this.dict = dict; 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", { - 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) { + ensureBuffer(requested) { // No-op, since `this.readBlock` will always parse the entire image and // directly insert all of its data into `this.buffer`. - }; + } - JpegStream.prototype.readBlock = function () { + readBlock() { if (this.eof) { return; } @@ -105,9 +99,7 @@ const JpegStream = (function JpegStreamClosure() { this.buffer = data; this.bufferLength = data.length; this.eof = true; - }; - - return JpegStream; -})(); + } +} export { JpegStream };