add close scope for input stream