Copy the entire file contents to the temporary file
| 42 | |
| 43 | // Copy the entire file contents to the temporary file |
| 44 | int64_t ProcessSessionReadCallback::process(const std::shared_ptr<io::BaseStream>& stream) { |
| 45 | // Copy file contents into tmp file |
| 46 | _writeSucceeded = false; |
| 47 | size_t size = 0; |
| 48 | uint8_t buffer[8192]; |
| 49 | do { |
| 50 | int read = stream->read(buffer, 8192); |
| 51 | if (read < 0) { |
| 52 | return -1; |
| 53 | } |
| 54 | if (read == 0) { |
| 55 | break; |
| 56 | } |
| 57 | if (!_tmpFileOs.write(reinterpret_cast<char*>(buffer), read)) { |
| 58 | return -1; |
| 59 | } |
| 60 | size += read; |
| 61 | } while (size < stream->size()); |
| 62 | _writeSucceeded = true; |
| 63 | return size; |
| 64 | } |
| 65 | |
| 66 | // Renames tmp file to final destination |
| 67 | // Returns true if commit succeeded |