fix error handling bugs in reader.WriteTo

- r.err is checked before r.WriteTo begins writing. This avoids writing
  corrupt input to the input writer.

- r.err is set when decoding errors occur in r.WriteTo. A copyWriter
  type is introduced to distinguish decoding errors vs write errors and
  allow reading to safely resume after a write error occurs.