Extract record formatting to own function.

Extract record formatting to a separate function so that it can be
invoked by a streams based delayed write.

See #107.
See #4.