write and end methods on stream