offsetAvailable checks if the data at the given offset is available for reading. It may return io.EOF if the reader is finished reading and the offset is beyond the end of the stream.
(off int64)
| 442 | // offsetAvailable checks if the data at the given offset is available for reading. |
| 443 | // It may return io.EOF if the reader is finished reading and the offset is beyond the end of the stream. |
| 444 | func (ab *AsyncBuffer) offsetAvailable(off int64) (bool, error) { |
| 445 | // We can not read data from the closed reader, none |
| 446 | if err := ab.closedError(); err != nil { |
| 447 | return false, err |
| 448 | } |
| 449 | |
| 450 | // In case the offset falls within the already read chunks, we can return immediately, |
| 451 | // even if error has occurred in the future |
| 452 | if off < ab.bytesRead.Load() { |
| 453 | return true, nil |
| 454 | } |
| 455 | |
| 456 | // In case the reader is finished reading, and we have not read enough |
| 457 | // data yet, return either error or EOF |
| 458 | if ab.finished.Load() { |
| 459 | // In case, error has occurred, we need to return it |
| 460 | if err := ab.Error(); err != nil { |
| 461 | return false, err |
| 462 | } |
| 463 | |
| 464 | // Otherwise, it's EOF if the offset is beyond the end of the stream |
| 465 | return false, io.EOF |
| 466 | } |
| 467 | |
| 468 | // No available data |
| 469 | return false, nil |
| 470 | } |
| 471 | |
| 472 | // readChunkAt copies data from the chunk at the given absolute offset to the provided slice. |
| 473 | // Chunk must be available when this method is called. |
no test coverage detected