]> git.parisson.com Git - pdf.js.git/commitdiff
combined redudent code in Stream
authorsbarman <sbarman@L3CWZ5T.(none)>
Tue, 21 Jun 2011 22:16:04 +0000 (15:16 -0700)
committersbarman <sbarman@L3CWZ5T.(none)>
Tue, 21 Jun 2011 22:16:04 +0000 (15:16 -0700)
pdf.js

diff --git a/pdf.js b/pdf.js
index 52a65f1e39fb95315e49be7ab9fc253e663c4f19..8ea56ae22b5b2b447f6007510dc9486c269503db 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -65,45 +65,47 @@ var Stream = (function() {
         this.dict = dict;
     }
 
+    // required methods for a stream. if a particular stream does not
+    // implement these, an error should be thrown
     constructor.prototype = {
         get length() {
             return this.end - this.start;
         },
+        lookByte: function() {
+            if (this.pos >= this.end)
+                return;
+            return this.bytes[this.pos];
+        },
         getByte: function() {
-            var bytes = this.bytes;
             if (this.pos >= this.end)
-                return -1;
-            return bytes[this.pos++];
+                return;
+            return this.bytes[this.pos++];
         },
         // returns subarray of original buffer
         // should only be read
         getBytes: function(length) {
             var bytes = this.bytes;
             var pos = this.pos;
+            var strEnd = this.end;
+
+            if (!length)
+                return bytes.subarray(pos, strEnd);
 
             var end = pos + length;
-            var strEnd = this.end;
-            if (!end || end > strEnd)
+            if (end > strEnd)
                 end = strEnd;
 
             this.pos = end;
             return bytes.subarray(pos, end);
         },
         lookChar: function() {
-            var bytes = this.bytes;
-            if (this.pos >= this.end)
-                return;
-            return String.fromCharCode(bytes[this.pos]);
+            return String.fromCharCode(this.lookByte());
         },
         getChar: function() {
-            var ch = this.lookChar();
-            if (!ch)
-                return ch;
-            this.pos++;
-            return ch;
+            return String.fromCharCode(this.getByte());
         },
         skip: function(n) {
-            if (!n && !IsNum(n))
+            if (!n)
                 n = 1;
             this.pos += n;
         },