]> git.parisson.com Git - pdf.js.git/commitdiff
PDFDoc() now detects argument type
authorArtur Adib <arturadib@gmail.com>
Tue, 27 Sep 2011 16:57:33 +0000 (12:57 -0400)
committerArtur Adib <arturadib@gmail.com>
Tue, 27 Sep 2011 17:17:05 +0000 (13:17 -0400)
pdf.js

diff --git a/pdf.js b/pdf.js
index 449fd9c16f858e29b69517d51efadb10c4eb8aa0..44ebf4c167469bcb0cdd2a88bf4e987684a58607 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -172,7 +172,8 @@ var Stream = (function streamStream() {
     },
     makeSubStream: function stream_makeSubstream(start, length, dict) {
       return new Stream(this.bytes.buffer, start, length, dict);
-    }
+    },
+    isStream: true
   };
 
   return constructor;
@@ -3800,8 +3801,21 @@ var Catalog = (function catalogCatalog() {
 })();
 
 var PDFDoc = (function pdfDoc() {
-  function constructor(data) {
-    var stream = new Stream(data);
+  function constructor(arg, callback) {    
+    // Stream argument
+    if (typeof arg.isStream !== 'undefined') {
+      init.call(this, arg);
+    }
+    // ArrayBuffer argument
+    else if (typeof arg.byteLength !== 'undefined') {
+      init.call(this, new Stream(arg));
+    }
+    else {
+      error('Unknown argument type');
+    }    
+  }
+
+  function init(stream){
     assertWellFormed(stream.length > 0, 'stream must have data');
     this.stream = stream;
     this.setup();
@@ -3822,7 +3836,7 @@ var PDFDoc = (function pdfDoc() {
     stream.pos += index;
     return true; /* found */
   }
-
+  
   constructor.prototype = {
     get linearization() {
       var length = this.stream.length;