Fix GH-820. CryptoStream.end shouldn't throw if not writable

This matches the behavior of net.Socket
This commit is contained in:
Ryan Dahl committed 2011-03-21 14:36:49 -07:00
1 parent 4198de280f
commit 7e28630f5e
1 file changed
+16 -18
+16 -18
View File
@@ -168,25 +168,23 @@ CryptoStream.prototype.getCipher = function(err) {
CryptoStream.prototype.end = function(d) {
if (!this.writable) {
throw new Error('CryptoStream is not writable');
if (this.writable) {
if (this.pair._done) return;
if (d) {
this.write(d);
}
this._pending.push(END_OF_FILE);
this._pendingCallbacks.push(null);
// If this is an encrypted stream then we need to disable further 'data'
// events.
this.writable = false;
this.pair._cycle();
}
if (this.pair._done) return;
if (d) {
this.write(d);
}
this._pending.push(END_OF_FILE);
this._pendingCallbacks.push(null);
// If this is an encrypted stream then we need to disable further 'data'
// events.
this.writable = false;
this.pair._cycle();
};