combined redudent code in Stream

This commit is contained in:
sbarman 2011-06-21 15:16:04 -07:00
parent 8f6006137d
commit e0853abdda

34
pdf.js
View File

@ -65,45 +65,47 @@ var Stream = (function() {
this.dict = dict; this.dict = dict;
} }
// required methods for a stream. if a particular stream does not
// implement these, an error should be thrown
constructor.prototype = { constructor.prototype = {
get length() { get length() {
return this.end - this.start; return this.end - this.start;
}, },
getByte: function() { lookByte: function() {
var bytes = this.bytes;
if (this.pos >= this.end) if (this.pos >= this.end)
return -1; return;
return bytes[this.pos++]; return this.bytes[this.pos];
},
getByte: function() {
if (this.pos >= this.end)
return;
return this.bytes[this.pos++];
}, },
// returns subarray of original buffer // returns subarray of original buffer
// should only be read // 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 strEnd = this.end;
if (!length)
return bytes.subarray(pos, strEnd);
var end = pos + length; var end = pos + length;
var strEnd = this.end; if (end > strEnd)
if (!end || end > strEnd)
end = strEnd; end = strEnd;
this.pos = end; this.pos = end;
return bytes.subarray(pos, end); return bytes.subarray(pos, end);
}, },
lookChar: function() { lookChar: function() {
var bytes = this.bytes; return String.fromCharCode(this.lookByte());
if (this.pos >= this.end)
return;
return String.fromCharCode(bytes[this.pos]);
}, },
getChar: function() { getChar: function() {
var ch = this.lookChar(); return String.fromCharCode(this.getByte());
if (!ch)
return ch;
this.pos++;
return ch;
}, },
skip: function(n) { skip: function(n) {
if (!n && !IsNum(n)) if (!n)
n = 1; n = 1;
this.pos += n; this.pos += n;
}, },