]> git.parisson.com Git - pdf.js.git/commitdiff
refactor getFingerprint
authorSaebekassebil <saebekassebil@gmail.com>
Mon, 26 Mar 2012 22:14:59 +0000 (00:14 +0200)
committerSaebekassebil <saebekassebil@gmail.com>
Mon, 26 Mar 2012 22:14:59 +0000 (00:14 +0200)
src/core.js

index 890563f4e12b1efdd6444746b7c057586ac57d34..dffdbd44ec10bb5dc725ac433f9a7a266f49522c 100644 (file)
@@ -587,16 +587,6 @@ var PDFDocModel = (function PDFDocModelClosure() {
                           this.mainXRefEntriesOffset);
       this.xref = xref;
       this.catalog = new Catalog(xref);
-      if (xref.trailer) {
-        if (xref.trailer.has('ID')) {
-          var fileID = '';
-          var id = xref.fetchIfRef(xref.trailer.get('ID'))[0];
-          id.split('').forEach(function(el) {
-            fileID += Number(el.charCodeAt(0)).toString(16);
-          });
-          this.fileID = fileID;
-        }
-      }
     },
     get numPages() {
       var linearization = this.linearization;
@@ -610,20 +600,25 @@ var PDFDocModel = (function PDFDocModelClosure() {
       }
     },
     getFingerprint: function pdfDocGetFingerprint() {
-      if (this.fileID) {
-        return this.fileID;
+      var xref = this.xref, fileID;
+      if (xref.trailer.has('ID')) {
+        fileID = '';
+        var id = xref.fetchIfRef(xref.trailer.get('ID'))[0];
+        id.split('').forEach(function(el) {
+          fileID += Number(el.charCodeAt(0)).toString(16);
+        });
       } else {
         // If we got no fileID, then we generate one,
         // from the first 100 bytes of PDF
         var data = this.stream.bytes.subarray(0, 100);
         var hash = calculateMD5(data, 0, data.length);
-        var strHash = '';
+        fileID = '';
         for (var i = 0, length = hash.length; i < length; i++) {
-          strHash += Number(hash[i]).toString(16);
+          fileID += Number(hash[i]).toString(16);
         }
-
-        return strHash;
       }
+
+      return shadow(this, 'getFingerprint', fileID);
     },
     getPage: function pdfDocGetPage(n) {
       return this.catalog.getPage(n);