Initial write code

Writing data is very similar to the read operation, but the error
handling will need a little more work.