writeStream implemenation