]> git.parisson.com Git - pdf.js.git/commitdiff
Merge branch 'master' of https://github.com/andreasgal/pdf.js.git into decryptstream
authornotmasteryet <async.processingjs@yahoo.com>
Sat, 25 Jun 2011 01:03:26 +0000 (20:03 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Sat, 25 Jun 2011 01:03:26 +0000 (20:03 -0500)
1  2 
pdf.js

diff --cc pdf.js
index 320fc6913bb4b32eb4f3b4ee60a56d24c09d3816,48fc8f1ae2be90793815a97b895012fb01b13a4d..3ebedd9e18787d73df10ab11e55dc5bb848d8305
--- 1/pdf.js
--- 2/pdf.js
+++ b/pdf.js
@@@ -56,20 -56,12 +56,20 @@@ function bytesToString(bytes) 
      return str;
  }
  
 +function stringToBytes(str) {
 +    var length = str.length;
 +    var bytes = new Uint8Array(length);
 +    for (var n = 0; n < length; ++n)
 +        bytes[n] = str.charCodeAt(n) & 0xFF;
 +    return bytes;
 +}
 +
  var Stream = (function() {
      function constructor(arrayBuffer, start, length, dict) {
-         this.bytes = Uint8Array(arrayBuffer);
+         this.bytes = new Uint8Array(arrayBuffer);
          this.start = start || 0;
          this.pos = this.start;
-         this.end = (start + length) || this.bytes.byteLength;
+         this.end = (start + length) || this.bytes.length;
          this.dict = dict;
      }
  
@@@ -747,36 -799,12 +807,35 @@@ var JpegStream = (function() 
  
      return constructor;
  })();
  var DecryptStream = (function() {
 -    function constructor(str, fileKey, encAlgorithm, keyLength) {
 -        TODO("decrypt stream is not implemented");
 +    function constructor(str, decrypt) {
 +        this.str = str;
 +        this.dict = str.dict;
 +        this.decrypt = decrypt;
 +
 +        DecodeStream.call(this);
      }
  
 -    constructor.prototype = Stream.prototype;
 +    const chunkSize = 512;
 +
 +    constructor.prototype = Object.create(DecodeStream.prototype);
 +    constructor.prototype.readBlock = function() {
 +      var chunk = this.str.getBytes(chunkSize);
 +      if (!chunk || chunk.length == 0) {
 +        this.eof = true;
 +        return;
 +      }
 +      var decrypt = this.decrypt;
 +      chunk = decrypt(chunk);
 +
 +      var bufferLength = this.bufferLength;
 +      var i, n = chunk.length;
 +      var buffer = this.ensureBuffer(bufferLength + n);
 +      for (i = 0; i < n; i++)
 +        buffer[bufferLength++] = chunk[i];
 +      this.bufferLength = n;
 +      this.eof = n < chunkSize;
 +    };
  
      return constructor;
  })();