mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-05 01:31:00 +02:00
Shorten the getBytes method in the Stream/ChunkedStream classes
This is very old code and there's currently a bit of unneeded duplication in these methods, especially in the `ChunkedStream` class.
This commit is contained in:
parent
9071f451a5
commit
d36d3ab893
@ -182,28 +182,14 @@ class ChunkedStream extends Stream {
|
||||
}
|
||||
|
||||
getBytes(length) {
|
||||
const bytes = this.bytes;
|
||||
const pos = this.pos;
|
||||
const strEnd = this.end;
|
||||
const endPos = !length ? this.end : Math.min(pos + length, this.end);
|
||||
|
||||
if (!length) {
|
||||
if (strEnd > this.progressiveDataLength) {
|
||||
this.ensureRange(pos, strEnd);
|
||||
}
|
||||
this.pos = strEnd;
|
||||
return bytes.subarray(pos, strEnd);
|
||||
if (endPos > this.progressiveDataLength) {
|
||||
this.ensureRange(pos, endPos);
|
||||
}
|
||||
|
||||
let end = pos + length;
|
||||
if (end > strEnd) {
|
||||
end = strEnd;
|
||||
}
|
||||
if (end > this.progressiveDataLength) {
|
||||
this.ensureRange(pos, end);
|
||||
}
|
||||
|
||||
this.pos = end;
|
||||
return bytes.subarray(pos, end);
|
||||
this.pos = endPos;
|
||||
return this.bytes.subarray(pos, endPos);
|
||||
}
|
||||
|
||||
getByteRange(begin, end) {
|
||||
|
||||
@ -46,20 +46,11 @@ class Stream extends BaseStream {
|
||||
}
|
||||
|
||||
getBytes(length) {
|
||||
const bytes = this.bytes;
|
||||
const pos = this.pos;
|
||||
const strEnd = this.end;
|
||||
const endPos = !length ? this.end : Math.min(pos + length, this.end);
|
||||
|
||||
if (!length) {
|
||||
this.pos = strEnd;
|
||||
return bytes.subarray(pos, strEnd);
|
||||
}
|
||||
let end = pos + length;
|
||||
if (end > strEnd) {
|
||||
end = strEnd;
|
||||
}
|
||||
this.pos = end;
|
||||
return bytes.subarray(pos, end);
|
||||
this.pos = endPos;
|
||||
return this.bytes.subarray(pos, endPos);
|
||||
}
|
||||
|
||||
getByteRange(begin, end) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user