At EOF, gcs::ObjectReadStream::tellg() returns -1, but our APIs canonically return the stream size. This method helps with the conversion.
| 124 | // At EOF, gcs::ObjectReadStream::tellg() returns -1, but our APIs canonically return |
| 125 | // the stream size. This method helps with the conversion. |
| 126 | Result<int64_t> TellOr(int64_t max_pos) const { |
| 127 | if (closed()) return Status::Invalid("Cannot use Tell() on a closed stream"); |
| 128 | int64_t pos = stream_.tellg(); |
| 129 | if (pos < 0) { |
| 130 | if (!stream_.eof()) { |
| 131 | return Status::IOError("Tell() failed before end of stream"); |
| 132 | } |
| 133 | return max_pos; |
| 134 | } |
| 135 | return pos; |
| 136 | } |
| 137 | |
| 138 | // A gcs::ObjectReadStream can be "born closed". For small objects the stream returns |
| 139 | // `IsOpen() == false` as soon as it is created, but the application can still read from |