change @pipe  as input.on 'end' appears unreliable