fix encode and stream issue