From: notmasteryet Date: Sat, 25 Jun 2011 01:03:26 +0000 (-0500) Subject: Merge branch 'master' of https://github.com/andreasgal/pdf.js.git into decryptstream X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=490571f7f9ab94bab80b11086ac5f450e0ad97d3;p=pdf.js.git Merge branch 'master' of https://github.com/andreasgal/pdf.js.git into decryptstream --- 490571f7f9ab94bab80b11086ac5f450e0ad97d3 diff --cc pdf.js index 320fc69,48fc8f1..3ebedd9 --- a/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; })();