copyFrom writes bytes starting from offset off in src to dst stopping at the end of src or at the first error. copyFrom returns the number of bytes written and any error.
(dst io.Writer, src io.ReaderAt, off int64)
| 156 | // end of src or at the first error. copyFrom returns the number of bytes |
| 157 | // written and any error. |
| 158 | func copyFrom(dst io.Writer, src io.ReaderAt, off int64) (written int64, err error) { |
| 159 | buf := make([]byte, byteBufferSize) |
| 160 | for { |
| 161 | nr, rerr := src.ReadAt(buf, off) |
| 162 | if nr > 0 { |
| 163 | nw, werr := dst.Write(buf[0:nr]) |
| 164 | if nw > 0 { |
| 165 | written += int64(nw) |
| 166 | } |
| 167 | if werr != nil { |
| 168 | err = werr |
| 169 | break |
| 170 | } |
| 171 | if nr != nw { |
| 172 | err = io.ErrShortWrite |
| 173 | break |
| 174 | } |
| 175 | off += int64(nr) |
| 176 | } |
| 177 | if rerr != nil { |
| 178 | if rerr != io.EOF { |
| 179 | err = rerr |
| 180 | } |
| 181 | break |
| 182 | } |
| 183 | } |
| 184 | return written, err |
| 185 | } |
| 186 | |
| 187 | // copyLinesFrom writes lines starting from line off in src to dst stopping at |
| 188 | // the end of src or at the first error. copyLinesFrom returns the number of |