From 2ac4ad3111fb8a328d1d2fca1f75fb918c569f97 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 28 Apr 2021 14:05:25 +0200 Subject: [PATCH] Let `ChunkedStream` extend `Stream`, rather than `BaseStream` directly Looking at the `ChunkedStream` implementation, it's basically a "regular" `Stream` but with added functionality in order to deal with fetching/loading of missing data. Hence, by letting `ChunkedStream` extend `Stream`, we can remove some duplicate methods from the `ChunkedStream` class. --- src/core/chunked_stream.js | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 28b4ebe0d..5bfe512eb 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -18,17 +18,18 @@ import { arraysToBytes, createPromiseCapability, } from "../shared/util.js"; -import { BaseStream } from "./base_stream.js"; import { MissingDataException } from "./core_utils.js"; +import { Stream } from "./stream.js"; -class ChunkedStream extends BaseStream { +class ChunkedStream extends Stream { constructor(length, chunkSize, manager) { - super(); + super( + /* arrayBuffer = */ new Uint8Array(length), + /* start = */ 0, + /* length = */ length, + /* dict = */ null + ); - this.bytes = new Uint8Array(length); - this.start = 0; - this.pos = 0; - this.end = length; this.chunkSize = chunkSize; this._loadedChunks = new Set(); this.numChunks = Math.ceil(length / chunkSize); @@ -149,14 +150,6 @@ class ChunkedStream extends BaseStream { return this._loadedChunks.has(chunk); } - get length() { - return this.end - this.start; - } - - get isEmpty() { - return this.length === 0; - } - getByte() { const pos = this.pos; if (pos >= this.end) { @@ -209,14 +202,6 @@ class ChunkedStream extends BaseStream { return this.bytes.subarray(begin, end); } - reset() { - this.pos = this.start; - } - - moveStart() { - this.start = this.pos; - } - makeSubStream(start, length, dict = null) { if (length) { if (start + length > this.progressiveDataLength) {