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;
}
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;
})();