UNPKG

792 BJavaScriptView Raw
1var Transform = require('stream').Transform;
2var inherits = require('inherits');
3
4module.exports = CipherBase;
5inherits(CipherBase, Transform);
6function CipherBase() {
7 Transform.call(this);
8}
9CipherBase.prototype.update = function (data, inputEnd, outputEnc) {
10 this.write(data, inputEnd);
11 var outData = new Buffer('');
12 var chunk;
13 while ((chunk = this.read())) {
14 outData = Buffer.concat([outData, chunk]);
15 }
16 if (outputEnc) {
17 outData = outData.toString(outputEnc);
18 }
19 return outData;
20};
21CipherBase.prototype.final = function (outputEnc) {
22 this.end();
23 var outData = new Buffer('');
24 var chunk;
25 while ((chunk = this.read())) {
26 outData = Buffer.concat([outData, chunk]);
27 }
28 if (outputEnc) {
29 outData = outData.toString(outputEnc);
30 }
31 return outData;
32};
\No newline at end of file