Rewrite BytesStreamOutput on top of BigArrays/ByteArray.

Make BytesStreamOutput more efficient by using paging via BigArrays/ByteArrays. Also changes two existing callers to be more correct/efficient.

Fix for #5159