title: Read/copy up to a certain number of bytes from `io.Reader` to `io.Writer` in Golang, or return error if OVER a certain bytes limit?
body: <p>I have an <code>io.Reader</code> in Golang and I want to double-check that the size of its data is below a predetermined maximum before or while running <code>io.Copy()</code> to save it to disk using <code>io.Writer</code>.</p>
  
  <p>Since the file data in <code>io.Reader</code> could theoretically be quite large, I want to minimize memory usage and processing here if avoidable.<br>
  I don't think there's a function that's like <code>io.CopyLessThanOrEqualToThisManyBytesOrReturnError()</code>, but I did notice that <code>io.ReadFull()</code> can do the opposite to return an error if not enough bytes are there to fill the provided buffer.</p>
  
  <p>Does anyone have a solution to this?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong><br>
  To clarify, copying a fraction of the data is not OK. It either needs to fail if it's over the threshold, or work if it's under.</p>