Add API function to write out a file in one shot