| 476 | } |
| 477 | |
| 478 | void ReadCache::SkipBytes(size_t nof_skip) { |
| 479 | if (file_index_ + nof_skip <= data_size_) { |
| 480 | if (file_buffer_.empty()) { |
| 481 | const auto bytes = StepFilePosition(buffer_, nof_skip); |
| 482 | if (bytes != nof_skip) { |
| 483 | throw std::runtime_error("End of file detected."); |
| 484 | } |
| 485 | } |
| 486 | file_index_ += nof_skip; |
| 487 | data_count_ += nof_skip; |
| 488 | return; |
| 489 | } |
| 490 | |
| 491 | // First skip the remaining bytes. |
| 492 | nof_skip -= data_size_ - file_index_; |
| 493 | |
| 494 | // If a list try to skip block by block first |
| 495 | while (block_index_ < block_list_.size()) { |
| 496 | file_index_ = 0; |
| 497 | data_size_ = 0; |
| 498 | auto* current_block = block_list_[block_index_]; |
| 499 | ++block_index_; |
| 500 | if (current_block == nullptr) { |
| 501 | break; |
| 502 | } |
| 503 | data_size_ = current_block->DataSize(); |
| 504 | if (nof_skip > data_size_) { |
| 505 | nof_skip -= data_size_; |
| 506 | continue; |
| 507 | } |
| 508 | // In right block. Set up the file buffer. |
| 509 | if (current_block->BlockType() == "DZ") { |
| 510 | try { |
| 511 | file_buffer_.resize(static_cast<size_t>(data_size_) ); |
| 512 | } catch (const std::exception&) { |
| 513 | break;; |
| 514 | } |
| 515 | } else { |
| 516 | file_buffer_.clear(); |
| 517 | SetFilePosition(buffer_, current_block->DataPosition()); |
| 518 | } |
| 519 | break; |
| 520 | } |
| 521 | // Step to the byte inside |
| 522 | if (nof_skip > 0) { |
| 523 | if (file_buffer_.empty()) { |
| 524 | const auto bytes = StepFilePosition(buffer_, nof_skip); |
| 525 | if (bytes != nof_skip) { |
| 526 | throw std::runtime_error("End of file detected."); |
| 527 | } |
| 528 | } |
| 529 | file_index_ += nof_skip; |
| 530 | data_count_ += nof_skip; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | bool ReadCache::SkipByte() { |
| 535 | if ( file_index_ < data_size_) { |
nothing calls this directly
no test coverage detected