| 83 | : contents_(contents), force_error_(false) {} |
| 84 | |
| 85 | Status Read(uint64 offset, size_t n, StringPiece* result, |
| 86 | char* scratch) const override { |
| 87 | if (force_error_) { |
| 88 | force_error_ = false; |
| 89 | return errors::DataLoss("read error"); |
| 90 | } |
| 91 | |
| 92 | if (offset >= contents_->size()) { |
| 93 | return errors::OutOfRange("end of file"); |
| 94 | } |
| 95 | |
| 96 | if (contents_->size() < offset + n) { |
| 97 | n = contents_->size() - offset; |
| 98 | } |
| 99 | *result = StringPiece(contents_->data() + offset, n); |
| 100 | return Status::OK(); |
| 101 | } |
| 102 | |
| 103 | void force_error() { force_error_ = true; } |
| 104 | |