| 30 | } |
| 31 | |
| 32 | Status RandomAccessInputStream::ReadNBytes(int64 bytes_to_read, |
| 33 | string* result) { |
| 34 | if (bytes_to_read < 0) { |
| 35 | return errors::InvalidArgument("Cannot read negative number of bytes"); |
| 36 | } |
| 37 | result->clear(); |
| 38 | result->resize(bytes_to_read); |
| 39 | char* result_buffer = &(*result)[0]; |
| 40 | StringPiece data; |
| 41 | Status s = file_->Read(pos_, bytes_to_read, &data, result_buffer); |
| 42 | if (data.data() != result_buffer) { |
| 43 | memmove(result_buffer, data.data(), data.size()); |
| 44 | } |
| 45 | result->resize(data.size()); |
| 46 | if (s.ok() || errors::IsOutOfRange(s)) { |
| 47 | pos_ += data.size(); |
| 48 | } |
| 49 | return s; |
| 50 | } |
| 51 | |
| 52 | #if defined(PLATFORM_GOOGLE) |
| 53 | Status RandomAccessInputStream::ReadNBytes(int64 bytes_to_read, |