fix error handling bugs in reader.WriteTo

I noticed a couple bugs in how I implemented reader.WriteTo. Here's a summary of the changes.

- r.err is checked before r.WriteTo begins writing. This avoids potentially writing
  corrupt data to the io.Writer after a previous decoding error.

- r.err is set when decoding errors occur in r.WriteTo. A copyWriter
  type is introduced to let r.WriteTo distinguish decoding errors vs
  write errors and allow reading to safely resume after a write error
  occurs.