write() first fills up the data buffer before flush it out
| 17 | |
| 18 | // write() first fills up the data buffer before flush it out |
| 19 | uint64_t S3KeyWriter::write(const char* buf, uint64_t count) { |
| 20 | // Defensive code |
| 21 | S3_CHECK_OR_DIE(buf != NULL, S3RuntimeError, "Buffer is NULL"); |
| 22 | this->checkQueryCancelSignal(); |
| 23 | |
| 24 | uint64_t offset = 0; |
| 25 | while (offset < count) { |
| 26 | if (sharedError) { |
| 27 | std::rethrow_exception(sharedException); |
| 28 | } |
| 29 | |
| 30 | uint64_t bufferRemaining = this->params.getChunkSize() - this->buffer.size(); |
| 31 | uint64_t dataRemaining = count - offset; |
| 32 | uint64_t dataToBuffer = bufferRemaining < dataRemaining ? bufferRemaining : dataRemaining; |
| 33 | |
| 34 | this->buffer.insert(this->buffer.end(), buf + offset, buf + offset + dataToBuffer); |
| 35 | |
| 36 | if (this->buffer.size() == this->params.getChunkSize()) { |
| 37 | this->flushBuffer(); |
| 38 | } |
| 39 | |
| 40 | offset += dataToBuffer; |
| 41 | } |
| 42 | |
| 43 | return count; |
| 44 | } |
| 45 | |
| 46 | // This should be reentrant, has no side effects when called multiple times. |
| 47 | void S3KeyWriter::close() { |
nothing calls this directly
no test coverage detected