]> git.parisson.com Git - pdf.js.git/commitdiff
starting position of a stream is relative to the file, not the current stream
authorAndreas Gal <andreas.gal@gmail.com>
Thu, 2 Jun 2011 17:57:06 +0000 (10:57 -0700)
committerAndreas Gal <andreas.gal@gmail.com>
Thu, 2 Jun 2011 17:57:06 +0000 (10:57 -0700)
pdf.js

diff --git a/pdf.js b/pdf.js
index 1cfa59cb28273fb08f51ff15da1fb73e82a6579a..8ac26e93246fa1104c9b2b3a753920516a5cf388 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -47,26 +47,24 @@ function shadow(obj, prop, value) {
 }
 
 var Stream = (function() {
-    function constructor(arrayBuffer, dict) {
+    function constructor(arrayBuffer, start, length, dict) {
         this.bytes = new Uint8Array(arrayBuffer);
-        this.pos = 0;
-        this.start = 0;
+        this.start = start || 0;
+        this.pos = this.start;
+        this.length = (start + length) || arrayBuffer.byteLength;
         this.dict = dict;
     }
 
     constructor.prototype = {
-        get length() {
-            return this.bytes.length;
-        },
         getByte: function() {
             var bytes = this.bytes;
-            if (this.pos >= bytes.length)
+            if (this.pos >= this.length)
                 return -1;
             return bytes[this.pos++];
         },
         lookChar: function() {
             var bytes = this.bytes;
-            if (this.pos >= bytes.length)
+            if (this.pos >= this.length)
                 return;
             return String.fromCharCode(bytes[this.pos]);
         },
@@ -88,11 +86,8 @@ var Stream = (function() {
         moveStart: function() {
             this.start = this.pos;
         },
-        makeSubStream: function(pos, length, dict) {
-            var buffer = this.bytes.buffer;
-            if (length)
-                return new Stream(new Uint8Array(buffer, pos, length), dict);
-            return new Stream(new Uint8Array(buffer, pos), dict);
+        makeSubStream: function(start, length, dict) {
+            return new Stream(this.bytes.buffer, start, length, dict);
         }
     };