Saving a file in chunks using a buffer