/**
 * Emulates stream.setTimeout() behaviour, but respects outgoing data
 * too.
 *
 * @param {Number} timeout Milliseconds
 */
exports.attach = function(stream, timeout) {
    var timer;
    var emitTimeout = function() {
        timer = undefined;
        stream.emit('timeout');
    };
    var updateTimer = function() {
        if (timer)
            clearTimeout(timer);
        timer = setTimeout(emitTimeout, timeout);
    };

    var oldWrite = stream.write;
    stream.write = function() {
        updateTimer();
        oldWrite.apply(this, arguments);
    };
    var clear = function() {
        if (timer)
            clearTimeout(timer);
        if (stream.write !== oldWrite)
            stream.write = oldWrite;
    delete stream.clearTimer;
    };
    stream.clearTimer = clear;
    stream.addListener('data', updateTimer);
    stream.addListener('error', clear);
    stream.addListener('close', clear);
    stream.addListener('end', clear);
};

@@ -1,8 +1,23 @@
+'use strict';%0A%0A
 /**%0A * E
@@ -191,25 +191,24 @@
    var timer
-;
 %0A    var emi
@@ -256,17 +256,16 @@
 ndefined
-;
 %0A       
@@ -287,24 +287,22 @@
 imeout')
-;
 %0A    %7D
-;
 %0A    var
@@ -343,36 +343,24 @@
   if (timer)
-%0A           
  clearTimeou
@@ -359,33 +359,32 @@
 arTimeout(timer)
-;
 %0A        timer =
@@ -416,24 +416,22 @@
 timeout)
-;
 %0A    %7D
-;
 %0A%0A    va
@@ -451,25 +451,24 @@
 stream.write
-;
 %0A    stream.
@@ -509,17 +509,16 @@
 eTimer()
-;
 %0A       
@@ -549,24 +549,22 @@
 guments)
-;
 %0A    %7D
-;
 %0A    var
@@ -603,28 +603,16 @@
  (timer)
-%0A           
  clearTi
@@ -619,25 +619,24 @@
 meout(timer)
-;
 %0A        if 
@@ -666,20 +666,8 @@
 ite)
-%0A           
  str
@@ -686,22 +686,25 @@
 oldWrite
-;
 %0A
+  
     
+  
 delete s
@@ -723,16 +723,14 @@
 imer
-;
 %0A    %7D
-;
 %0A   
@@ -755,17 +755,16 @@
  = clear
-;
 %0A    str
@@ -799,17 +799,16 @@
 teTimer)
-;
 %0A    str
@@ -830,33 +830,32 @@
 ('error', clear)
-;
 %0A    stream.addL
@@ -877,17 +877,16 @@
 , clear)
-;
 %0A    str
@@ -918,9 +918,6 @@
 ear)
-;
 %0A%7D
-;%0A

Clean up idle_timeout.js