]> git.parisson.com Git - pdf.js.git/commitdiff
added getBytes method
authorsbarman <sbarman@L3CWZ5T.(none)>
Wed, 8 Jun 2011 22:41:17 +0000 (15:41 -0700)
committersbarman <sbarman@L3CWZ5T.(none)>
Wed, 8 Jun 2011 22:41:17 +0000 (15:41 -0700)
pdf.js

diff --git a/pdf.js b/pdf.js
index 64e9432e98d8d2c1a778e38fa48397f159d46bad..96427c5d9f85f4388548413d07e7d69f974fff31 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -65,6 +65,17 @@ var Stream = (function() {
                 return -1;
             return bytes[this.pos++];
         },
+        getBytes: function(length) {
+            var bytes = this.bytes;
+            var pos = this.pos;
+            var end = this.end;
+            if (pos + length > end)
+                length = end - pos;
+            
+            var n = 0;
+            var buf = new Uint8Array(bytes, pos, length);
+            return buf;
+        },
         lookChar: function() {
             var bytes = this.bytes;
             if (this.pos >= this.end)
@@ -233,7 +244,7 @@ var FlateStream = (function() {
         this.eof = false;
         this.codeSize = 0;
         this.codeBuf = 0;
-        this.pos = 0;
+        
         this.bufferPos = 0;
         this.bufferLength = 0;
     }
@@ -290,6 +301,27 @@ var FlateStream = (function() {
                 buffer2[i] = buffer[i];
             return this.buffer = buffer2;
         },
+        getByte: function() {
+            var bufferLength = this.bufferLength;
+            var bufferPos = this.bufferPos;
+            if (bufferLength == bufferPos) {
+                if (this.eof)
+                    return;
+                this.readBlock();
+            }
+            return this.buffer[this.bufferPos++];
+        },
+        getBytes: function(length) {
+            var bufferPos = this.bufferPos;
+
+            while (!this.eof && this.bufferLength < bufferPos + length)
+                this.readBlock();
+
+            if (length > bufferLength - bufferPos)
+                length = bufferLength - bufferPos;
+
+            return new Uint8Array(this.buffer, bufferPos, length);
+        },
         lookChar: function() {
             var bufferLength = this.bufferLength;
             var bufferPos = this.bufferPos;
@@ -304,7 +336,6 @@ var FlateStream = (function() {
             var ch = this.lookChar();
             if (!ch)
                 return;
-            this.pos++;
             this.bufferPos++;
             return ch;
         },