Skip to content

Commit 01bc76e

Browse files
Merge pull request #20806 from Snuffleupagus/BinaryCMapStream-extends-Stream
Let `BinaryCMapStream` extend the `Stream` class
2 parents 7e48938 + fccee4b commit 01bc76e

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

src/core/binary_cmap.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
import { FormatError } from "../shared/util.js";
17+
import { Stream } from "./stream.js";
1718

1819
function hexToInt(a, size) {
1920
let n = 0;
@@ -56,26 +57,23 @@ function incHex(a, size) {
5657
const MAX_NUM_SIZE = 16;
5758
const MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
5859

59-
class BinaryCMapStream {
60-
constructor(data) {
61-
this.buffer = data;
62-
this.pos = 0;
63-
this.end = data.length;
64-
this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
65-
}
60+
class BinaryCMapStream extends Stream {
61+
tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
6662

67-
readByte() {
68-
if (this.pos >= this.end) {
69-
return -1;
70-
}
71-
return this.buffer[this.pos++];
63+
constructor(data) {
64+
super(
65+
/* arrayBuffer = */ data,
66+
/* start = */ 0,
67+
/* length = */ data.length,
68+
/* dict = */ null
69+
);
7270
}
7371

7472
readNumber() {
7573
let n = 0;
7674
let last;
7775
do {
78-
const b = this.readByte();
76+
const b = this.getByte();
7977
if (b < 0) {
8078
throw new FormatError("unexpected EOF in bcmap");
8179
}
@@ -91,16 +89,15 @@ class BinaryCMapStream {
9189
}
9290

9391
readHex(num, size) {
94-
num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
95-
this.pos += size + 1;
92+
num.set(this.getBytes(size + 1));
9693
}
9794

9895
readHexNumber(num, size) {
9996
let last;
10097
const stack = this.tmpBuf;
10198
let sp = 0;
10299
do {
103-
const b = this.readByte();
100+
const b = this.getByte();
104101
if (b < 0) {
105102
throw new FormatError("unexpected EOF in bcmap");
106103
}
@@ -145,7 +142,7 @@ class BinaryCMapStream {
145142
class BinaryCMapReader {
146143
async process(data, cMap, extend) {
147144
const stream = new BinaryCMapStream(data);
148-
const header = stream.readByte();
145+
const header = stream.getByte();
149146
cMap.vertical = !!(header & 1);
150147

151148
let useCMap = null;
@@ -157,7 +154,7 @@ class BinaryCMapReader {
157154
let code;
158155

159156
let b;
160-
while ((b = stream.readByte()) >= 0) {
157+
while ((b = stream.getByte()) >= 0) {
161158
const type = b >> 5;
162159
if (type === 7) {
163160
// metadata, e.g. comment or usecmap

0 commit comments

Comments
 (0)