Replace failure with an error.
Added convenience function to save a buffer

Make it more convenient to write a buffer to a file.
Open the file write-only.
fixed formatting
Merge commit '2184609a44f38b659aa65dafe690ed380c20f538'
Merge pull request #118 from nwin/master

Added convenience function to save a buffer