1 | var Transform = require('stream').Transform;
|
2 | var inherits = require('inherits');
|
3 |
|
4 | module.exports = CipherBase;
|
5 | inherits(CipherBase, Transform);
|
6 | function CipherBase() {
|
7 | Transform.call(this);
|
8 | }
|
9 | CipherBase.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 | };
|
21 | CipherBase.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 |