| 1 | #include "buffered_io.h" |
| 2 | |
| 3 | i64 IBinaryStream::LongWrite(const void* userBuffer, i64 size) { |
| 4 | Y_ABORT_UNLESS(size >= 0, "IBinaryStream::Write() called with a negative buffer size."); |
| 5 | |
| 6 | i64 leftToWrite = size; |
| 7 | while (leftToWrite != 0) { |
| 8 | int writeSz = static_cast<int>(Min<i64>(leftToWrite, std::numeric_limits<int>::max())); |
| 9 | int written = WriteImpl(userBuffer, writeSz); |
| 10 | Y_ASSERT(written <= writeSz); |
| 11 | leftToWrite -= written; |
| 12 | // Assumption: if WriteImpl(buf, writeSz) returns < writeSz, the stream is |
| 13 | // full and there's no sense in continuing. |
| 14 | if (written < writeSz) |
| 15 | break; |
| 16 | } |
| 17 | Y_ASSERT(size >= leftToWrite); |
| 18 | return size - leftToWrite; |
| 19 | } |
| 20 | |
| 21 | i64 IBinaryStream::LongRead(void* userBuffer, i64 size) { |
| 22 | Y_ABORT_UNLESS(size >= 0, "IBinaryStream::Read() called with a negative buffer size."); |