This PR resolves the issue described in #17. When reading a stream and a partial sector read is required, if that read is at the end of the file it will result in an io.EOF error. That error will be returned immediately with only the bytes read prior to the sector read. The io.EOF tells the reader there is no more data which can cause unexpected errors (like the missed writing n bytes in the case of archive/tar ).
To resolve this, when reading the partial sector an error is only returned if it's not an io.EOF error. If the file read reaches EOF, it can be ignored so the data read from the sector can be copied into whatever space remains in the buffer and the rest can stored for the next read. If the buffer has space for all the data from the sector, then the next call will result in an io.EOF as remaining will be zero at that point.
This PR resolves the issue described in #17. When reading a stream and a partial sector read is required, if that read is at the end of the file it will result in an
io.EOF
error. That error will be returned immediately with only the bytes read prior to the sector read. Theio.EOF
tells the reader there is no more data which can cause unexpected errors (like the missed writingn
bytes in the case ofarchive/tar
).To resolve this, when reading the partial sector an error is only returned if it's not an
io.EOF
error. If the file read reaches EOF, it can be ignored so the data read from the sector can be copied into whatever space remains in the buffer and the rest can stored for the next read. If the buffer has space for all the data from the sector, then the next call will result in anio.EOF
asremaining
will be zero at that point.