|
@ -34,14 +34,33 @@ function CryptoStream (pair) { |
|
|
|
|
|
|
|
|
this._writeState = true; |
|
|
this._writeState = true; |
|
|
this._pending = []; |
|
|
this._pending = []; |
|
|
|
|
|
this._pendingCallbacks = []; |
|
|
} |
|
|
} |
|
|
util.inherits(CryptoStream, stream.Stream); |
|
|
util.inherits(CryptoStream, stream.Stream); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CryptoStream.prototype.write = function(data) { |
|
|
CryptoStream.prototype.write = function(data /* , encoding, cb */) { |
|
|
if (typeof data == 'string') data = Buffer(data); |
|
|
var encoding, cb; |
|
|
|
|
|
|
|
|
|
|
|
// parse arguments
|
|
|
|
|
|
if (typeof arguments[1] == 'string') { |
|
|
|
|
|
encoding = arguments[1]; |
|
|
|
|
|
cb = arguments[2]; |
|
|
|
|
|
} else { |
|
|
|
|
|
cb = arguments[1]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Transform strings into buffers.
|
|
|
|
|
|
if (typeof data == 'string') { |
|
|
|
|
|
data = new Buffer(data, encoding); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
debug('clearIn data'); |
|
|
debug('clearIn data'); |
|
|
|
|
|
|
|
|
this._pending.push(data); |
|
|
this._pending.push(data); |
|
|
|
|
|
this._pendingCallbacks.push(cb); |
|
|
|
|
|
|
|
|
this.pair._cycle(); |
|
|
this.pair._cycle(); |
|
|
return this._writeState; |
|
|
return this._writeState; |
|
|
}; |
|
|
}; |
|
@ -187,10 +206,13 @@ CryptoStream.prototype._blow = function() { |
|
|
// });
|
|
|
// });
|
|
|
//
|
|
|
//
|
|
|
CryptoStream.prototype._suck = function() { |
|
|
CryptoStream.prototype._suck = function() { |
|
|
var tmp, rv; |
|
|
var tmp, cb, rv; |
|
|
var havePending = this._pending.length > 0; |
|
|
var havePending = this._pending.length > 0; |
|
|
while (this._pending.length > 0) { |
|
|
while (this._pending.length > 0) { |
|
|
tmp = this._pending.shift(); |
|
|
tmp = this._pending.shift(); |
|
|
|
|
|
cb = this._pendingCallbacks.shift(); |
|
|
|
|
|
|
|
|
|
|
|
assert(this._pending.length === this._pendingCallbacks.length); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
rv = this._sucker(tmp); |
|
|
rv = this._sucker(tmp); |
|
@ -205,9 +227,12 @@ CryptoStream.prototype._suck = function() { |
|
|
|
|
|
|
|
|
if (rv === 0) { |
|
|
if (rv === 0) { |
|
|
this._pending.unshift(tmp); |
|
|
this._pending.unshift(tmp); |
|
|
|
|
|
this._pendingCallbacks.unshift(cb); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cb) cb(); |
|
|
|
|
|
|
|
|
assert(rv === tmp.length); |
|
|
assert(rv === tmp.length); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|