| 174 | } |
| 175 | |
| 176 | Status InputBuffer::Seek(int64 position) { |
| 177 | if (position < 0) { |
| 178 | return errors::InvalidArgument("Seeking to a negative position: ", |
| 179 | position); |
| 180 | } |
| 181 | // Position of the buffer within file. |
| 182 | const int64 bufpos = file_pos_ - static_cast<int64>(limit_ - buf_); |
| 183 | if (position >= bufpos && position < file_pos_) { |
| 184 | // Seeks to somewhere inside the buffer. |
| 185 | pos_ = buf_ + (position - bufpos); |
| 186 | DCHECK(pos_ >= buf_ && pos_ < limit_); |
| 187 | } else { |
| 188 | // Seeks to somewhere outside. Discards the buffered data. |
| 189 | pos_ = limit_ = buf_; |
| 190 | file_pos_ = position; |
| 191 | } |
| 192 | return Status::OK(); |
| 193 | } |
| 194 | |
| 195 | } // namespace io |
| 196 | } // namespace tensorflow |