fixed getBytes
This commit is contained in:
parent
5da69f520d
commit
cfff44f2b2
26
pdf.js
26
pdf.js
@ -65,16 +65,19 @@ var Stream = (function() {
|
|||||||
return -1;
|
return -1;
|
||||||
return bytes[this.pos++];
|
return bytes[this.pos++];
|
||||||
},
|
},
|
||||||
|
// returns subarray of original buffer
|
||||||
|
// should only be read
|
||||||
getBytes: function(length) {
|
getBytes: function(length) {
|
||||||
var bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
var end = this.end;
|
var end = pos + length;
|
||||||
if (pos + length > end)
|
var strEnd = this.end;
|
||||||
length = end - pos;
|
if (end > strEnd)
|
||||||
|
end = strEnd;
|
||||||
|
|
||||||
var n = 0;
|
var n = 0;
|
||||||
var buf = new Uint8Array(length);
|
var buf = new Uint8Array(length);
|
||||||
while (n < length)
|
while (pos < end)
|
||||||
buf[n++] = bytes[pos++]
|
buf[n++] = bytes[pos++]
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
return buf;
|
return buf;
|
||||||
@ -315,20 +318,23 @@ var FlateStream = (function() {
|
|||||||
return this.buffer[this.bufferPos++];
|
return this.buffer[this.bufferPos++];
|
||||||
},
|
},
|
||||||
getBytes: function(length) {
|
getBytes: function(length) {
|
||||||
var bufferPos = this.bufferPos;
|
var pos = this.bufferPos;
|
||||||
|
|
||||||
while (!this.eof && this.bufferLength < bufferPos + length)
|
while (!this.eof && this.bufferLength < bufferPos + length)
|
||||||
this.readBlock();
|
this.readBlock();
|
||||||
|
|
||||||
if (length > bufferLength - bufferPos)
|
var end = pos + length;
|
||||||
length = bufferLength - bufferPos;
|
var bufEnd = this.bufferLength;
|
||||||
|
|
||||||
|
if (end > bufEnd)
|
||||||
|
end = bufEnd;
|
||||||
|
|
||||||
var buffer = this.buffer;
|
var buffer = this.buffer;
|
||||||
var retBuffer = new Uint8Array(length);
|
var retBuffer = new Uint8Array(length);
|
||||||
var n = 0;
|
var n = 0;
|
||||||
while (n < length)
|
while (pos < end)
|
||||||
retBuffer[n++] = buffer[bufferPos++];
|
retBuffer[n++] = buffer[pos++];
|
||||||
this.bufferPos = bufferPos;
|
this.bufferPos = pos;
|
||||||
return retBuffer;
|
return retBuffer;
|
||||||
},
|
},
|
||||||
lookChar: function() {
|
lookChar: function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user